Class: Magneto::HamlFilter

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

Instance Method Summary collapse

Methods inherited from Filter

inherited, #initialize, subclasses

Constructor Details

This class inherits a constructor from Magneto::Filter

Instance Method Details

#apply(content, ivars) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/magneto/filters/haml.rb', line 9

def apply(content, ivars)
  begin
    require 'haml'
  rescue LoadError => ex
    $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{ex.to_s}"
    $stderr.puts "You're missing a library required to use Haml. Try running:"
    $stderr.puts '  $ [sudo] gem install haml'
    raise 'Missing dependency: haml'
  end

  # Adapted from "nanoc/filters/haml.rb" with thanks to Denis Defreyne and contributors.
  context = RenderContext.new(ivars)
  proc = ivars[:content] ? lambda { ivars[:content] } : lambda {}

  Haml::Engine.new(content, (ivars[:haml].symbolize_keys rescue {})).render(context, ivars, &proc)
end

#nameObject



5
6
7
# File 'lib/magneto/filters/haml.rb', line 5

def name
  'haml'
end