Class: Nanoc::Filters::ERB Private

Inherits:
Nanoc::Filter
  • Object
show all
Defined in:
lib/nanoc/filters/erb.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 [ERB](ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html).

Parameters:

  • content (String)

    The content to filter

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :trim_mode (String) — default: nil

    The trim mode to use

Returns:

  • (String)

    The filtered content



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nanoc/filters/erb.rb', line 17

def run(content, params = {})
  # Add locals
  assigns.merge!(params[:locals] || {})

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

  # Get binding
  proc = assigns[:content] ? -> { assigns[:content] } : nil
  assigns_binding = context.get_binding(&proc)

  # Get result
  trim_mode = params[:trim_mode]
  erb = ::ERB.new(content, trim_mode:)
  erb.filename = filename
  erb.result(assigns_binding)
end