Class: Prow::Templates

Inherits:
Struct
  • Object
show all
Defined in:
lib/prow/templates.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



2
3
4
# File 'lib/prow/templates.rb', line 2

def path
  @path
end

Instance Method Details

#collectionObject



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

#loadObject



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

#partialsObject



15
16
17
# File 'lib/prow/templates.rb', line 15

def partials
  collection.select {|template| template.type == 'partials' }
end

#template(type, name) ⇒ Object

Raises:

  • (ArgumentError)


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