Class: TTY::Templater
- Inherits:
-
Object
- Object
- TTY::Templater
- Includes:
- PathHelpers
- Defined in:
- lib/tty/templater.rb
Instance Attribute Summary collapse
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
-
#add_mapping(source, target) ⇒ Object
Add mapping to templates.
-
#generate(template_options, color_option) ⇒ Object
private
Process templates by injecting vars and moving to location.
-
#initialize(source_path, target_path) ⇒ Templater
constructor
A new instance of Templater.
-
#templates_root_path ⇒ Object
The root path for all the templates.
Methods included from PathHelpers
#name_from_path, #relative_path_from, #root_path, #within_root_path
Constructor Details
#initialize(source_path, target_path) ⇒ Templater
Returns a new instance of Templater.
13 14 15 16 17 |
# File 'lib/tty/templater.rb', line 13 def initialize(source_path, target_path) @source_path = templates_root_path.join(source_path) @target_path = target_path @templates = [] end |
Instance Attribute Details
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
11 12 13 |
# File 'lib/tty/templater.rb', line 11 def templates @templates end |
Instance Method Details
#add_mapping(source, target) ⇒ Object
Add mapping to templates
34 35 36 |
# File 'lib/tty/templater.rb', line 34 def add_mapping(source, target) @templates << [source, target] end |
#generate(template_options, color_option) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Process templates by injecting vars and moving to location
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tty/templater.rb', line 41 def generate(, color_option) templates.each do |src, dst| source = @source_path.join(src) destination = @target_path.join(dst).to_s next unless ::File.exist?(source) within_root_path do TTY::File.copy_file(source, destination, { context: }.merge(color_option)) end end end |
#templates_root_path ⇒ Object
The root path for all the templates
22 23 24 |
# File 'lib/tty/templater.rb', line 22 def templates_root_path Pathname(__dir__).join('templates') end |