Class: HamlCoffeeTemplate::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/haml_coffee_template/processor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, &block) ⇒ Processor

Returns a new instance of Processor.



3
4
5
6
# File 'lib/haml_coffee_template/processor.rb', line 3

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

Class Method Details

.call(input) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/haml_coffee_template/processor.rb', line 19

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

.compilerObject



27
28
29
# File 'lib/haml_coffee_template/processor.rb', line 27

def self.compiler
  @compiler ||= Compiler.new
end

.run(filename, source, context) ⇒ Object



12
13
14
15
16
17
# File 'lib/haml_coffee_template/processor.rb', line 12

def self.run(filename, source, context)
  compiler.template(context.logical_path, source)
rescue StandardError => e
  STDOUT.puts("(#{name}) Failed to compile: #{filename}")
  raise e
end

Instance Method Details

#render(context, _empty_hash_wtf) ⇒ Object



8
9
10
# File 'lib/haml_coffee_template/processor.rb', line 8

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