Class: Nanoc2::CLI::CreateLayoutCommand
- Inherits:
-
Cri::Command
- Object
- Cri::Command
- Nanoc2::CLI::CreateLayoutCommand
- Defined in:
- lib/nanoc2/cli/commands/create_layout.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_layout.rb', line 9 def aliases [ 'cl' ] end |
#long_desc ⇒ Object
17 18 19 |
# File 'lib/nanoc2/cli/commands/create_layout.rb', line 17 def long_desc 'Create a new layout in the current site.' end |
#name ⇒ Object
5 6 7 |
# File 'lib/nanoc2/cli/commands/create_layout.rb', line 5 def name 'create_layout' end |
#option_definitions ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/nanoc2/cli/commands/create_layout.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 73 74 75 76 77 78 79 80 81 |
# File 'lib/nanoc2/cli/commands/create_layout.rb', line 35 def run(, arguments) # Check arguments if arguments.length != 1 $stderr.puts "usage: #{usage}" exit 1 end # Extract arguments path = arguments[0].cleaned_path # Make sure we are in a nanoc site directory @base.require_site # Set VCS if possible @base.set_vcs([:vcs]) # Check whether layout is unique if !@base.site.layouts.find { |l| l.path == path }.nil? $stderr.puts "A layout already exists at #{path}. Please pick a unique name " + "for the layout you are creating." exit 1 end # Setup notifications Nanoc2::NotificationCenter.on(:file_created) do |file_path| Nanoc2::CLI::Logger.instance.file(:high, :create, file_path) end # Create layout layout = Nanoc2::Layout.new( "<html>\n" + " <head>\n" + " <title><%= @page.title %></title>\n" + " </head>\n" + " <body>\n" + " <p>Hi, I'm a new layout. Please customize me!</p>\n" + "<%= @page.content %>\n" + " </body>\n" + "</html>\n", { :filter => 'erb' }, path ) layout.site = @base.site layout.save puts "A layout has been created at #{path}." end |
#short_desc ⇒ Object
13 14 15 |
# File 'lib/nanoc2/cli/commands/create_layout.rb', line 13 def short_desc 'create a layout' end |
#usage ⇒ Object
21 22 23 |
# File 'lib/nanoc2/cli/commands/create_layout.rb', line 21 def usage "nanoc2 create_layout [path]" end |