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.

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

._erb_cacheObject

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.



11
12
13
# File 'lib/nanoc/filters/erb.rb', line 11

def _erb_cache
  @_erb_cache
end

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nanoc/filters/erb.rb', line 23

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_for(content, trim_mode:).result(assigns_binding)
end