Module: Opal::ERB

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

Defined Under Namespace

Classes: Compiler

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



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

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