Class: Nanoc::Tilt::Filter

Inherits:
Filter
  • Object
show all
Defined in:
lib/nanoc/tilt/filter.rb

Instance Method Summary collapse

Instance Method Details

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

Runs the content through [Tilt](github.com/rtomayko/tilt). Parameters passed as ‘:args` will be passed on to Tilt.

Parameters:

  • content (String)

    The content to filter

Returns:

  • (String)

    The filtered content



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nanoc/tilt/filter.rb', line 14

def run(content, params = {})
  # Get options
  options = params.fetch(:args, {})

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

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

  # Find Tilt template class
  ext = item.identifier.ext || item[:extension]
  template_class = ::Tilt[ext]

  # Render
  template = template_class.new(options) { content }
  template.render(context, assigns, &proc)
end