Class: Expansions::TemplateProcessors

Inherits:
Object
  • Object
show all
Defined in:
lib/expansions/template_processors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processors = {}) ⇒ TemplateProcessors

Returns a new instance of TemplateProcessors.



5
6
7
# File 'lib/expansions/template_processors.rb', line 5

def initialize(processors={})
  @processors = processors
end

Instance Attribute Details

#processorsObject (readonly)

Returns the value of attribute processors.



3
4
5
# File 'lib/expansions/template_processors.rb', line 3

def processors
  @processors
end

Instance Method Details

#get_processor_for(file_name) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/expansions/template_processors.rb', line 9

def get_processor_for(file_name)
  template_type = File.extname(file_name).gsub(/\./,'').to_sym

  raise "There is no processor for #{file_name}" unless processor?(template_type)

  return processors[template_type]
end

#processor?(template_type) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/expansions/template_processors.rb', line 23

def processor?(template_type)
  return processors.has_key?(template_type.to_sym)
end

#register_processor(template_type, processor) ⇒ Object



17
18
19
20
21
# File 'lib/expansions/template_processors.rb', line 17

def register_processor(template_type,processor)
  raise "The processor for the template already exists" if processor?(template_type)

  processors[template_type.to_sym] = processor
end