Class: Nanoc2::CLI::CreatePageCommand
- Inherits:
-
Cri::Command
- Object
- Cri::Command
- Nanoc2::CLI::CreatePageCommand
- Defined in:
- lib/nanoc2/cli/commands/create_page.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_page.rb', line 9 def aliases [ 'cp' ] end |
#long_desc ⇒ Object
17 18 19 20 21 |
# File 'lib/nanoc2/cli/commands/create_page.rb', line 17 def long_desc 'Create a new page in the current site. The template that will be ' + 'used for generating the page will be \'default\', unless otherwise ' + 'specified.' end |
#name ⇒ Object
5 6 7 |
# File 'lib/nanoc2/cli/commands/create_page.rb', line 5 def name 'create_page' end |
#option_definitions ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nanoc2/cli/commands/create_page.rb', line 27 def option_definitions [ # --vcs { :long => 'vcs', :short => 'c', :argument => :required, :desc => 'select the VCS to use' }, # --template { :long => 'template', :short => 't', :argument => :required, :desc => 'specify the template for the new page' } ] end |
#run(options, arguments) ⇒ Object
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 73 74 75 76 77 78 79 80 81 |
# File 'lib/nanoc2/cli/commands/create_page.rb', line 42 def run(, arguments) # Check arguments if arguments.length != 1 $stderr.puts "usage: #{usage}" exit 1 end # Extract arguments and options path = arguments[0].cleaned_path template_name = [:template] || 'default' # Make sure we are in a nanoc site directory @base.require_site # Set VCS if possible @base.set_vcs([:vcs]) # Find template template = @base.site.templates.find { |t| t.name == template_name } if template.nil? $stderr.puts "A template named '#{template_name}' was not found; aborting." exit 1 end # Setup notifications Nanoc2::NotificationCenter.on(:file_created) do |file_path| Nanoc2::CLI::Logger.instance.file(:high, :create, file_path) end # Create page page = Nanoc2::Page.new( template.page_content, template.page_attributes, path ) page.site = @base.site page.save puts "A page has been created at #{path}." end |
#short_desc ⇒ Object
13 14 15 |
# File 'lib/nanoc2/cli/commands/create_page.rb', line 13 def short_desc 'create a page' end |
#usage ⇒ Object
23 24 25 |
# File 'lib/nanoc2/cli/commands/create_page.rb', line 23 def usage "nanoc2 create_page [options] [path]" end |