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