Class: Nanoc3::CLI::Commands::CreateItem

  • Cri::Command
    • Nanoc3::CLI::Commands::CreateItem

Public Visibility

Public Instance Method Summary

#aliases
#long_desc
#name
#option_definitions
#run(options, arguments)
#short_desc
#usage

Public Instance Method Details

aliases

public aliases
[View source]


11
12
13
# File 'lib/nanoc3/cli/commands/create_item.rb', line 11

def aliases
  [ 'ci' ]
end

long_desc

public long_desc
[View source]


19
20
21
# File 'lib/nanoc3/cli/commands/create_item.rb', line 19

def long_desc
  'Create a new item in the current site. The first data source in the site configuration will be used.'
end

name

public name
[View source]


7
8
9
# File 'lib/nanoc3/cli/commands/create_item.rb', line 7

def name
  'create_item'
end

option_definitions

public option_definitions
[View source]


27
28
29
30
31
32
33
34
35
# File 'lib/nanoc3/cli/commands/create_item.rb', line 27

def option_definitions
  [
    # --vcs
    {
      :long => 'vcs', :short => 'c', :argument => :required,
      :desc => 'select the VCS to use'
    }
  ]
end

run

public run(options, arguments)
[View source]


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
# File 'lib/nanoc3/cli/commands/create_item.rb', line 37

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

public short_desc
[View source]


15
16
17
# File 'lib/nanoc3/cli/commands/create_item.rb', line 15

def short_desc
  'create a item'
end

usage

public usage
[View source]


23
24
25
# File 'lib/nanoc3/cli/commands/create_item.rb', line 23

def usage
  "nanoc3 create_item [options] [identifier]"
end
Generated on Sunday, August 09 2009 at 01:43:08 PM by YARD 0.2.3.2 (ruby-1.8.7).