Parent

Class/Module Index [+]

Quicksearch

Nanoc3::CLI::Commands::CreateItem

Public Instance Methods

aliases() click to toggle source
# File lib/nanoc3/cli/commands/create_item.rb, line 10
def aliases
  [ 'ci' ]
end
long_desc() click to toggle source
# File lib/nanoc3/cli/commands/create_item.rb, line 18
def long_desc
  'Create a new item in the current site. The first data source in the site configuration will be used.'
end
name() click to toggle source
# File lib/nanoc3/cli/commands/create_item.rb, line 6
def name
  'create_item'
end
option_definitions() click to toggle source
# File lib/nanoc3/cli/commands/create_item.rb, line 26
def option_definitions
  [
    # --vcs
    {
      :long => 'vcs', :short => 'c', :argument => :required,
      :desc => 'select the VCS to use'
    }
  ]
end
run(options, arguments) click to toggle source
# File lib/nanoc3/cli/commands/create_item.rb, line 36
def run(options, arguments)
  # Check arguments
  if arguments.length != 1
    $stderr.puts "usage: #{usage}"
    exit 1
  end

  # Extract arguments and options
  identifier = arguments[0].cleaned_identifier

  # Make sure we are in a nanoc site directory
  @base.require_site
  @base.site.load_data

  # Set VCS if possible
  @base.set_vcs(options[:vcs])

  # Check whether item is unique
  if !@base.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 = @base.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
short_desc() click to toggle source
# File lib/nanoc3/cli/commands/create_item.rb, line 14
def short_desc
  'create a item'
end
usage() click to toggle source
# File lib/nanoc3/cli/commands/create_item.rb, line 22
def usage
  "nanoc3 create_item [options] identifier"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.