Sha256: 6240bebab2ff2135e1aab22cc6665e3b8bfecf7be30d77ca53191c75d675ebc1

Contents?: true

Size: 873 Bytes

Versions: 1

Compression:

Stored size: 873 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Pug
  module Sprockets
    # Sprockets 2, 3 & 4 interface
    # https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#registering-all-versions-of-sprockets-in-processors
    class Transformer
      def initialize(filename, &block)
        @filename = filename
        @source   = block.call
      end

      def render(context, _)
        self.class.run(@filename, @source, context)
      end

      def self.run(filename, source, context)
        Pug.compile(source, filename: filename, client: true)
      end

      def self.call(input)
        filename = input[:filename]
        source   = input[:data]
        context  = input[:environment].context_class.new(input)

        result = run(filename, source, context)
        context.metadata.merge(data: result)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pug-rails-2.0.3 lib/pug-rails/sprockets/transformer.rb