Sha256: c110ab0da776fc66a0943bc4e5e3c8f19537a84aded272ab71b3a0075c9bbadb

Contents?: true

Size: 892 Bytes

Versions: 49

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

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

49 entries across 49 versions & 1 rubygems

Version Path
nanoc-4.11.8 lib/nanoc/filters/handlebars.rb
nanoc-4.11.7 lib/nanoc/filters/handlebars.rb
nanoc-4.11.6 lib/nanoc/filters/handlebars.rb
nanoc-4.11.5 lib/nanoc/filters/handlebars.rb
nanoc-4.11.4 lib/nanoc/filters/handlebars.rb
nanoc-4.11.3 lib/nanoc/filters/handlebars.rb
nanoc-4.11.2 lib/nanoc/filters/handlebars.rb
nanoc-4.11.1 lib/nanoc/filters/handlebars.rb
nanoc-4.11.0 lib/nanoc/filters/handlebars.rb
nanoc-4.10.4 lib/nanoc/filters/handlebars.rb
nanoc-4.10.3 lib/nanoc/filters/handlebars.rb
nanoc-4.10.2 lib/nanoc/filters/handlebars.rb
nanoc-4.10.1 lib/nanoc/filters/handlebars.rb
nanoc-4.10.0 lib/nanoc/filters/handlebars.rb
nanoc-4.9.9 lib/nanoc/filters/handlebars.rb
nanoc-4.9.8 lib/nanoc/filters/handlebars.rb
nanoc-4.9.7 lib/nanoc/filters/handlebars.rb
nanoc-4.9.6 lib/nanoc/filters/handlebars.rb
nanoc-4.9.5 lib/nanoc/filters/handlebars.rb
nanoc-4.9.4 lib/nanoc/filters/handlebars.rb