Sha256: f811c3babdb26a84b748762868907b35ec48e16a469758359418e2b8cfc477ae

Contents?: true

Size: 698 Bytes

Versions: 1

Compression:

Stored size: 698 Bytes

Contents

module Munge
  module Transformer
    class Tilt
      def initialize(scope)
        @pristine_scope = scope
      end

      def name
        :tilt
      end

      def call(item, content = nil, renderer = nil)
        scope = @pristine_scope.dup
        scope.instance_variable_set :@renderer, @renderer
        dirty_scope = extend_with_helpers(scope)
        dirty_scope.render_with_layout(item, content_engines: renderer, content_override: content)
      end

      private

      def extend_with_helpers(scope)
        Munge::Helper.constants
          .map  { |sym| Munge::Helper.const_get(sym) }
          .inject(scope) { |scope, helper| scope.extend(helper) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
munge-0.4.0 lib/munge/transformer/tilt.rb