Sha256: ed709ba9a17db60fd616dcced703e54d3586cb569a5b5bffcebb58e404e71603

Contents?: true

Size: 947 Bytes

Versions: 21

Compression:

Stored size: 947 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
      engine_opts = { bufvar: '_erbout', filename: filename }.merge(params)
      engine = ::Erubi::Engine.new(content, engine_opts)
      eval(engine.src, assigns_binding, filename)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
nanoc-4.11.0 lib/nanoc/filters/erubi.rb
nanoc-4.10.4 lib/nanoc/filters/erubi.rb
nanoc-4.10.3 lib/nanoc/filters/erubi.rb
nanoc-4.10.2 lib/nanoc/filters/erubi.rb
nanoc-4.10.1 lib/nanoc/filters/erubi.rb
nanoc-4.10.0 lib/nanoc/filters/erubi.rb
nanoc-4.9.9 lib/nanoc/filters/erubi.rb
nanoc-4.9.8 lib/nanoc/filters/erubi.rb
nanoc-4.9.7 lib/nanoc/filters/erubi.rb
nanoc-4.9.6 lib/nanoc/filters/erubi.rb
nanoc-4.9.5 lib/nanoc/filters/erubi.rb
nanoc-4.9.4 lib/nanoc/filters/erubi.rb
nanoc-4.9.3 lib/nanoc/filters/erubi.rb
nanoc-4.9.2 lib/nanoc/filters/erubi.rb
nanoc-4.9.1 lib/nanoc/filters/erubi.rb
nanoc-4.9.0 lib/nanoc/filters/erubi.rb
nanoc-4.8.19 lib/nanoc/filters/erubi.rb
nanoc-4.8.18 lib/nanoc/filters/erubi.rb
nanoc-4.8.17 lib/nanoc/filters/erubi.rb
nanoc-4.8.16 lib/nanoc/filters/erubi.rb