Class: Tilt::HerbTemplate
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, #fixed_locals?, #initialize, metadata, #metadata, #name, #render
Constructor Details
This class inherits a constructor from Tilt::Template
Instance Method Details
#freeze_string_literals? ⇒ Boolean
106 107 108 |
# File 'lib/tilt/herb.rb', line 106 def freeze_string_literals? @freeze_string_literals end |
#precompiled_template(locals) ⇒ Object
102 103 104 |
# File 'lib/tilt/herb.rb', line 102 def precompiled_template(locals) @src end |
#prepare ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tilt/herb.rb', line 66 def prepare @options[:preamble] = false @options[:postamble] = false @options[:ensure] = true # Unlike Erubi, Herb uses the filename when reporting errors, so pass # the file Tilt loaded the template from if the caller did not set one. @options[:filename] ||= file engine_class = @options[:engine_class] || Herb::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 Herb 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 Herb. @options.delete(:freeze) # Herb by default appends .freeze to template literals, 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 |