Sha256: f13355ac5d9f546b470c63c2475538157591ac2bbe421ce1b41e0591d2efe632

Contents?: true

Size: 1.03 KB

Versions: 20

Compression:

Stored size: 1.03 KB

Contents

module Nanoc::Filters
  # @api private
  class ERB < Nanoc::Filter
    identifier :erb

    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::Int::Context.new(assigns)

      # Get binding
      proc = assigns[:content] ? -> { 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

20 entries across 20 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/filters/erb.rb
nanoc-4.7.8 lib/nanoc/filters/erb.rb
nanoc-4.7.7 lib/nanoc/filters/erb.rb
nanoc-4.7.6 lib/nanoc/filters/erb.rb
nanoc-4.7.5 lib/nanoc/filters/erb.rb
nanoc-4.7.4 lib/nanoc/filters/erb.rb
nanoc-4.7.3 lib/nanoc/filters/erb.rb
nanoc-4.7.2 lib/nanoc/filters/erb.rb
nanoc-4.7.1 lib/nanoc/filters/erb.rb
nanoc-4.7.0 lib/nanoc/filters/erb.rb
nanoc-4.6.4 lib/nanoc/filters/erb.rb
nanoc-4.6.3 lib/nanoc/filters/erb.rb
nanoc-4.6.2 lib/nanoc/filters/erb.rb
nanoc-4.6.1 lib/nanoc/filters/erb.rb
nanoc-4.6.0 lib/nanoc/filters/erb.rb
nanoc-4.5.4 lib/nanoc/filters/erb.rb
nanoc-4.5.3 lib/nanoc/filters/erb.rb
nanoc-4.5.2 lib/nanoc/filters/erb.rb
nanoc-4.5.1 lib/nanoc/filters/erb.rb
nanoc-4.5.0 lib/nanoc/filters/erb.rb