Class: Middleman::Renderers::Haml

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-core/renderers/haml.rb

Overview

Haml Renderer

Constant Summary

Constants included from Contracts

Contracts::PATH_MATCHER

Instance Attribute Summary

Attributes inherited from Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Extension

activated_extension, #after_build, #after_configuration, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #manipulate_resource_list, option, #ready, resources

Methods included from Contracts

#Contract

Constructor Details

#initialize(app, options = {}, &block) ⇒ Haml

Returns a new instance of Haml.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/middleman-core/renderers/haml.rb', line 43

def initialize(app, options={}, &block)
  super

  ::Haml::Options.defaults[:context] = nil
  ::Haml::Options.send :attr_accessor, :context

  # rubocop:disable NestedMethodDefinition
  [::Haml::Filters::Sass, ::Haml::Filters::Scss, ::Haml::Filters::Markdown].each do |f|
    f.class_exec do
      def self.render_with_options(text, compiler_options)
        modified_options = options.dup
        modified_options[:context] = compiler_options[:context]

        text = template_class.new(nil, 1, modified_options) { text }.render
        super(text, compiler_options)
      end
    end
  end
  # rubocop:enable NestedMethodDefinition

  ::Tilt.prefer(::Middleman::Renderers::HamlTemplate, :haml)

  # Add haml helpers to context
  ::Middleman::TemplateContext.send :include, ::Haml::Helpers
end

Instance Method Details

#add_exposed_to_context(context) ⇒ Object



69
70
71
72
73
# File 'lib/middleman-core/renderers/haml.rb', line 69

def add_exposed_to_context(context)
  super

  context.init_haml_helpers if context.respond_to?(:init_haml_helpers)
end