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) ⇒ Transformer

Returns a new instance of Transformer.



20
21
22
23
# File 'lib/pug-rails/sprockets/transformer.rb', line 20

def initialize(filename)
  @filename = filename
  @source   = yield
end

Class Method Details

.cache_keyObject



46
47
48
49
50
51
52
53
54
# File 'lib/pug-rails/sprockets/transformer.rb', line 46

def self.cache_key
  [name,
   PUG_RUBY_GEM_VERSION,
   PUG_RAILS_GEM_VERSION,
   Pug.compiler.version,
   Pug.compiler.class.name,
   Digest::SHA1.hexdigest(Pug.config.to_h.to_a.flatten.map(&:to_s).join(","))
  ].join(":").freeze
end

.call(input) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/pug-rails/sprockets/transformer.rb', line 37

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



33
34
35
# File 'lib/pug-rails/sprockets/transformer.rb', line 33

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

Instance Method Details

#cache_keyObject



29
30
31
# File 'lib/pug-rails/sprockets/transformer.rb', line 29

def cache_key
  self.class.cache_key
end

#render(context, _) ⇒ Object



25
26
27
# File 'lib/pug-rails/sprockets/transformer.rb', line 25

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