Class: Khaleesi::CLI::CreatePost
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
class_from_arg, #create_file_p, normalize_syntax
Constructor Details
#initialize(opts = {}) ⇒ CreatePost
Returns a new instance of CreatePost.
156
157
158
|
# File 'lib/khaleesi/cli.rb', line 156
def initialize(opts={})
@page_name = opts[:page_name]
end
|
Instance Attribute Details
#page_name ⇒ Object
Returns the value of attribute page_name.
154
155
156
|
# File 'lib/khaleesi/cli.rb', line 154
def page_name
@page_name
end
|
Class Method Details
.desc ⇒ Object
130
131
132
|
# 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>'| ... } ⇒ Object
134
135
136
137
138
139
140
|
# 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
|
.parse(argv) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
|
# 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
|
Instance Method Details
#run ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# 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
|