class Tilt::ErubiTemplate

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).

Public Instance Methods

freeze_string_literals?() click to toggle source
   # File lib/tilt/erubi.rb
50 def freeze_string_literals?
51   @freeze_string_literals
52 end
precompiled_template(locals) click to toggle source
   # File lib/tilt/erubi.rb
46 def precompiled_template(locals)
47   @src
48 end
prepare() click to toggle source
   # File lib/tilt/erubi.rb
14 def prepare
15   @options.merge!(:preamble => false, :postamble => false, :ensure=>true)
16 
17   engine_class = @options[:engine_class] || Erubi::Engine
18 
19   # If :freeze option is given, the intent is to setup frozen string
20   # literals in the template.  So enable frozen string literals in the
21   # code Tilt generates if the :freeze option is given.
22   if @freeze_string_literals = !!@options[:freeze]
23     # Passing the :freeze option to Erubi sets the
24     # frozen-string-literal magic comment, which doesn't have an effect
25     # with Tilt as Tilt wraps the resulting code.  Worse, the magic
26     # comment appearing not at the top of the file can cause a warning.
27     # So remove the :freeze option before passing to Erubi.
28     @options.delete(:freeze)
29 
30     # Erubi by default appends .freeze to template literals on Ruby 2.1+,
31     # but that is not necessary and slows down code when Tilt is using
32     # frozen string literals, so pass the :freeze_template_literals
33     # option to not append .freeze.
34     @options[:freeze_template_literals] = false
35   end
36 
37   @engine = engine_class.new(data, @options)
38   @outvar = @engine.bufvar
39 
40   # Remove dup after tilt supports frozen source.
41   @src = @engine.src.dup
42 
43   @engine
44 end