Methods
L
N
P
R
Classes and Modules
Constants
OPERATION_EVAL_EXPRESSION = '='
OPERATION_COMMENT_LINE = '#'
OPERATION_BEGIN_LAMBDA = '|'
OPERATION_EVAL_TEMPLATE_FILE = '+'
OPERATION_EVAL_TEMPLATE_STRING = '~'
OPERATION_INSERT_PLAIN_FILE = '<'
Class Public methods
load_file(path, options = {})

Builds a template whose body is read from the given source.

If the source is a relative path, it will be resolved relative to options[:source_file] if that is a valid path.

# File lib/ember/template.rb, line 93
      def load_file path, options = {}
        path = resolve_path(path, options)
        new File.read(path), options.merge(:source_file => path)
      end
new(input, options = {})

Builds a processor that evaluates eRuby directives in the given input according to the given options.

This processor transforms the given input into an executable Ruby program (provided by the to_s() method) which is then executed by the render() method on demand.

eRuby directives that contribute to the output of the given template are called “vocal” directives. Those that do not are called “silent” directives.

Options

:result_variable
Name of the variable which stores the result of template evaluation during template evaluation.

The default value is “_erbout”.

:continue_result
Append to the result variable if it already exists?

The default value is false.

:source_file
Name of the file which contains the given input. This is shown in stack traces when reporting error messages.

The default value is “SOURCE”.

:source_line
Line number at which the given input exists in the :source_file. This is shown in stack traces when reporting error messages.

The default value is 1.

:shorthand
Treat lines beginning with “%” as eRuby directives?

The default value is false.

:infer_end
Add missing <% end %> statements based on indentation?

The default value is false.

:unindent
Unindent the content of eRuby blocks (everything between <% do %> … <% end %>) hierarchically?

The default value is false.

# File lib/ember/template.rb, line 63
    def initialize input, options = {}
      @options = options
      @compile = compile(input.to_s)
    end
read_file(path, options = {})

Returns the contents of the given file, which can be relative to the current template in which this command is being executed.

If the source is a relative path, it will be resolved relative to options[:source_file] if that is a valid path.

# File lib/ember/template.rb, line 105
      def read_file path, options = {}
        File.read resolve_path(path, options)
      end
Instance Public methods
program()

Ruby source code assembled from the eRuby template provided as input to the constructor of this class.

# File lib/ember/template.rb, line 72
    def program
      @compile
    end
render(context = TOPLEVEL_BINDING)

Returns the result of executing the Ruby program for this template (provided by the to_s() method) inside the given context binding.

# File lib/ember/template.rb, line 80
    def render(context = TOPLEVEL_BINDING)
      eval @compile, context,
        (@options[:source_file] || :SOURCE).to_s,
        (@options[:source_line] || 1).to_i
    end