Class: Nanoc2::CLI::CreateTemplateCommand
- Inherits:
-
Cri::Command
- Object
- Cri::Command
- Nanoc2::CLI::CreateTemplateCommand
- Defined in:
- lib/nanoc2/cli/commands/create_template.rb
Overview
:nodoc:
Instance Method Summary collapse
- #aliases ⇒ Object
- #long_desc ⇒ Object
- #name ⇒ Object
- #option_definitions ⇒ Object
- #run(options, arguments) ⇒ Object
- #short_desc ⇒ Object
- #usage ⇒ Object
Instance Method Details
#aliases ⇒ Object
9 10 11 |
# File 'lib/nanoc2/cli/commands/create_template.rb', line 9 def aliases [ 'ct' ] end |
#long_desc ⇒ Object
17 18 19 |
# File 'lib/nanoc2/cli/commands/create_template.rb', line 17 def long_desc 'Create a new template in the current site.' end |
#name ⇒ Object
5 6 7 |
# File 'lib/nanoc2/cli/commands/create_template.rb', line 5 def name 'create_template' end |
#option_definitions ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/nanoc2/cli/commands/create_template.rb', line 25 def option_definitions [ # --vcs { :long => 'vcs', :short => 'c', :argument => :required, :desc => 'select the VCS to use' } ] end |
#run(options, arguments) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/nanoc2/cli/commands/create_template.rb', line 35 def run(, arguments) # Check arguments if arguments.length != 1 $stderr.puts "usage: #{usage}" exit 1 end # Extract arguments name = arguments[0] # Check template name if name.include?('/') $stderr.puts 'Template names cannot contain slashes; aborting.' exit 1 end # Make sure we are in a nanoc site directory @base.require_site # Set VCS if possible @base.set_vcs([:vcs]) # Setup notifications Nanoc2::NotificationCenter.on(:file_created) do |file_path| Nanoc2::CLI::Logger.instance.file(:high, :create, file_path) end # Create template template = Nanoc2::Template.new( "Hi, I'm a new template. Please edit me!", { :title => "A Title" }, name ) template.site = @base.site template.save puts "A template named '#{name}' has been created." end |
#short_desc ⇒ Object
13 14 15 |
# File 'lib/nanoc2/cli/commands/create_template.rb', line 13 def short_desc 'create a template' end |
#usage ⇒ Object
21 22 23 |
# File 'lib/nanoc2/cli/commands/create_template.rb', line 21 def usage "nanoc2 create_template [name]" end |