Class: Jekyll::Commands::Post

Inherits:
Command
  • Object
show all
Defined in:
lib/jekyll/commands/post.rb

Defined Under Namespace

Classes: PostArgParser, PostFileInfo

Class Method Summary collapse

Class Method Details

.init_with_program(prog) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/jekyll/commands/post.rb', line 4

def self.init_with_program(prog)
  prog.command(:post) do |c|
    c.syntax "post NAME"
    c.description "Creates a new post with the given NAME"

    options.each { |opt| c.option *opt }

    c.action { |args, options| process args, options }
  end
end

.optionsObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/jekyll/commands/post.rb', line 15

def self.options
  [
    ["extension", "-x EXTENSION", "--extension EXTENSION", "Specify the file extension"],
    ["layout", "-l LAYOUT", "--layout LAYOUT", "Specify the post layout"],
    ["force", "-f", "--force", "Overwrite a post if it already exists"],
    ["date", "-d DATE", "--date DATE", "Specify the post date"],
    ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
    ["source", "-s", "--source SOURCE", "Custom source directory"],
  ]
end

.process(args = [], options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/jekyll/commands/post.rb', line 26

def self.process(args = [], options = {})
  params = PostArgParser.new args, options
  params.validate!

  post = PostFileInfo.new params

  Compose::FileCreator.new(post, params.force?, params.source).create!
end