Module: Innate::View
- Includes:
- Optioned
- Defined in:
- /home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb,
lib/ramaze/view/slim.rb,
/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view/erb.rb,
/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view/none.rb,
/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/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, Slim
Class Method Summary (collapse)
-
+ (Object) compile(string)
-
+ (Object) exts_of(engine)
-
+ (Object) get(engine)
Try to obtain given engine by its registered name.
-
+ (Object) obtain(klass, root = 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).
-
+ (Object) read(view)
private
Reads the specified view template from the filesystem.
-
+ (Object) register(klass, *exts)
Register given templating engine wrapper and extensions for later usage.
Instance Method Summary (collapse)
-
- (Object) compile(string)
private
-
- (Object) exts_of(engine)
private
-
- (Object) get(engine)
private
Try to obtain given engine by its registered name.
-
- (Object) obtain(klass, root = Object)
private
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).
-
- (Object) read(view)
private
private
Reads the specified view template from the filesystem.
-
- (Object) register(klass, *exts)
private
Register given templating engine wrapper and extensions for later usage.
Methods included from Optioned
Class Method Details
+ (Object) compile(string)
24 25 26 27 28 29 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 24 def compile(string) return yield(string.to_s) unless View..cache string = string.to_s checksum = Digest::MD5.hexdigest(string) Cache.view[checksum] ||= yield(string) end |
+ (Object) exts_of(engine)
31 32 33 34 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 31 def exts_of(engine) name = engine.to_s ENGINE.reject{|ext, klass| klass != name }.keys end |
+ (Object) get(engine)
Try to obtain given engine by its registered name.
37 38 39 40 41 42 43 44 45 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/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 |
+ (Object) obtain(klass, root = 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.
51 52 53 54 55 56 57 58 59 60 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 51 def obtain(klass, root = Object) Innate.sync do view_name = /^#{klass.to_s.downcase.dup.delete('_')}$/i if view = View.constants.grep(view_name).first root.const_get(view) else raise(NameError, "View #{klass} not found") end end end |
+ (Object) read(view)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
74 75 76 77 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 74 def read(view) return Cache.view[view] ||= ::File.read(view) if View..read_cache ::File.read(view) end |
+ (Object) register(klass, *exts)
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.
84 85 86 87 88 89 90 91 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/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 |
Instance Method Details
- (Object) compile(string) (private)
24 25 26 27 28 29 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 24 def compile(string) return yield(string.to_s) unless View..cache string = string.to_s checksum = Digest::MD5.hexdigest(string) Cache.view[checksum] ||= yield(string) end |
- (Object) exts_of(engine) (private)
31 32 33 34 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 31 def exts_of(engine) name = engine.to_s ENGINE.reject{|ext, klass| klass != name }.keys end |
- (Object) get(engine) (private)
Try to obtain given engine by its registered name.
37 38 39 40 41 42 43 44 45 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/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 |
- (Object) obtain(klass, root = Object) (private)
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.
51 52 53 54 55 56 57 58 59 60 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 51 def obtain(klass, root = Object) Innate.sync do view_name = /^#{klass.to_s.downcase.dup.delete('_')}$/i if view = View.constants.grep(view_name).first root.const_get(view) else raise(NameError, "View #{klass} not found") end end end |
- (Object) read(view) (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
74 75 76 77 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/view.rb', line 74 def read(view) return Cache.view[view] ||= ::File.read(view) if View..read_cache ::File.read(view) end |
- (Object) register(klass, *exts) (private)
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.
84 85 86 87 88 89 90 91 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/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 |