Sha256: 171b5a2137d8a9d002345d9bf771ac517516c305f3f94291b3eff87ea1444bfa

Contents?: true

Size: 883 Bytes

Versions: 20

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Filters
  # @api private
  class Erubi < Nanoc::Filter
    identifier :erubi

    requires 'erubi'

    # Runs the content through [Erubi](https://github.com/jeremyevans/erubi).
    # To prevent single quote escaping use :escapefunc => 'Nanoc::Helpers::HTMLEscape.html_escape'
    # See the Erubi documentation for more options.
    #
    # @param [String] content The content to filter
    #
    # @return [String] The filtered content
    def run(content, params = {})
      # Create context
      context = ::Nanoc::Int::Context.new(assigns)

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

      # Get result
      eval(::Erubi::Engine.new(content, { bufvar: '_erbout', filename: filename }.merge(params)).src, assigns_binding)
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nanoc-4.8.14 lib/nanoc/filters/erubi.rb
nanoc-4.8.13 lib/nanoc/filters/erubi.rb
nanoc-4.8.12 lib/nanoc/filters/erubi.rb
nanoc-4.8.11 lib/nanoc/filters/erubi.rb
nanoc-4.8.10 lib/nanoc/filters/erubi.rb
nanoc-4.8.9 lib/nanoc/filters/erubi.rb
nanoc-4.8.8 lib/nanoc/filters/erubi.rb
nanoc-4.8.7 lib/nanoc/filters/erubi.rb
nanoc-4.8.6 lib/nanoc/filters/erubi.rb
nanoc-4.8.5 lib/nanoc/filters/erubi.rb
nanoc-4.8.4 lib/nanoc/filters/erubi.rb
nanoc-4.8.3 lib/nanoc/filters/erubi.rb
nanoc-4.8.2 lib/nanoc/filters/erubi.rb
nanoc-4.8.1 lib/nanoc/filters/erubi.rb
nanoc-4.8.0 lib/nanoc/filters/erubi.rb
nanoc-4.7.14 lib/nanoc/filters/erubi.rb
nanoc-4.7.13 lib/nanoc/filters/erubi.rb
nanoc-4.7.12 lib/nanoc/filters/erubi.rb
nanoc-4.7.11 lib/nanoc/filters/erubi.rb
nanoc-4.7.10 lib/nanoc/filters/erubi.rb