Class: Radical::View

Inherits:
Object
  • Object
show all
Defined in:
lib/radical/view.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

._layoutObject

Returns the value of attribute _layout.



23
24
25
# File 'lib/radical/view.rb', line 23

def _layout
  @_layout
end

._views_pathObject

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, options = {})
  t = template!(dir, name)

  layout = template('', @_layout || 'layout') unless options[:layout] != false

  if layout
    layout.render scope, {} do
      t.render scope, options[: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