Module: Opal::ERB

Defined in:
lib/opal/erb.rb,
lib/opal/sprockets/erb.rb

Defined Under Namespace

Classes: Compiler, Processor

Class Method Summary collapse

Class Method Details

.compile(source, file_name = '(erb)') ⇒ String

Compile ERB code into javascript.

[Opal::ERB] can be used to compile [ERB] templates into javascript code. This module uses the [Opal::Compiler] internally.

Compiled templates, when run in a javascript environment, will appear under the Template namespace, and can be accessed as:

Template['template_name'] # => template instance

Examples:


source = "<div><%= @content %></div>"

Opal::ERB.compile source, "my_template.erb"

25
26
27
# File 'lib/opal/erb.rb', line 25

def self.compile(source, file_name = '(erb)')
  Compiler.new(source, file_name).compile
end