Class: Rake::Pipeline::Web::Filters::MinispadeFilter
- Inherits:
-
Filter
- Object
- Filter
- Rake::Pipeline::Web::Filters::MinispadeFilter
- Defined in:
- lib/rake-pipeline-web-filters/minispade_filter.rb
Overview
A filter that wraps JavaScript files in a minispade.register closure for use in minispade.
Instance Method Summary collapse
-
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API.
-
#initialize(options = {}) ⇒ MinispadeFilter
constructor
A new instance of MinispadeFilter.
Constructor Details
#initialize(options = {}) ⇒ MinispadeFilter
Returns a new instance of MinispadeFilter.
26 27 28 29 30 31 32 33 |
# File 'lib/rake-pipeline-web-filters/minispade_filter.rb', line 26 def initialize( = {}) super() @use_strict = [:use_strict] @module_id_generator = [:module_id_generator] || proc { |input| input.fullpath.sub(Dir.pwd, '') } @rewrite_requires = [:rewrite_requires] @string_module = [:string] end |
Instance Method Details
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API. Wraps each input file in a minispade.register closure.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rake-pipeline-web-filters/minispade_filter.rb', line 44 def generate_output(inputs, output) inputs.each do |input| code = input.read code.gsub!(%r{^\s*require\s*\(\s*}, 'minispade.require(') if @rewrite_requires code.gsub!(%r{^\s*requireAll\s*\(\s*}, 'minispade.requireAll(') if @rewrite_requires code = %["use strict";\n] + code if @use_strict module_id = @module_id_generator.call(input) if @string_module contents = %{(function() {#{code}\n})();\n//@ sourceURL=#{module_id}}.to_json else contents = "function() {#{code}\n}" end ret = "minispade.register('#{module_id}', #{contents});" output.write ret end end |