class Haml::TempleEngine
Public Instance Methods
compile(template)
click to toggle source
# File lib/haml/temple_engine.rb, line 41 def compile(template) initialize_encoding(template, options[:encoding]) @precompiled = call(template) end
precompiled()
click to toggle source
The source code that is evaluated to produce the Haml
document.
This is automatically converted to the correct encoding (see {file:REFERENCE.md#encodings the ‘:encoding` option}).
@return [String]
# File lib/haml/temple_engine.rb, line 52 def precompiled encoding = Encoding.find(@encoding || '') return @precompiled.dup.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT return @precompiled.encode(encoding) end
precompiled_method_return_value_with_haml_xss()
click to toggle source
# File lib/haml/template.rb, line 18 def precompiled_method_return_value_with_haml_xss "::Haml::Util.html_safe(#{precompiled_method_return_value_without_haml_xss})" end
Also aliased as: precompiled_method_return_value
precompiled_with_ambles(local_names, after_preamble: '', before_postamble: '')
click to toggle source
The source code that is evaluated to produce the Haml
document.
This is automatically converted to the correct encoding (see {file:REFERENCE.md#encodings the ‘:encoding` option}).
@return [String]
# File lib/haml/temple_engine.rb, line 68 def precompiled_with_ambles(local_names, after_preamble: '', before_postamble: '') preamble = <<END.tr("\n", ';') begin extend Haml::Helpers _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{Options.new(options).for_buffer.inspect}) _erbout = _hamlout.buffer #{after_preamble} END postamble = <<END.tr("\n", ';') #{before_postamble} #{precompiled_method_return_value} ensure @haml_buffer = @haml_buffer.upper if @haml_buffer end END "#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup end
precompiled_with_return_value()
click to toggle source
# File lib/haml/temple_engine.rb, line 58 def precompiled_with_return_value "#{precompiled};#{precompiled_method_return_value}".dup end
Private Instance Methods
initialize_encoding(template, given_value)
click to toggle source
# File lib/haml/temple_engine.rb, line 88 def initialize_encoding(template, given_value) if given_value @encoding = given_value else @encoding = Encoding.default_internal || template.encoding end end
inspect_obj(obj)
click to toggle source
# File lib/haml/temple_engine.rb, line 113 def inspect_obj(obj) case obj when String %Q!"#{obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]}}"! when Symbol ":#{inspect_obj(obj.to_s)}" else obj.inspect end end
locals_code(names)
click to toggle source
# File lib/haml/temple_engine.rb, line 102 def locals_code(names) names = names.keys if Hash === names names.map do |name| # Can't use || because someone might explicitly pass in false with a symbol sym_local = "_haml_locals[#{inspect_obj(name.to_sym)}]" str_local = "_haml_locals[#{inspect_obj(name.to_s)}]" "#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local};" end.join end