class Gluey::Glues::JsScript

Public Class Methods

set_uglifier_options(**opts) click to toggle source
# File lib/gluey/workshop/glues/js_script/uglifier_addons.rb, line 6
def self.set_uglifier_options(**opts)
  @uglifier_options = {copyright: :none}.merge! opts
end
uglifier() click to toggle source
# File lib/gluey/workshop/glues/js_script/uglifier_addons.rb, line 10
def self.uglifier
  @uglifier ||= ::Uglifier.new(@uglifier_options || set_uglifier_options)
end

Public Instance Methods

post_enclose(_) click to toggle source
# File lib/gluey/workshop/glues/js_script.rb, line 11
def post_enclose(_)
  @output = "(function(){\n#{@output}\n}());"
end
post_return(_) click to toggle source
# File lib/gluey/workshop/glues/js_script.rb, line 30
def post_return(_)
  @output = "(function(){\n#{@output}\n}())"
end
post_strict(_) click to toggle source
# File lib/gluey/workshop/glues/js_script.rb, line 7
def post_strict(_)
  @output = "'use strict';\n#{@output}"
end
post_strict_mode(_) click to toggle source
# File lib/gluey/workshop/glues/js_script.rb, line 15
def post_strict_mode(_)
  @output = "'use strict';\n#{@output}"
end
pre_replace(args) click to toggle source
# File lib/gluey/workshop/glues/js_script.rb, line 19
def pre_replace(args)
  file = find_nested_file(args[1])
  cached_file, deps = get_nested_piece file
  @dependencies.concat deps
  @script.gsub! /"%#{args[0]}%"/, File.read(cached_file)
end
pre_replace_with_handlebars(args) click to toggle source
# File lib/gluey/workshop/glues/js_script/handlebars_addons.rb, line 6
def pre_replace_with_handlebars(args)
  dir = File.expand_path("../#{args[1]}", @base_file)
  raise "cannot find dir containing handlebars templates for script=#{@base_file}" unless dir && Dir.exists?(dir)

  logical_path = dir[/(?:^#{@context.root}\/)?(.+)$/, 1]
  key = "dep:hb_bundle:#{logical_path}:#{@material.name}"
  hb_dep = @context.cache[key]
  unless hb_dep
    hb_dep = ::Gluey::Dependencies::Handlebars_bundle.new dir, logical_path, @context
    @context.cache[key] = hb_dep
  end

  hb_dep.actualize if hb_dep.changed?
  @dependencies << hb_dep
  @script.gsub! /"%#{args[0]}%"/, File.read(hb_dep.file)
end
pre_replace_with_texts_bundle(args) click to toggle source
# File lib/gluey/workshop/glues/js_script.rb, line 34
def pre_replace_with_texts_bundle(args)
  dir = File.expand_path("../#{args[1]}", @base_file)
  raise "cannot find relative path #{args[1]} for script=#{@base_file}" unless dir && Dir.exists?(dir)

  logical_path = dir[/(?:^#{@context.root}\/)?(.+)$/, 1]
  key = "dep:txt_bundle:#{logical_path}:#{@material.name}"
  hb_dep = @context.cache[key]
  unless hb_dep
    hb_dep = ::Gluey::Dependencies::TextsBundle.new dir, logical_path, @context
    @context.cache[key] = hb_dep
  end

  hb_dep.actualize if hb_dep.changed?
  @dependencies << hb_dep
  @script.gsub! /"%#{args[0]}%"/, File.read(hb_dep.file)
end
pre_return(args) click to toggle source
# File lib/gluey/workshop/glues/js_script.rb, line 26
def pre_return(args)
  @script = "#{@script}\nreturn #{args.first};"
end
process(base_file, deps) click to toggle source
Calls superclass method
# File lib/gluey/workshop/glues/js_script/uglifier_addons.rb, line 14
def process(base_file, deps)
  JsScript.uglifier.compile super
end