Class: Tilt::ErubiTemplate
Overview
Erubi (a simplified version of Erubis) template implementation. See github.com/jeremyevans/erubi
ErubiTemplate supports the following additional options, in addition to the options supported by the Erubi engine:
- :engine_class
-
allows you to specify a custom engine class to use instead of the default (which is ::Erubi::Engine).
Instance Attribute Summary
Attributes inherited from Template
#compiled_path, #data, #file, #line, #options
Instance Method Summary collapse
Methods inherited from Template
#basename, #compiled_method, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render
Constructor Details
This class inherits a constructor from Tilt::Template
Instance Method Details
#freeze_string_literals? ⇒ Boolean
51 52 53 |
# File 'lib/tilt/erubi.rb', line 51 def freeze_string_literals? @freeze_string_literals end |
#precompiled_template(locals) ⇒ Object
47 48 49 |
# File 'lib/tilt/erubi.rb', line 47 def precompiled_template(locals) @src end |
#prepare ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tilt/erubi.rb', line 15 def prepare @options[:preamble] = false @options[:postamble] = false @options[:ensure] = true engine_class = @options[:engine_class] || Erubi::Engine # If :freeze option is given, the intent is to setup frozen string # literals in the template. So enable frozen string literals in the # code Tilt generates if the :freeze option is given. if @freeze_string_literals = !!@options[:freeze] # Passing the :freeze option to Erubi sets the # frozen-string-literal magic comment, which doesn't have an effect # with Tilt as Tilt wraps the resulting code. Worse, the magic # comment appearing not at the top of the file can cause a warning. # So remove the :freeze option before passing to Erubi. @options.delete(:freeze) # Erubi by default appends .freeze to template literals on Ruby 2.1+, # but that is not necessary and slows down code when Tilt is using # frozen string literals, so pass the :freeze_template_literals # option to not append .freeze. @options[:freeze_template_literals] = false end @engine = engine_class.new(@data, @options) @outvar = @engine.bufvar @src = @engine.src @engine end |