Module: Roda::RodaPlugins::Render::InstanceMethods
- Defined in:
- lib/roda/plugins/render.rb
Instance Method Summary collapse
-
#render(template, opts = {}, &block) ⇒ Object
Render the given template.
-
#render_opts ⇒ Object
Return the render options for the instance’s class.
-
#view(template, opts = {}) ⇒ Object
Render the given template.
Instance Method Details
#render(template, opts = {}, &block) ⇒ Object
Render the given template. See Render for details.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/roda/plugins/render.rb', line 123 def render(template, opts = {}, &block) if template.is_a?(Hash) if opts.empty? opts = template else opts = opts.merge(template) end end render_opts = render_opts() if content = opts[:inline] path = content template_block = Proc.new{content} template_class = ::Tilt[opts[:engine] || render_opts[:engine]] else template_class = ::Tilt unless path = opts[:path] path = template_path(template, opts) end end cached_template(path) do template_class.new(path, 1, render_opts[:opts].merge(opts), &template_block) end.render(self, opts[:locals], &block) end |
#render_opts ⇒ Object
Return the render options for the instance’s class.
150 151 152 |
# File 'lib/roda/plugins/render.rb', line 150 def render_opts self.class.render_opts end |
#view(template, opts = {}) ⇒ Object
Render the given template. If there is a default layout for the class, take the result of the template rendering and render it inside the layout. See Render for details.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/roda/plugins/render.rb', line 157 def view(template, opts={}) if template.is_a?(Hash) if opts.empty? opts = template else opts = opts.merge(template) end end content = opts[:content] || render(template, opts) if layout = opts.fetch(:layout, render_opts[:layout]) if layout_opts = opts[:layout_opts] layout_opts = render_opts[:layout_opts].merge(layout_opts) end content = render(layout, layout_opts||{}){content} end content end |