Module: Nesta::Commands::Command
- Included in:
- Demo::Content, New, Theme::Create, Theme::Enable, Theme::Install
- Defined in:
- lib/nesta/commands.rb
Instance Method Summary collapse
- #copy_template(src, dest) ⇒ Object
- #copy_templates(templates) ⇒ Object
- #fail(message) ⇒ Object
- #template_root ⇒ Object
- #update_config_yaml(pattern, replacement) ⇒ Object
Instance Method Details
#copy_template(src, dest) ⇒ Object
22 23 24 25 26 |
# File 'lib/nesta/commands.rb', line 22 def copy_template(src, dest) FileUtils.mkdir_p(File.dirname(dest)) template = ERB.new(File.read(File.join(template_root, src))) File.open(dest, 'w') { |file| file.puts template.result(binding) } end |
#copy_templates(templates) ⇒ Object
28 29 30 |
# File 'lib/nesta/commands.rb', line 28 def copy_templates(templates) templates.each { |src, dest| copy_template(src, dest) } end |
#fail(message) ⇒ Object
13 14 15 16 |
# File 'lib/nesta/commands.rb', line 13 def fail() $stderr.puts "Error: #{}" exit 1 end |
#template_root ⇒ Object
18 19 20 |
# File 'lib/nesta/commands.rb', line 18 def template_root File.('../../templates', File.dirname(__FILE__)) end |
#update_config_yaml(pattern, replacement) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nesta/commands.rb', line 32 def update_config_yaml(pattern, replacement) configured = false File.open(Nesta::Config.yaml_path, 'r+') do |file| output = '' file.each_line do |line| if configured output << line else output << line.sub(pattern, replacement) configured = true if line =~ pattern end end output << "#{replacement}\n" unless configured file.pos = 0 file.print(output) file.truncate(file.pos) end end |