Class: Opal::BuilderProcessors::ERBProcessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/opal/builder_processors.rb

Overview

This handler is for files named ".js.erb", which ought to first get preprocessed via ERB, then served verbatim as JS.

Instance Attribute Summary

Attributes inherited from Processor

#abs_path, #autoloads, #filename, #options, #required_trees, #requires

Instance Method Summary collapse

Methods inherited from Processor

handles, #initialize, #mark_as_required, match?, match_regexp, #to_s

Constructor Details

This class inherits a constructor from Opal::BuilderProcessors::Processor

Instance Method Details

#sourceObject



168
169
170
171
172
173
174
175
# File 'lib/opal/builder_processors.rb', line 168

def source
  erb = ::ERB.new(@source.to_s)
  erb.filename = @abs_path

  result = erb.result
  module_name = ::Opal::Compiler.module_name(@filename)
  "Opal.modules[#{module_name.inspect}] = function() {#{result}};"
end