Class: Mack::Rendering::Engine::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mack/rendering/engine/registry.rb

Overview

A registry used to store which Mack::Rendering::Type objects can use which Mack::Rendering::Engine objects.

Example:

Mack::Rendering::Engine::Registry.register(:bar, :sass)
render(:bar, "my_file") will now get run through Mack::Rendering::Type::Bar and Mack::Rendering::Engine::Sass

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



15
16
17
18
19
20
21
22
23
# File 'lib/mack/rendering/engine/registry.rb', line 15

def initialize
  @engines = {
    :action => [:erubis, :builder],
    :template => [:erubis, :builder],
    :partial => [:erubis, :builder],
    :layout => [:erubis],
    :xml => [:builder, :erubis]
  }
end

Instance Attribute Details

#enginesObject (readonly)

Returns all the engines registered with the system.



13
14
15
# File 'lib/mack/rendering/engine/registry.rb', line 13

def engines
  @engines
end

Class Method Details

.method_missing(sym, *args) ⇒ Object



40
41
42
# File 'lib/mack/rendering/engine/registry.rb', line 40

def method_missing(sym, *args)
  Mack::Rendering::Engine::Registry.instance.send(sym, *args)
end

Instance Method Details

#register(type, engine) ⇒ Object

Registers an engine to a type.

Example: Mack::Rendering::Engine::Registry.register(:action, :haml)



29
30
31
32
33
34
35
36
# File 'lib/mack/rendering/engine/registry.rb', line 29

def register(type, engine)
  type = type.to_sym
  if self.engines.has_key?(type)
    self.engines[type].insert(0, engine)
  else
    self.engines[type] = [engine]
  end
end