Class: Miso::Commands::New
- Inherits:
-
Object
- Object
- Miso::Commands::New
- Defined in:
- lib/miso/commands.rb
Instance Method Summary collapse
- #copy_template(src, dest) ⇒ Object
- #copy_templates(templates) ⇒ Object
- #execute ⇒ Object
-
#initialize(path, options = {}) ⇒ New
constructor
A new instance of New.
- #make_directories ⇒ Object
- #template_root ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ New
Returns a new instance of New.
8 9 10 11 12 13 |
# File 'lib/miso/commands.rb', line 8 def initialize(path, = {}) path.nil? && (raise UsageError.new('path not specified')) fail("#{path} already exists") if File.exist?(path) @path = path @options = end |
Instance Method Details
#copy_template(src, dest) ⇒ Object
19 20 21 |
# File 'lib/miso/commands.rb', line 19 def copy_template(src, dest) FileUtils.cp(File.join(template_root, src), dest) end |
#copy_templates(templates) ⇒ Object
23 24 25 |
# File 'lib/miso/commands.rb', line 23 def copy_templates(templates) templates.each { |src, dest| copy_template(src, dest) } end |
#execute ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/miso/commands.rb', line 33 def execute make_directories templates = { 'config.ru' => "#{@path}/config.ru", 'Gemfile' => "#{@path}/Gemfile", '_app/miso/config.ru' => "#{@path}/_app/miso/config.ru", '_app/miso/miso.erb' => "#{@path}/_app/miso/miso.erb", '_site/index.html' => "#{@path}/_site/index.html" } copy_templates(templates) end |
#make_directories ⇒ Object
27 28 29 30 31 |
# File 'lib/miso/commands.rb', line 27 def make_directories %w[_app/miso _site].each do |dir| FileUtils.mkdir_p(File.join(@path, dir)) end end |
#template_root ⇒ Object
15 16 17 |
# File 'lib/miso/commands.rb', line 15 def template_root File.('../../template', File.dirname(__FILE__)) end |