Module: Renee::Render
- Defined in:
- lib/renee_render.rb,
lib/renee_render/version.rb
Overview
This module is responsible for handling the rendering of templates using Tilt supporting all included template engines.
Defined Under Namespace
Modules: ClassMethods Classes: TemplateNotFound
Constant Summary collapse
- VERSION =
The current version of Renee::Render
Renee::Core::VERSION
Instance Method Summary collapse
-
#inline(data, engine, options = nil, &block) ⇒ String
Renders a string given the engine and the content.
-
#inline!(data, engine, options = {}, &blk) ⇒ String
Same as inline but automatically halts.
-
#partial(template, options = {}) ⇒ String
Render a partials with collections support.
-
#render(file, engine = nil, options = nil, &block) ⇒ String
Renders a file given the engine and the content.
-
#render!(file, engine = nil, options = nil, &blk) ⇒ String
Same as render but automatically halts.
Instance Method Details
#inline(data, engine, options = nil, &block) ⇒ String
Renders a string given the engine and the content.
it will be detected based on the extension of the file.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/renee_render.rb', line 114 def inline(data, engine, = nil, &block) , engine = engine, nil if engine.is_a?(Hash) call_data = && .delete(:_caller) || Callsite.parse(caller.first) render_setup(engine, , block) do |, views| body = data.is_a?(Proc) ? data : Proc.new { data } template = Tilt[engine] raise "Template engine not found: #{engine}" if template.nil? template.new(call_data.filename, call_data.line, , &body) end end |
#inline!(data, engine, options = {}, &blk) ⇒ String
Same as inline but automatically halts.
64 65 66 67 |
# File 'lib/renee_render.rb', line 64 def inline!(data, engine, = {}, &blk) [:_caller] = Callsite.parse(caller.first) halt inline(data, engine, , &blk) end |
#partial(template, options = {}) ⇒ String
Render a partials with collections support
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/renee_render.rb', line 135 def partial(template, ={}) = { :locals => {}, :layout => false }.merge() path = template.to_s.split(File::SEPARATOR) object_name = path[-1].to_sym path[-1] = "_#{path[-1]}" template_path = File.join(path).to_sym raise 'Partial collection specified but is nil' if .has_key?(:collection) && [:collection].nil? if collection = .delete(:collection) .delete(:object) counter = 0 collection.map { |member| counter += 1 [:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter) render(template_path, .dup) }.join("\n") else if member = .delete(:object) [:locals].merge!(object_name => member) end render(template_path, .dup) end end |
#render(file, engine = nil, options = nil, &block) ⇒ String
Renders a file given the engine and the content.
it will be detected based on the extension of the file.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/renee_render.rb', line 85 def render(file, engine = nil, = nil, &block) , engine = engine, nil if engine.is_a?(Hash) render_setup(engine, , block) do |, views| template_cache.fetch(engine, file, ) do file_path, found_engine = find_template(views, file, engine) template = Tilt[found_engine] raise TemplateNotFound, "Template engine not found: #{found_engine.inspect}" unless template raise TemplateNotFound, "Template #{file.inspect} (with engine #{engine.inspect}) not found in #{views.inspect}!" unless file_path # TODO suppress errors for layouts? template.new(file_path, 1, ) end end end |
#render!(file, engine = nil, options = nil, &blk) ⇒ String
Same as render but automatically halts.
56 57 58 |
# File 'lib/renee_render.rb', line 56 def render!(file, engine = nil, = nil, &blk) halt render(file, engine, , &blk) end |