Module: Opal::ERB

Defined in:
/Users/elia/Code/opal-docs/opal/lib/opal/erb.rb,
/Users/elia/Code/opal-docs/opal/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"

Parameters:

  • source (String)

    erb content

  • file_name (String) (defaults to: '(erb)')

    filename for reference in template

Returns:

  • (String)

    javascript code


25
26
27
# File '/Users/elia/Code/opal-docs/opal/lib/opal/erb.rb', line 25

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