Module: Nesta::Commands::Command

Included in:
Demo::Content, Edit, New, Theme::Create, Theme::Enable, Theme::Install
Defined in:
lib/nesta/commands.rb

Instance Method Summary collapse

Instance Method Details

#copy_template(src, dest) ⇒ Object



23
24
25
26
27
# File 'lib/nesta/commands.rb', line 23

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



29
30
31
# File 'lib/nesta/commands.rb', line 29

def copy_templates(templates)
  templates.each { |src, dest| copy_template(src, dest) }
end

#fail(message) ⇒ Object



14
15
16
17
# File 'lib/nesta/commands.rb', line 14

def fail(message)
  $stderr.puts "Error: #{message}"
  exit 1
end

#template_rootObject



19
20
21
# File 'lib/nesta/commands.rb', line 19

def template_root
  File.expand_path('../../templates', File.dirname(__FILE__))
end

#update_config_yaml(pattern, replacement) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nesta/commands.rb', line 33

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