class Khaleesi::CLI::CreatePost

Attributes

page_name[R]

Public Class Methods

desc() click to toggle source
# File lib/khaleesi/cli.rb, line 130
def self.desc
  'create a new page in pwd with an unique identifier which composed by 20 characters like "b36446316f29e2b97a7d"'
end
doc() { |'usage: khaleesi createpost <filename>'| ... } click to toggle source
# File lib/khaleesi/cli.rb, line 134
def self.doc
  return enum_for(:doc) unless block_given?

  yield 'usage: khaleesi createpost <filename>'
  yield ''
  yield '<filename>  specify a page file name (exclude extension)'
end
new(opts={}) click to toggle source
# File lib/khaleesi/cli.rb, line 156
def initialize(opts={})
  @page_name = opts[:page_name]
end
parse(argv) click to toggle source
# File lib/khaleesi/cli.rb, line 142
def self.parse(argv)
  opts = {:page_name => nil}

  until argv.empty?
    opts[:page_name] = argv.shift
  end

  puts 'unspecific page name' unless opts[:page_name]

  new(opts)
end

Public Instance Methods

run() click to toggle source
# File lib/khaleesi/cli.rb, line 160
def run
  return unless @page_name

  page_path = "#{Dir.pwd}/#{@page_name}.md"
  open(page_path, 'w') do |f|
    f.puts 'title: <input page title>'
    f.puts 'decorator: <input page decorator>'
    f.puts "identifier: #{SecureRandom.hex(10)}"
    f.puts '‡‡‡‡‡‡‡‡‡‡‡‡‡‡'
    f.puts 'here is page content.'
  end

  puts "A post page was created : #{page_path}."
end