Class: Nanoc3::CLI::Commands::CreateItem
- Inherits:
-
Nanoc3::CLI::Command
- Object
- Nanoc3::CLI::Command
- Nanoc3::CLI::Commands::CreateItem
- Defined in:
- lib/nanoc3/cli/commands/create_item.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
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 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 21 def run # Check arguments if arguments.length != 1 $stderr.puts "usage: #{command.usage}" exit 1 end # Extract arguments and options 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 item is unique if !self.site.items.find { |i| i.identifier == identifier }.nil? $stderr.puts "An item already exists at #{identifier}. Please " + "pick a unique name for the item you are creating." exit 1 end # Setup notifications Nanoc3::NotificationCenter.on(:file_created) do |file_path| Nanoc3::CLI::Logger.instance.file(:high, :create, file_path) end # Create item data_source = self.site.data_sources[0] data_source.create_item( "Hi, I'm a new item!\n", { :title => "A New Item" }, identifier ) puts "An item has been created at #{identifier}." end |