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
def compile(string)
  return yield(string.to_s) unless View.options.cache
  string = string.to_s
  checksum = Digest::MD5.hexdigest(string)
  Cache.view[checksum] ||= yield(string)
end
exts_of(engine) click to toggle source
# File lib/innate/view.rb, line 31
def exts_of(engine)
  name = engine.to_s
  ENGINE.reject{|ext, klass| klass != name }.keys
end
get(engine) click to toggle source

Try to obtain given engine by its registered name.

# File lib/innate/view.rb, line 37
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) 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
def obtain(klass, root = Object)
  Innate.sync do
    view_name = /^#{klass.to_s.downcase.dup.delete('_')}$/
    if view = View.constants.grep(view_name).first
      root.const_get(view)
    else
      raise(NameError, "View #{klass} not found")
    end
  end
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 [to_str] view

@api private @see Action#render

# File lib/innate/view.rb, line 74
def read(view)
  return Cache.view[view] ||= ::File.read(view) if View.options.read_cache
  ::File.read(view)
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 to_s

that indicate which filename-extensions the templates may have.
# File lib/innate/view.rb, line 84
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.