Class: Radical::View
- Inherits:
-
Object
- Object
- Radical::View
- Defined in:
- lib/radical/view.rb
Class Attribute Summary collapse
-
._layout ⇒ Object
Returns the value of attribute _layout.
-
._views_path ⇒ Object
Returns the value of attribute _views_path.
Class Method Summary collapse
- .layout(name) ⇒ Object
- .path(path = nil) ⇒ Object
- .render(dir, name, scope, options = {}) ⇒ Object
- .template(dir, name) ⇒ Object
- .template!(dir, name) ⇒ Object
- .view_path(dir, name) ⇒ Object
- .view_path!(dir, name) ⇒ Object
Class Attribute Details
._layout ⇒ Object
Returns the value of attribute _layout.
23 24 25 |
# File 'lib/radical/view.rb', line 23 def _layout @_layout end |
._views_path ⇒ Object
Returns the value of attribute _views_path.
23 24 25 |
# File 'lib/radical/view.rb', line 23 def _views_path @_views_path end |
Class Method Details
.layout(name) ⇒ Object
49 50 51 |
# File 'lib/radical/view.rb', line 49 def layout(name) @_layout = name end |
.path(path = nil) ⇒ Object
45 46 47 |
# File 'lib/radical/view.rb', line 45 def path(path = nil) @_views_path = path end |
.render(dir, name, scope, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/radical/view.rb', line 53 def render(dir, name, scope, = {}) t = template!(dir, name) layout = template('', @_layout || 'layout') unless [:layout] != false if layout layout.render scope, {} do t.render scope, [:locals] || {} end else t.render scope end end |
.template(dir, name) ⇒ Object
37 38 39 |
# File 'lib/radical/view.rb', line 37 def template(dir, name) Tilt.new(view_path(dir, name), engine_class: CaptureEngine, escape_html: true) end |
.template!(dir, name) ⇒ Object
41 42 43 |
# File 'lib/radical/view.rb', line 41 def template!(dir, name) Tilt.new(view_path!(dir, name), engine_class: CaptureEngine, escape_html: true) end |
.view_path(dir, name) ⇒ Object
33 34 35 |
# File 'lib/radical/view.rb', line 33 def view_path(dir, name) File.join(@_views_path || '.', 'views', dir, "#{name}.erb") end |
.view_path!(dir, name) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/radical/view.rb', line 25 def view_path!(dir, name) filename = view_path(dir, name) raise "Could not find view file: #{filename}. You need to create it." unless File.exist?(filename) filename end |