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.8.15 lib/nanoc/filters/erubi.rb