Included Modules

Innate::View

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

Constants

TEMP

Public Instance Methods

compile(string) click to toggle source
    # File lib/innate/view.rb, line 24
24:     def compile(string)
25:       return yield(string.to_s) unless View.options.cache
26:       string = string.to_s
27:       checksum = Digest::MD5.hexdigest(string)
28:       Cache.view[checksum] ||= yield(string)
29:     end
exts_of(engine) click to toggle source
    # File lib/innate/view.rb, line 31
31:     def exts_of(engine)
32:       name = engine.to_s
33:       ENGINE.reject{|ext, klass| klass != name }.keys
34:     end
get(engine) click to toggle source

Try to obtain given engine by its registered name.

    # File lib/innate/view.rb, line 37
37:     def get(engine)
38:       if klass = TEMP[engine]
39:         return klass
40:       elsif klass = ENGINE[engine]
41:         TEMP[engine] = obtain(klass)
42:       else
43:         TEMP[engine] = obtain(engine, View)
44:       end
45:     end
obtain(klass, root = Object) click to toggle source

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.

    # File lib/innate/view.rb, line 51
51:     def obtain(klass, root = Object)
52:       Innate.sync do
53:         view_name = /^#{klass.to_s.downcase.dup.delete('_')}$/
54:         if view = View.constants.grep(view_name).first
55:           root.const_get(view)
56:         else
57:           raise(NameError, "View #{klass} not found")
58:         end
59:       end
60:     end
read(view) click to toggle source

Reads the specified view template from the filesystem. When the read_cache option is enabled, templates will be cached to prevent unnecessary filesystem reads in the future.

@example usage

  View.read('some/file.xhtml')

@param [#] view

@api private @see Action#render

    # File lib/innate/view.rb, line 74
74:     def read(view)
75:       return Cache.view[view] ||= ::File.read(view) if View.options.read_cache
76:       ::File.read(view)
77:     end
register(klass, *exts) click to toggle source

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 #

         that indicate which filename-extensions the templates may have.
    # File lib/innate/view.rb, line 84
84:     def register(klass, *exts)
85:       exts.each do |ext|
86:         ext = ext.to_s
87:         engine = ENGINE[ext]
88:         Log.warn("overwriting %p, was set to %p" % [ext, engine]) if engine
89:         ENGINE[ext] = klass
90:       end
91:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.