class Javascript
Public Class Methods
new(javascript_path)
click to toggle source
# File lib/javascript.rb, line 4 def initialize(javascript_path) @javascript_path = javascript_path @javascript = {} end
Public Instance Methods
compile()
click to toggle source
# File lib/javascript.rb, line 32 def compile() walk @javascript.each do |key, content| view_path = Pathname("dist/" + key.to_s.delete_prefix('"').delete_suffix('/"') + ".js") view_path.dirname.mkpath view_path.write(content) end end
minify(content)
click to toggle source
# File lib/javascript.rb, line 22 def minify(content) return Uglifier.compile(content, harmony: true) end
parse(path)
click to toggle source
# File lib/javascript.rb, line 17 def parse(path) file_content = read path return file_content end
read(path)
click to toggle source
# File lib/javascript.rb, line 9 def read(path) if File.file? path return File.read(path) else raise "File #{path} does not exist" end end
walk()
click to toggle source
# File lib/javascript.rb, line 26 def walk() for file in Dir[@javascript_path + "/**/*.js"] @javascript[file.sub(@javascript_path + "/", "").sub(".js", "").to_sym] = minify(parse(file)) end end