Sha256: 873038d473c0989364a5b01b246ace2534878876fe82885c566f77a13816ddc1

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

# encoding: utf-8

require 'handlebars'

module Nanoc::Filters

  # @since 3.4.0
  class Handlebars < Nanoc::Filter

    # 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[:layout] = assigns[:layout].attributes
      context[:config] = assigns[:config]
      context[:yield]  = assigns[:content]

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

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-3.5.0 lib/nanoc/filters/handlebars.rb
nanoc-3.5.0b2 lib/nanoc/filters/handlebars.rb
nanoc-3.5.0b1 lib/nanoc/filters/handlebars.rb