Sha256: 8c734eda62d3fccd9699013b076911e677b918a515dbf0e6ea57eb0e1542c76f

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8                                                                                                           

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

    requires 'erb'

    # 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

8 entries across 8 versions & 1 rubygems

Version Path
nanoc-3.6.7 lib/nanoc/filters/erb.rb
nanoc-3.6.6 lib/nanoc/filters/erb.rb
nanoc-3.6.5 lib/nanoc/filters/erb.rb
nanoc-3.6.4 lib/nanoc/filters/erb.rb
nanoc-3.6.3 lib/nanoc/filters/erb.rb
nanoc-3.6.2 lib/nanoc/filters/erb.rb
nanoc-3.6.1 lib/nanoc/filters/erb.rb
nanoc-3.6.0 lib/nanoc/filters/erb.rb