Class: Tilt::ErubiTemplate

Inherits:
Template show all
Defined in:
lib/tilt/erubi.rb

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

Returns:

  • (Boolean)


84
85
86
# File 'lib/tilt/erubi.rb', line 84

def freeze_string_literals?
  @freeze_string_literals
end

#precompiled_template(locals) ⇒ Object



80
81
82
# File 'lib/tilt/erubi.rb', line 80

def precompiled_template(locals)
  @src
end

#prepareObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tilt/erubi.rb', line 48

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