Class: Distil::JavascriptDebugProduct

Inherits:
JavascriptBaseProduct show all
Includes:
Debug
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 Debug

#after_files, #before_files, #external_files, #filename

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

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

#write_outputObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/distil/product/javascript-product.rb', line 85

def write_output
  return if up_to_date
  @up_to_date= true
  
  copy_bootstrap_script
  
  required_files= files.map { |file| "'#{relative_path(file)}'" }
  asset_map= []
  assets.each { |a|
    asset_alias= target.alias_for_asset(a)
    asset_path= relative_path(a)
    next if asset_alias==asset_path
    asset_map << "'#{asset_alias}': '#{asset_path}'" 
  }
  
  external_files.each { |ext|
    next if !File.exist?(ext)
    required_files.unshift("'#{relative_path(ext)}'")
  }
  
  File.open(filename, "w") { |f|
    f.write(target.notice_text)
    f.write("#{bootstrap_source}\n\n") if bootstrap
    
    if global_export
      f.write("window.#{global_export}=window.#{global_export}||{};");
      f.write("\n\n");
    end
    
    files.each { |file|
      f.write("/*jsl:import #{relative_path(file)}*/\n")
    }
    
    if (APP_TYPE==target.target_type)
      f.puts "distil.sync= #{Kernel::Boolean(synchronous_load)};"
    end
    
    f.write(<<-EOS)

distil.module('#{target.name}', {
  folder: '',
  required: [#{required_files.join(", ")}],
  asset_map: {
#{asset_map.join(",\n    ")}
  }
});
EOS
  }

end