Class: QuickStart::Template
- Inherits:
-
Object
- Object
- QuickStart::Template
- Includes:
- Contracts::Builtin, Contracts::Core
- 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.
13 14 15 16 |
# File 'lib/quickstart/template.rb', line 13 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.
10 11 12 |
# File 'lib/quickstart/template.rb', line 10 def path @path end |
Instance Method Details
#directories ⇒ Object
29 30 31 32 33 |
# File 'lib/quickstart/template.rb', line 29 def directories Dir.glob("#{path}/**/*/").map do |directory| directory.tap { |d| d.slice! %r{^#{Regexp.quote path}/} } end end |
#files ⇒ Object
36 37 38 39 40 |
# File 'lib/quickstart/template.rb', line 36 def files Dir.glob("#{path}/**/*").map do |file| file.tap { |f| f.slice! %r{^#{Regexp.quote path}/} } end end |
#render(name, overrides = {}) ⇒ Object
43 44 45 46 |
# File 'lib/quickstart/template.rb', line 43 def render(name, overrides = {}) template = "#{path}/#{name}" Tilt::ErubisTemplate.new(template).render(Object.new, overrides) end |
#root ⇒ Object
24 25 26 |
# File 'lib/quickstart/template.rb', line 24 def root File. ENV.fetch('QUICKSTART_TEMPLATES', './templates') end |