Class: QuickStart::Template
- Inherits:
-
Object
- Object
- QuickStart::Template
- Includes:
- Contracts
- Defined in:
- lib/quickstart/template.rb
Overview
Templating for QuickStart
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #directories ⇒ Object
- #files ⇒ Object
-
#initialize(name) ⇒ Template
constructor
A new instance of Template.
- #render(name, overrides = {}) ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(name) ⇒ Template
Returns a new instance of Template.
12 13 14 15 |
# File 'lib/quickstart/template.rb', line 12 def initialize(name) @name = name fail LoadError, "#{path} does not exist" unless Dir.exist? path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/quickstart/template.rb', line 9 def path @path end |
Instance Method Details
#directories ⇒ Object
28 29 30 31 32 |
# File 'lib/quickstart/template.rb', line 28 def directories Dir.glob("#{path}/**/*/").map do |directory| directory.tap { |d| d.slice! %r{^#{Regexp.quote path}/} } end end |
#files ⇒ Object
35 36 37 38 39 |
# File 'lib/quickstart/template.rb', line 35 def files Dir.glob("#{path}/**/*").map do |file| file.tap { |f| f.slice! %r{^#{Regexp.quote path}/} } end end |
#render(name, overrides = {}) ⇒ Object
42 43 44 45 |
# File 'lib/quickstart/template.rb', line 42 def render(name, overrides = {}) template = "#{path}/#{name}" Tilt::ErubisTemplate.new(template).render(Object.new, overrides) end |
#root ⇒ Object
23 24 25 |
# File 'lib/quickstart/template.rb', line 23 def root File. ENV.fetch('QUICKSTART_TEMPLATES', './templates') end |