DEV: Use yarn to manage Highlight.js dependency
Moves Highlight.js files to vendor/assets/javascripts Adds Highlight.js in yarn package management Removes old rake task and reliance on NPM to build Highlight.js Highlight.js is now integrated in the "javascript:update" rake task
This commit is contained in:
parent
81953339f2
commit
b28d68efbf
|
@ -1 +0,0 @@
|
|||
hljs.registerLanguage("xquery",function(e){var t="for let if while then else return where group by xquery encoding versionmodule namespace boundary-space preserve strip default collation base-uri orderingcopy-namespaces order declare import schema namespace function option in allowing emptyat tumbling window sliding window start when only end when previous next stable ascendingdescending empty greatest least some every satisfies switch case typeswitch try catch andor to union intersect instance of treat as castable cast map array delete insert intoreplace value rename copy modify update",a="false true xs:string xs:integer element item xs:date xs:datetime xs:float xs:double xs:decimal QName xs:anyURI xs:long xs:int xs:short xs:byte attribute",s={b:/\$[a-zA-Z0-9\-]+/},n={cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},r={cN:"string",v:[{b:/"/,e:/"/,c:[{b:/""/,r:0}]},{b:/'/,e:/'/,c:[{b:/''/,r:0}]}]},i={cN:"meta",b:"%\\w+"},c={cN:"comment",b:"\\(:",e:":\\)",r:10,c:[{cN:"doctag",b:"@\\w+"}]},o={b:"{",e:"}"},l=[s,r,n,c,i,o];return o.c=l,{aliases:["xpath","xq"],cI:!1,l:/[a-zA-Z\$][a-zA-Z0-9_:\-]*/,i:/(proc)|(abstract)|(extends)|(until)|(#)/,k:{keyword:t,literal:a},c:l}});
|
|
@ -1,18 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module HighlightJs
|
||||
HIGHLIGHTJS_DIR = "#{Rails.root}/vendor/assets/javascripts/highlightjs/"
|
||||
|
||||
def self.languages
|
||||
Dir.glob(File.dirname(__FILE__) << "/assets/lang/*.js").map do |path|
|
||||
File.basename(path)[0..-4]
|
||||
langs = Dir.glob(HIGHLIGHTJS_DIR + "languages/*.js").map do |path|
|
||||
File.basename(path)[0..-8]
|
||||
end
|
||||
|
||||
langs.sort
|
||||
end
|
||||
|
||||
def self.bundle(langs)
|
||||
path = File.dirname(__FILE__) << "/assets/"
|
||||
|
||||
result = File.read(path + "highlight.js")
|
||||
result = File.read(HIGHLIGHTJS_DIR + "highlight.min.js")
|
||||
langs.each do |lang|
|
||||
begin
|
||||
result << "\n" << File.read(path + "lang/#{lang}.js")
|
||||
result << "\n" << File.read(HIGHLIGHTJS_DIR + "languages/#{lang}.min.js")
|
||||
rescue Errno::ENOENT
|
||||
# no file, don't care
|
||||
end
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
desc "download latest version of highlight and prepare it"
|
||||
task "highlightjs:update" do
|
||||
|
||||
def run(cmd, opts = {})
|
||||
puts cmd
|
||||
system(cmd, opts.merge(out: $stdout, err: :out))
|
||||
end
|
||||
run("cd tmp && rm -fr highlight.js && git clone --depth 1 https://github.com/isagalaev/highlight.js.git")
|
||||
run("cd tmp && rm -fr highlight_distrib && mkdir -p highlight_distrib/lang")
|
||||
run("cd tmp/highlight.js && npm install")
|
||||
run("cd tmp/highlight.js && node tools/build.js -t cdn none")
|
||||
|
||||
run("mv tmp/highlight.js/build/highlight.min.js tmp/highlight_distrib/highlight.js")
|
||||
|
||||
run("cd tmp/highlight.js && npm install && node tools/build.js -t cdn")
|
||||
|
||||
Dir.glob("tmp/highlight.js/build/languages/*.min.js") do |path|
|
||||
lang = File.basename(path)[0..-8]
|
||||
run("mv #{path} tmp/highlight_distrib/lang/#{lang}.js")
|
||||
end
|
||||
|
||||
run("rm -fr lib/highlight_js/assets")
|
||||
run("mv tmp/highlight_distrib lib/highlight_js/assets")
|
||||
|
||||
end
|
|
@ -44,6 +44,9 @@ task 'javascript:update' do
|
|||
source: 'handlebars/dist/handlebars.js'
|
||||
}, {
|
||||
source: 'handlebars/dist/handlebars.runtime.js'
|
||||
}, {
|
||||
source: 'highlight.js/build/.',
|
||||
destination: 'highlightjs'
|
||||
}, {
|
||||
source: 'htmlparser/lib/htmlparser.js'
|
||||
}, {
|
||||
|
@ -82,6 +85,18 @@ task 'javascript:update' do
|
|||
filename = f[:destination]
|
||||
end
|
||||
|
||||
# Highlight.js needs building
|
||||
if src.include? "highlight.js"
|
||||
puts "Install Highlight.js dependencies"
|
||||
system("cd node_modules/highlight.js && yarn install")
|
||||
|
||||
puts "Build Highlight.js"
|
||||
system("cd node_modules/highlight.js && node tools/build.js -t cdn none")
|
||||
|
||||
puts "Cleanup unused styles folder"
|
||||
system("rm -rf node_modules/highlight.js/build/styles")
|
||||
end
|
||||
|
||||
if f[:public]
|
||||
dest = "#{public_js}/#{filename}"
|
||||
else
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"chart.js": "2.7.2",
|
||||
"favcount": "https://github.com/chrishunt/favcount",
|
||||
"handlebars": "4.0.5",
|
||||
"highlight.js": "https://github.com/highlightjs/highlight.js",
|
||||
"htmlparser": "https://github.com/tautologistics/node-htmlparser",
|
||||
"intersection-observer": "^0.5.1",
|
||||
"jquery": "3.3.1",
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue