Module: Innate::View

Defined in:
lib/innate/view.rb,
lib/innate/view/erb.rb,
lib/innate/view/none.rb,
lib/innate/view/etanni.rb

Overview

This is a container module for wrappers of templating engines and handles lazy requiring of needed engines.

Defined Under Namespace

Modules: ERB, Etanni, None

Class Method Summary collapse

Class Method Details

.exts_of(engine) ⇒ Object



11
12
13
14
# File 'lib/innate/view.rb', line 11

def exts_of(engine)
  name = engine.to_s
  ENGINE.reject{|k,v| v != name }.keys
end

.get(engine) ⇒ Object

Try to obtain given engine by its registered name.



17
18
19
20
21
22
23
24
25
# File 'lib/innate/view.rb', line 17

def get(engine)
  if klass = TEMP[engine]
    return klass
  elsif klass = ENGINE[engine]
    TEMP[engine] = obtain(klass)
  else
    TEMP[engine] = obtain(engine, View)
  end
end

.obtain(klass, root = Object) ⇒ Object

We need to put this in a Mutex because simultanous calls for the same class will cause race conditions and one call may return the wrong class on the first request (before TEMP is set). No mutex is used in Fiber environment, see Innate::State and subclasses.



31
32
33
34
35
36
# File 'lib/innate/view.rb', line 31

def obtain(klass, root = Object)
  STATE.sync do
    klass.to_s.scan(/\w+/){|part| root = root.const_get(part) }
    root
  end
end

.register(klass, *exts) ⇒ Object

Register given templating engine wrapper and extensions for later usage.

name : the class name of the templating engine wrapper exts : any number of arguments will be turned into strings via #to_s

that indicate which filename-extensions the templates may have.


43
44
45
46
47
48
49
50
# File 'lib/innate/view.rb', line 43

def register(klass, *exts)
  exts.each do |ext|
    ext = ext.to_s
    engine = ENGINE[ext]
    Log.warn("overwriting %p, was set to %p" % [ext, engine]) if engine
    ENGINE[ext] = klass
  end
end