Class: Licensor::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/licensor/template.rb

Constant Summary collapse

EXTNAME =
".mustache"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTemplate

Returns a new instance of Template.



7
8
9
10
11
# File 'lib/licensor/template.rb', line 7

def initialize
  @templates = find_templates
  @licenses = @templates.map{|t| File.basename(t, EXTNAME) }
  @template_table = Hash[@licenses.zip(@templates)]
end

Instance Attribute Details

#licensesObject (readonly)

Returns the value of attribute licenses.



13
14
15
# File 'lib/licensor/template.rb', line 13

def licenses
  @licenses
end

Instance Method Details

#render(license, name, year) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/licensor/template.rb', line 15

def render(license, name, year)
  unless @licenses.include?(license)
    raise ArgumentError, "Given license `#{license}' is not supported. Try `--list' option to see all available licenses."
  end

  Mustache.render(File.read(@template_table[license]), name: name, year: year)
end