Class: QuickStart::Template

Inherits:
Object
  • Object
show all
Includes:
Contracts
Defined in:
lib/quickstart/template.rb

Overview

Templating for QuickStart

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/quickstart/template.rb', line 9

def path
  @path
end

Instance Method Details

#directoriesObject



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

#filesObject



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

#rootObject



23
24
25
# File 'lib/quickstart/template.rb', line 23

def root
  File.expand_path ENV.fetch('QUICKSTART_TEMPLATES', './templates')
end