Class: ProcessIt::Processors

Inherits:
Object
  • Object
show all
Defined in:
lib/processit/processors.rb

Constant Summary collapse

@@instance =
Processors.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessors

Returns a new instance of Processors.



5
6
7
8
# File 'lib/processit/processors.rb', line 5

def initialize
	@processors = {}
	@null_extention = {"output_ext" => nil, "klasses" => []}
end

Class Method Details

.instanceObject



12
13
14
# File 'lib/processit/processors.rb', line 12

def self.instance
	return @@instance
end

Instance Method Details

#process_extensionsObject

Returns an ‘Array` of processor extension `String`s.

environment.engine_extensions
# => ['.coffee', '.sass', ...]


39
40
41
# File 'lib/processit/processors.rb', line 39

def process_extensions
  @processors.keys
end

#processor(ext = nil) ⇒ Object

Returns a ‘Hash` of `Engine`s registered on the `Environment`. If an `ext` argument is supplied, the `Engine` associated with that extension will be returned.

processors
# => {".coffee" => CoffeeScriptTemplate, ".sass" => SassTemplate, ...}


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/processit/processors.rb', line 23

def processor(ext = nil)
  if ext
	ext = ProcessIt::Utils.normalize_extension(ext)
	processor = @processors[ext]
	if (processor)
		return processor
	end
  end

  return @null_extention
end

#register_processor(ext, output_ext, klasses = []) ⇒ Object

Registers a new Engine ‘klass` for `ext`. If the `ext` already has an engine registered, it will be overridden.

environment.register_engine '.coffee', CoffeeScriptTemplate


48
49
50
51
# File 'lib/processit/processors.rb', line 48

def register_processor(ext, output_ext, klasses = [])
  ext = ProcessIt::Utils.normalize_extension(ext)
  @processors[ext] = {"output_ext" => output_ext, "klasses" => klasses}
end