Class: Pug::Sprockets::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/pug-rails/sprockets/transformer.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, &block) ⇒ Transformer

Returns a new instance of Transformer.



9
10
11
12
# File 'lib/pug-rails/sprockets/transformer.rb', line 9

def initialize(filename, &block)
  @filename = filename
  @source   = block.call
end

Class Method Details

.call(input) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/pug-rails/sprockets/transformer.rb', line 22

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

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

.run(filename, source, context) ⇒ Object



18
19
20
# File 'lib/pug-rails/sprockets/transformer.rb', line 18

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

Instance Method Details

#render(context, _) ⇒ Object



14
15
16
# File 'lib/pug-rails/sprockets/transformer.rb', line 14

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