Sha256: 55511f48da7e0a29aa19ce328128be588e08f87f1379e3fabbdf1453ef98aff6

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8

module Nanoc::Filters
  # @api private
  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::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

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-4.0.0b1 lib/nanoc/filters/erb.rb
nanoc-4.0.0a2 lib/nanoc/filters/erb.rb
nanoc-4.0.0a1 lib/nanoc/filters/erb.rb