Module: Yaframework::Render
- Included in:
- Base
- Defined in:
- lib/yaframework/render.rb
Instance Method Summary collapse
- #partial(template, locals = {}) ⇒ Object
- #render(template, locals = {}, layout = ) ⇒ Object
- #setup(settings = {}) ⇒ Object
- #template_path(template) ⇒ Object
- #view(template, locals = {}, layout = ) ⇒ Object
Instance Method Details
#partial(template, locals = {}) ⇒ Object
26 27 28 |
# File 'lib/yaframework/render.rb', line 26 def partial(template, locals = {}) _render(template_path(template), locals, @settings[:options]) end |
#render(template, locals = {}, layout = ) ⇒ Object
17 18 19 20 |
# File 'lib/yaframework/render.rb', line 17 def render(template, locals = {}, layout = @settings[:layout]) res.headers["Content-Type"] ||= "text/html; charset=utf-8" res.write(view(template, locals, layout)) end |
#setup(settings = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/yaframework/render.rb', line 7 def setup(settings = {}) @settings = settings @settings[:template_engine] ||= "erb" @settings[:layout] ||= "layout" @settings[:views] ||= File.("views", Dir.pwd) @settings[:options] ||= { default_encoding: Encoding.default_external } end |
#template_path(template) ⇒ Object
30 31 32 33 34 |
# File 'lib/yaframework/render.rb', line 30 def template_path(template) dir = @settings[:views] ext = @settings[:template_engine] File.join(dir, "#{template}.#{ext}") end |
#view(template, locals = {}, layout = ) ⇒ Object
22 23 24 |
# File 'lib/yaframework/render.rb', line 22 def view(template, locals = {}, layout = @settings[:layout]) partial(layout, locals.merge(content: partial(template, locals))) end |