Sha256: 3d5d03eb676eff1c3f7414fbd0eb7fef2ccc45d37b6a8062729cd5d87227aee7

Contents?: true

Size: 1.11 KB

Versions: 15

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8                                                                                                           

require 'erb'

module Nanoc::Filters
  class ERB < Nanoc::Filter

    # Runs the content through [ERB](http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html).
    #
    # @param [String] content The content to filter
    #
    # @option params [Integer] safe_level (nil) The safe level (`$SAFE`) to
    #   use while running this filter
    #
    # @option params [String] trim_mode (nil) The trim mode to use
    #
    # @return [String] The filtered content
    def run(content, params={})
      # Add locals
      assigns.merge!(params[:locals] || {})

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

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

      # Get result
      safe_level = params[:safe_level]
      trim_mode = params[:trim_mode]
      erb = ::ERB.new(content, safe_level, trim_mode)
      erb.filename = filename
      erb.result(assigns_binding)
    end 

  end 
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nanoc-3.5.0 lib/nanoc/filters/erb.rb
nanoc-3.5.0b2 lib/nanoc/filters/erb.rb
nanoc-3.5.0b1 lib/nanoc/filters/erb.rb
nanoc-3.4.3 lib/nanoc/filters/erb.rb
nanoc-3.4.2 lib/nanoc/filters/erb.rb
nanoc-3.4.1 lib/nanoc/filters/erb.rb
nanoc-3.4.0 lib/nanoc/filters/erb.rb
nanoc-3.3.7 lib/nanoc/filters/erb.rb
nanoc-3.3.6 lib/nanoc/filters/erb.rb
nanoc-3.3.5 lib/nanoc/filters/erb.rb
nanoc-3.3.4 lib/nanoc/filters/erb.rb
nanoc-3.3.3 lib/nanoc/filters/erb.rb
nanoc-3.3.2 lib/nanoc/filters/erb.rb
nanoc-3.3.1 lib/nanoc/filters/erb.rb
nanoc-3.3.0 lib/nanoc/filters/erb.rb