Class: Tiltout
- Inherits:
-
Object
- Object
- Tiltout
- Defined in:
- lib/tiltout/version.rb,
lib/tiltout.rb
Overview
– The MIT License (MIT)
Copyright © 2012 Gitorious AS
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Defined Under Namespace
Modules: Partials
Constant Summary collapse
- VERSION =
"1.4.0"
Instance Attribute Summary collapse
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #helper(helpers) ⇒ Object
-
#initialize(template_root, opt = {}) ⇒ Tiltout
constructor
A new instance of Tiltout.
- #render(template, locals = {}, options = {}) ⇒ Object
- #render_in_context(context, template, locals, &block) ⇒ Object
Constructor Details
#initialize(template_root, opt = {}) ⇒ Tiltout
Returns a new instance of Tiltout.
32 33 34 35 36 37 38 39 |
# File 'lib/tiltout.rb', line 32 def initialize(template_root, opt = {}) @paths = Array(template_root) @cache = {} if !opt.key?(:cache) || opt[:cache] @layout = opt[:layout] @default_type = opt[:default_type] || "erb" @context_class = Class.new helper(opt[:helpers]) end |
Instance Attribute Details
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
30 31 32 |
# File 'lib/tiltout.rb', line 30 def paths @paths end |
Instance Method Details
#helper(helpers) ⇒ Object
41 42 43 44 45 |
# File 'lib/tiltout.rb', line 41 def helper(helpers) return if helpers.nil? helpers = [helpers] unless helpers.is_a?(Array) helpers.each { |h| @context_class.send(:include, helper_module(h)) } end |
#render(template, locals = {}, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tiltout.rb', line 47 def render(template, locals = {}, = {}) context = @context_class.new context.renderer = self if context.respond_to?(:renderer=) content = render_in_context(context, template, locals) layout_tpl = .key?(:layout) ? [:layout] : @layout if !layout_tpl.nil? content = render_in_context(context, layout_tpl, locals) { content } end content end |
#render_in_context(context, template, locals, &block) ⇒ Object
60 61 62 |
# File 'lib/tiltout.rb', line 60 def render_in_context(context, template, locals, &block) load(template).render(context, locals, &block) end |