Class: Tilt::ERBTemplate
Overview
ERB template implementation. See: www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
Constant Summary collapse
- SUPPORTS_KVARGS =
::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false
Instance Attribute Summary
Attributes inherited from Template
#compiled_path, #data, #file, #line, #options
Instance Method Summary collapse
- #freeze_string_literals? ⇒ Boolean
-
#precompiled(locals) ⇒ Object
ERB generates a line to specify the character coding of the generated source in 1.9.
- #precompiled_postamble(locals) ⇒ Object
- #precompiled_preamble(locals) ⇒ Object
- #precompiled_template(locals) ⇒ Object
- #prepare ⇒ Object
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
60 61 62 |
# File 'lib/tilt/erb.rb', line 60 def freeze_string_literals? @freeze_string_literals end |
#precompiled(locals) ⇒ Object
ERB generates a line to specify the character coding of the generated source in 1.9. Account for this in the line offset.
55 56 57 58 |
# File 'lib/tilt/erb.rb', line 55 def precompiled(locals) source, offset = super [source, offset + 1] end |
#precompiled_postamble(locals) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/tilt/erb.rb', line 44 def precompiled_postamble(locals) " \#{super}\n ensure\n \#{@outvar} = __original_outvar\n end\n RUBY\nend\n" |
#precompiled_preamble(locals) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/tilt/erb.rb', line 36 def precompiled_preamble(locals) " begin\n __original_outvar = \#{@outvar} if defined?(\#{@outvar})\n \#{super}\n RUBY\nend\n" |
#precompiled_template(locals) ⇒ Object
31 32 33 34 |
# File 'lib/tilt/erb.rb', line 31 def precompiled_template(locals) source = @engine.src source end |
#prepare ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tilt/erb.rb', line 11 def prepare @freeze_string_literals = !![:freeze] @outvar = [:outvar] || '_erbout' trim = case [:trim] when false nil when nil, true '<>' else [:trim] end @engine = if SUPPORTS_KVARGS ::ERB.new(@data, trim_mode: trim, eoutvar: @outvar) # :nocov: else ::ERB.new(@data, [:safe], trim, @outvar) # :nocov: end end |