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.3.0"
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.
30 31 32 33 34 35 36 37 |
# File 'lib/tiltout.rb', line 30 def initialize(template_root, opt = {}) @template_root = 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 Method Details
#helper(helpers) ⇒ Object
39 40 41 42 43 |
# File 'lib/tiltout.rb', line 39 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
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tiltout.rb', line 45 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
58 59 60 |
# File 'lib/tiltout.rb', line 58 def render_in_context(context, template, locals, &block) load(template).render(context, locals, &block) end |