Class: Nanoc::Filters::Handlebars Private

Inherits:
Nanoc::Filter show all
Defined in:
lib/nanoc/filters/handlebars.rb

Overview

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.

Since:

  • 3.4.0

Constant Summary

Constants inherited from Nanoc::Filter

Nanoc::Filter::TMP_BINARY_ITEMS_DIR

Instance Attribute Summary

Attributes inherited from Nanoc::Filter

#assigns

Instance Method Summary collapse

Methods inherited from Nanoc::Filter

#depend_on, #filename, from_binary?, #initialize, #output_filename, requires, setup, #setup_and_run, to_binary?, type

Methods included from Int::PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Methods inherited from Int::Context

#get_binding, #initialize

Constructor Details

This class inherits a constructor from Nanoc::Filter

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 [Handlebars](handlebarsjs.com/) using [Handlebars.rb](github.com/cowboyd/handlebars.rb). This method takes no options.

Parameters:

  • content (String)

    The content to filter

Returns:

  • (String)

    The filtered content

Since:

  • 3.4.0



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nanoc/filters/handlebars.rb', line 16

def run(content, _params = {})
  context = item.attributes.dup
  context[:item]   = assigns[:item].attributes
  context[:config] = assigns[:config]
  context[:yield]  = assigns[:content]
  if assigns.key?(:layout)
    context[:layout] = assigns[:layout].attributes
  end

  handlebars = ::Handlebars::Context.new
  template = handlebars.compile(content)
  template.call(context)
end