Class: Prow::Templates
- Inherits:
-
Struct
- Object
- Struct
- Prow::Templates
- Defined in:
- lib/prow/templates.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #collection ⇒ Object
- #layout(name = 'default') ⇒ Object
- #load ⇒ Object
- #page(name) ⇒ Object
- #partial(name) ⇒ Object
- #partials ⇒ Object
- #template(type, name) ⇒ Object
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path
2 3 4 |
# File 'lib/prow/templates.rb', line 2 def path @path end |
Instance Method Details
#collection ⇒ Object
25 26 27 |
# File 'lib/prow/templates.rb', line 25 def collection @collection ||= load end |
#layout(name = 'default') ⇒ Object
3 4 5 |
# File 'lib/prow/templates.rb', line 3 def layout(name='default') template('layouts', name) end |
#load ⇒ Object
29 30 31 32 33 |
# File 'lib/prow/templates.rb', line 29 def load Dir.glob("#{path}/**/*.mustache").map do |template_path| Template.new(template_path, path) end end |
#page(name) ⇒ Object
7 8 9 |
# File 'lib/prow/templates.rb', line 7 def page(name) template('pages', name) end |
#partial(name) ⇒ Object
11 12 13 |
# File 'lib/prow/templates.rb', line 11 def partial(name) partials.detect {|t| t.name == name} end |
#partials ⇒ Object
15 16 17 |
# File 'lib/prow/templates.rb', line 15 def partials collection.select {|template| template.type == 'partials' } end |
#template(type, name) ⇒ Object
19 20 21 22 23 |
# File 'lib/prow/templates.rb', line 19 def template(type, name) found = collection.detect { |template| template.type == type && template.name == name } raise ArgumentError.new("#{type} #{name} not found") unless found found end |