class Tilt::ErubiTemplate

  1. lib/tilt/erubi.rb
Superclass: Template

Public Instance methods

freeze_string_literals?()
[show source]
   # File lib/tilt/erubi.rb
84 def freeze_string_literals?
85   @freeze_string_literals
86 end
precompiled_template(locals)
[show source]
   # File lib/tilt/erubi.rb
80 def precompiled_template(locals)
81   @src
82 end
prepare()
[show source]
   # File lib/tilt/erubi.rb
48 def prepare
49   @options[:preamble] = false
50   @options[:postamble] = false
51   @options[:ensure] = true
52 
53   engine_class = @options[:engine_class] || Erubi::Engine
54 
55   # If :freeze option is given, the intent is to setup frozen string
56   # literals in the template.  So enable frozen string literals in the
57   # code Tilt generates if the :freeze option is given.
58   if @freeze_string_literals = !!@options[:freeze]
59     # Passing the :freeze option to Erubi sets the
60     # frozen-string-literal magic comment, which doesn't have an effect
61     # with Tilt as Tilt wraps the resulting code.  Worse, the magic
62     # comment appearing not at the top of the file can cause a warning.
63     # So remove the :freeze option before passing to Erubi.
64     @options.delete(:freeze)
65 
66     # Erubi by default appends .freeze to template literals on Ruby 2.1+,
67     # but that is not necessary and slows down code when Tilt is using
68     # frozen string literals, so pass the :freeze_template_literals
69     # option to not append .freeze.
70     @options[:freeze_template_literals] = false
71   end
72 
73   @engine = engine_class.new(@data, @options)
74   @outvar = @engine.bufvar
75   @src = @engine.src
76 
77   @engine
78 end