Class: Wukong::Deploy::Templater
- Inherits:
-
Object
- Object
- Wukong::Deploy::Templater
- Includes:
- FileUtils::Verbose
- Defined in:
- lib/wukong-deploy/templater.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#repo ⇒ Object
Returns the value of attribute repo.
Instance Method Summary collapse
- #create ⇒ Object
- #create_dirs ⇒ Object
- #create_gitignore ⇒ Object
- #create_gitkeeps ⇒ Object
- #create_template(input_path, output_path, binding = {}) ⇒ Object
- #create_templates ⇒ Object
-
#initialize(root, options = {}) ⇒ Templater
constructor
A new instance of Templater.
- #templates_dir ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/wukong-deploy/templater.rb', line 12 def @options end |
#repo ⇒ Object
Returns the value of attribute repo.
11 12 13 |
# File 'lib/wukong-deploy/templater.rb', line 11 def repo @repo end |
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 |
# File 'lib/wukong-deploy/templater.rb', line 21 def create create_dirs create_templates create_gitkeeps create_gitignore end |
#create_dirs ⇒ Object
28 29 30 |
# File 'lib/wukong-deploy/templater.rb', line 28 def create_dirs repo.dirs_to_create.each { |dir| mkdir_p(dir) } end |
#create_gitignore ⇒ Object
55 56 57 |
# File 'lib/wukong-deploy/templater.rb', line 55 def create_gitignore create_template(templates_dir.join('gitignore'), repo.root.join('.gitignore')) end |
#create_gitkeeps ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/wukong-deploy/templater.rb', line 47 def create_gitkeeps repo.dirs_to_create.each do |dir| if Dir[File.join(dir, '*')].empty? touch(File.join(dir, '.gitkeep')) end end end |
#create_template(input_path, output_path, binding = {}) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/wukong-deploy/templater.rb', line 38 def create_template input_path, output_path, binding={} input = File.read(input_path) erb = Erubis::Eruby.new(input) output = erb.result(binding) action = File.exist?(output_path) ? 'modify' : 'create' puts "#{action} #{output_path}" File.open(output_path, 'w') { |f| f.puts(output) } end |
#create_templates ⇒ Object
32 33 34 35 36 |
# File 'lib/wukong-deploy/templater.rb', line 32 def create_templates repo.files_to_template.each do |repo_path| create_template(templates_dir.join("#{repo_path}.erb"), repo.root.join(repo_path)) end end |
#templates_dir ⇒ Object
59 60 61 |
# File 'lib/wukong-deploy/templater.rb', line 59 def templates_dir @templates_dir ||= Pathname.new(File.('../../../templates', __FILE__)) end |