class Tilt::Template
def initialize(file=nil, line=nil, options=nil)
:scope_class :: Force the scope class used for the method. By default,
and no embedded locals are found (or scanned for).
only used if :fixed_locals is not provided
:default_fixed_locals :: Similar to fixed_locals, but lowest priority,
and extracted from the template code.
:extract_fixed_locals :: Whether embedded fixed locals should be scanned for
disable the scan for embedded fixed locals.
surrounded by parentheses. Can be set to false to
containing the parameters for the compiled method,
extracting locals from that. Should be a string
the locals hash as a positional argument, and
the method with a splat of locals, instead of passing
:fixed_locals :: Force a specific method parameter signature, and call
an encoding magic comment.
:skip_compiled_encoding_detection :: Do not scan template code for
encoding.
:default_encoding :: Force the encoding of the template to the given
libraries:
are used by Tilt::Template itself and not the underlying template
All arguments are optional. The following options are respected and
a block is required.
it should read template data and return as a String. When file is nil,
default, template data is read from the file. When a block is given,
Create a new template with the file, line, and options specified. By
def initialize(file=nil, line=nil, options=nil) @file, @line, @options = nil, 1, nil process_arg(options) process_arg(line) process_arg(file) raise ArgumentError, "file or block required" unless @file || block_given? @options ||= {} # Force a specific scope class, instead of using the class of the provided # scope as the scope class. @scope_class = @options.delete :scope_class # Force the encoding of the input data @default_encoding = @options.delete :default_encoding # Skip encoding detection from magic comments and forcing that encoding # for compiled templates @skip_compiled_encoding_detection = @options.delete :skip_compiled_encoding_detection # Compiled path to use. This must be specified as an option if # providing the :scope_class option and using fixed locals, # since template compilation occurs during initialization in that case. if compiled_path = @options.delete(:compiled_path) self.compiled_path = compiled_path end # load template data and prepare (uses binread to avoid encoding issues) @data = block_given? ? yield(self) : read_template_file if @data.respond_to?(:force_encoding) if default_encoding @data = _dup_string_if_frozen(@data) @data.force_encoding(default_encoding) end if !@data.valid_encoding? raise Encoding::InvalidByteSequenceError, "#{eval_file} is not valid #{@data.encoding}" end end set_fixed_locals prepare set_compiled_method_cache end