Class: Distil::JavascriptProduct

Inherits:
JavascriptBaseProduct show all
Includes:
Concatenated
Defined in:
lib/distil/product/javascript-product.rb

Instance Attribute Summary

Attributes inherited from Product

#assets, #join_string, #target

Attributes inherited from Configurable

#options

Instance Method Summary collapse

Methods included from Concatenated

#after_file, #before_file, #external_files, #filename, #write_output

Methods inherited from JavascriptBaseProduct

#bootstrap_source, #can_embed_file?, #copy_bootstrap_script, #initialize

Methods inherited from Product

#can_embed_file?, #clean, #external_files, #filename, #files, #files=, #handles_file?, #initialize, #relative_path, #up_to_date, #write_output

Methods included from ErrorReporter

#error, error, #ignore_warnings, #ignore_warnings=, #report, warning, #warning

Methods inherited from Configurable

#get_option, #get_options, #initialize, option

Constructor Details

This class inherits a constructor from Distil::JavascriptBaseProduct

Instance Method Details

#after_externals(f) ⇒ Object



16
17
# File 'lib/distil/product/javascript-product.rb', line 16

def after_externals(f)
end

#after_files(f) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/distil/product/javascript-product.rb', line 59

def after_files(f)
  if global_export
    exports= ["window.#{global_export}=window.#{global_export}||{}", *additional_globals].join(", ")
    f.puts "})(#{exports});"
  end

  f.puts "\n\n/*#nocode-*/\n\n"
  
  f.puts "distil.kick();" if bootstrap
  
end

#before_externals(f) ⇒ Object



11
12
13
14
# File 'lib/distil/product/javascript-product.rb', line 11

def before_externals(f)
  f.puts("/*#nocode+*/")
  f.puts(bootstrap_source) if bootstrap
end

#before_files(f) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/distil/product/javascript-product.rb', line 19

def before_files(f)

  if 0 != assets.length
    asset_references= []
    asset_map= []
    assets.each { |a|
      if can_embed_file?(a)
        content= target.get_content_for_file(a)
        content= content.gsub("\\", "\\\\").gsub("\n", "\\n").gsub("\"", "\\\"").gsub("'", "\\\\'")
        asset_references << "\"#{target.alias_for_asset(a)}\": \"#{content}\""
      else
        asset_alias= target.alias_for_asset(a)
        asset_path= relative_path(a)
        next if asset_alias==asset_path
        asset_map << "'#{asset_alias}': '#{asset_path}'" 
      end
    }

    f << <<-EOS
    
distil.module('#{target.name}', {
  folder: '',
  asset_map: {
#{asset_map.join(",\n    ")}
  },
  assets: {
#{asset_references.join(",\n    ")}
  }
});


EOS
  end

  if global_export
    exports= [global_export, *additional_globals].join(", ")
    f.puts "(function(#{exports}){"
  end
end