Class: Nanoc::Filters::Haml Private

Inherits:
Nanoc::Filter
  • Object
show all
Defined in:
lib/nanoc/filters/haml.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#run(content, params = {}) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the content through [Haml](haml-lang.com/). Parameters passed to this filter will be passed on to Haml.

Parameters:

  • content (String)

    The content to filter

Returns:

  • (String)

    The filtered content



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nanoc/filters/haml.rb', line 16

def run(content, params = {})
  # Get options
  options = params.merge(
    filename:,
    outvar: '_erbout',
    disable_capture: true,
  )

  # Create context
  context = ::Nanoc::Core::Context.new(assigns)

  # Get result
  proc = assigns[:content] ? -> { assigns[:content] } : nil

  # Render
  haml_major_version = ::Haml::VERSION[0]
  case haml_major_version
  when '5'
    ::Haml::Engine.new(content, options).render(context, assigns, &proc)
  when '6'
    template = Tilt::HamlTemplate.new(options) { content }
    template.render(context, assigns, &proc)
  else
    raise Nanoc::Core::TrivialError.new(
      "Cannot run Haml filter: unsupported Haml major version: #{haml_major_version}",
    )
  end
end