Class: Omniboard::Renderer
- Inherits:
-
Object
- Object
- Omniboard::Renderer
- Defined in:
- lib/omniboard/renderer.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
Instance Method Summary collapse
-
#add_column(*col) ⇒ Object
Add one or more columns to our array of columns.
-
#initialize ⇒ Renderer
constructor
A new instance of Renderer.
- #postamble ⇒ Object
- #preamble ⇒ Object
- #render_column(column) ⇒ Object
- #render_project(project) ⇒ Object
-
#template(template_name) ⇒ Object
Fetch a template from the templates folder.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Renderer
Returns a new instance of Renderer.
4 5 6 7 8 |
# File 'lib/omniboard/renderer.rb', line 4 def initialize() @columns = [] @current_column = nil @current_group = nil end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
2 3 4 |
# File 'lib/omniboard/renderer.rb', line 2 def columns @columns end |
Instance Method Details
#add_column(*col) ⇒ Object
Add one or more columns to our array of columns.
11 12 13 |
# File 'lib/omniboard/renderer.rb', line 11 def add_column(*col) @columns += col end |
#postamble ⇒ Object
25 26 27 |
# File 'lib/omniboard/renderer.rb', line 25 def postamble ERB.new(template "postamble").result(binding) end |
#preamble ⇒ Object
21 22 23 |
# File 'lib/omniboard/renderer.rb', line 21 def preamble ERB.new(template "preamble").result(binding) end |
#render_column(column) ⇒ Object
29 30 31 |
# File 'lib/omniboard/renderer.rb', line 29 def render_column(column) ERB.new(template("column")).result(binding) end |
#render_project(project) ⇒ Object
33 34 35 |
# File 'lib/omniboard/renderer.rb', line 33 def render_project(project) ERB.new(template("project")).result(binding) end |
#template(template_name) ⇒ Object
Fetch a template from the templates folder
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/omniboard/renderer.rb', line 38 def template(template_name) @templates ||= {} if !@templates.has_key?(template_name) template_file = template_name + ".erb" template_path = File.join(__dir__, "templates", template_file) raise(ArgumentError, "Attempting to find template #{template_file}, which does not exist.") unless File.exists?(template_path) @templates[template_name] = File.read(template_path) end @templates[template_name] end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/omniboard/renderer.rb', line 17 def to_s preamble + @columns.map{ |c| render_column(c) }.join("\n") + postamble end |