Sha256: 3d127cd53b7c48551d704f1169879fe4b356ea6a72b529f010d330757e89bbd2

Contents?: true

Size: 712 Bytes

Versions: 3

Compression:

Stored size: 712 Bytes

Contents

# encoding: utf-8

module Nanoc3::Filters
  class ERB < Nanoc3::Filter

    # Runs the content through [ERB](http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html).
    # This method takes no options.
    #
    # @param [String] content The content to filter
    #
    # @return [String] The filtered content
    def run(content, params={})
      require 'erb'

      # Create context
      context = ::Nanoc3::Context.new(assigns)

      # Get binding
      proc = assigns[:content] ? lambda { assigns[:content] } : nil
      assigns_binding = context.get_binding(&proc)

      # Get result
      erb = ::ERB.new(content)
      erb.filename = filename
      erb.result(assigns_binding)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nanoc3-3.1.9 lib/nanoc3/filters/erb.rb
nanoc3-3.1.8 lib/nanoc3/filters/erb.rb
nanoc3-3.1.7 lib/nanoc3/filters/erb.rb