Class: Nanoc3::CLI::Commands::CreateLayout
- Inherits:
-
Nanoc3::CLI::Command
- Object
- Nanoc3::CLI::Command
- Nanoc3::CLI::Commands::CreateLayout
- Defined in:
- lib/nanoc3/cli/commands/create_layout.rb
Instance Attribute Summary
Attributes inherited from Nanoc3::CLI::Command
#arguments, #command, #options
Instance Method Summary collapse
Methods inherited from Nanoc3::CLI::Command
#call, call, #initialize, #site
Constructor Details
This class inherits a constructor from Nanoc3::CLI::Command
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 |
# File 'lib/nanoc3/cli/commands/create_layout.rb', line 19 def run # Check arguments if arguments.length != 1 $stderr.puts "usage: #{usage}" exit 1 end # Extract arguments identifier = arguments[0].cleaned_identifier # Make sure we are in a nanoc site directory self.require_site # Set VCS if possible self.set_vcs([:vcs]) # Check whether layout is unique if !self.site.layouts.find { |l| l.identifier == identifier }.nil? $stderr.puts "A layout already exists at #{identifier}. Please " + "pick a unique name for the layout you are creating." exit 1 end # Check whether layout is not at / if identifier == '/' $stderr.puts "There cannot be a layout with the identifier '/'; " + "please pick a different identifier for this layout." exit 1 end # Setup notifications Nanoc3::NotificationCenter.on(:file_created) do |file_path| Nanoc3::CLI::Logger.instance.file(:high, :create, file_path) end # Create layout data_source = self.site.data_sources[0] data_source.create_layout( "<html>\n" + " <head>\n" + " <title><%= @item[:title] %></title>\n" + " </head>\n" + " <body>\n" + " <p>Hi, I'm a new layout. Please customize me!</p>\n" + "<%= yield %>\n" + " </body>\n" + "</html>\n", {}, identifier ) puts "A layout has been created at #{identifier}." end |