Method: Middleman::Renderers::Haml#initialize
- Defined in:
- lib/middleman-core/renderers/haml.rb
#initialize(app, options = {}, &block) ⇒ Haml
Returns a new instance of Haml.
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/middleman-core/renderers/haml.rb', line 52 def initialize(app, ={}, &block) super if Object.const_defined?('::Haml::Options') # Haml 5 and older ::Haml::Options.defaults[:context] = nil ::Haml::Options.send :attr_accessor, :context else # Haml 6+ ::Haml::Engine. context: nil end if defined?(::Haml::TempleEngine) ::Haml::TempleEngine. context: nil end [::Haml::Filters::Sass, ::Haml::Filters::Scss, ::Haml::Filters::Markdown].each do |f| f.class_exec do if respond_to?(:template_class) # Haml 5 and older def self.(text, ) = .dup [:context] = [:context] text = template_class.new(nil, 1, ) { text }.render super(text, ) end else # Haml 6+ def initialize( = {}) super @context = [:context] end def compile_with_tilt(node, name, indent_width: 0) = { context: @context } source = node.value[:text] result = ::Tilt["t.#{name}"].new(nil, 1, ) { source }.render temple = [:multi, [:static, result.gsub(/^/, ' ' * indent_width)]] source.lines.size.times do temple << [:newline] end temple end end end end ::Tilt.prefer(::Middleman::Renderers::HamlTemplate, :haml) # Add haml helpers to context ::Middleman::TemplateContext.send :include, ::Haml::Helpers end |