Sha256: 15e1c8d2c9bcc94ecd32481b2a3087b179939da8788c1e97e82da2e0dd5c044a

Contents?: true

Size: 855 Bytes

Versions: 8

Compression:

Stored size: 855 Bytes

Contents

# encoding: utf-8

module Nanoc::Filters

  # @since 3.4.0
  class Handlebars < Nanoc::Filter

    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

8 entries across 8 versions & 1 rubygems

Version Path
nanoc-3.7.3 lib/nanoc/filters/handlebars.rb
nanoc-3.7.2 lib/nanoc/filters/handlebars.rb
nanoc-3.7.1 lib/nanoc/filters/handlebars.rb
nanoc-3.7.0 lib/nanoc/filters/handlebars.rb
nanoc-3.6.11 lib/nanoc/filters/handlebars.rb
nanoc-3.6.10 lib/nanoc/filters/handlebars.rb
nanoc-3.6.9 lib/nanoc/filters/handlebars.rb
nanoc-3.6.8 lib/nanoc/filters/handlebars.rb