Sha256: 599e27ebb0dc5da63488f925178c5e85de1cf9e52e678aaba865f68f10d0bd12

Contents?: true

Size: 861 Bytes

Versions: 20

Compression:

Stored size: 861 Bytes

Contents

module Nanoc::Filters
  # @api private
  class Handlebars < Nanoc::Filter
    identifier :handlebars

    requires 'handlebars'

    # Runs the content through
    # [Handlebars](http://handlebarsjs.com/) using
    # [Handlebars.rb](https://github.com/cowboyd/handlebars.rb).
    # This method takes no options.
    #
    # @param [String] content The content to filter
    #
    # @return [String] The filtered content
    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
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/filters/handlebars.rb
nanoc-4.7.8 lib/nanoc/filters/handlebars.rb
nanoc-4.7.7 lib/nanoc/filters/handlebars.rb
nanoc-4.7.6 lib/nanoc/filters/handlebars.rb
nanoc-4.7.5 lib/nanoc/filters/handlebars.rb
nanoc-4.7.4 lib/nanoc/filters/handlebars.rb
nanoc-4.7.3 lib/nanoc/filters/handlebars.rb
nanoc-4.7.2 lib/nanoc/filters/handlebars.rb
nanoc-4.7.1 lib/nanoc/filters/handlebars.rb
nanoc-4.7.0 lib/nanoc/filters/handlebars.rb
nanoc-4.6.4 lib/nanoc/filters/handlebars.rb
nanoc-4.6.3 lib/nanoc/filters/handlebars.rb
nanoc-4.6.2 lib/nanoc/filters/handlebars.rb
nanoc-4.6.1 lib/nanoc/filters/handlebars.rb
nanoc-4.6.0 lib/nanoc/filters/handlebars.rb
nanoc-4.5.4 lib/nanoc/filters/handlebars.rb
nanoc-4.5.3 lib/nanoc/filters/handlebars.rb
nanoc-4.5.2 lib/nanoc/filters/handlebars.rb
nanoc-4.5.1 lib/nanoc/filters/handlebars.rb
nanoc-4.5.0 lib/nanoc/filters/handlebars.rb