class MrPoole::CLI
Public Class Methods
new(args)
click to toggle source
# File lib/mr_poole/cli.rb, line 7 def initialize(args) @helper = Helper.new @src_dir = @helper.ensure_jekyll_dir @params = args @config = @helper.config ext = @config.default_extension || 'md' @commands = Commands.new(ext) end
Public Instance Methods
execute(action)
click to toggle source
# File lib/mr_poole/cli.rb, line 18 def execute(action) case action when 'post' then handle_post when 'draft' then handle_draft when 'publish' then handle_publish when 'unpublish' then handle_unpublish when '--version' then @helper.version_statement when '-v' then @helper.version_statement else @helper.gen_usage end @helper.restore_orig_directory end
handle_draft()
click to toggle source
# File lib/mr_poole/cli.rb, line 36 def handle_draft do_create('draft') end
handle_post()
click to toggle source
# File lib/mr_poole/cli.rb, line 32 def handle_post do_create('post') end
handle_publish()
click to toggle source
# File lib/mr_poole/cli.rb, line 40 def handle_publish do_move('publish') end
handle_unpublish()
click to toggle source
# File lib/mr_poole/cli.rb, line 44 def handle_unpublish do_move('unpublish') end
Private Instance Methods
do_create(action)
click to toggle source
action is a string, either ‘post’ or ‘draft’
# File lib/mr_poole/cli.rb, line 51 def do_create(action) options = do_creation_options options.title ||= @params.first @helper.send("#{action}_usage") unless options.title fn = @commands.send(action, options) puts "#{@src_dir}/#{fn}" end
do_creation_options()
click to toggle source
# File lib/mr_poole/cli.rb, line 70 def do_creation_options options = OpenStruct.new options.slug = nil options.title = nil options.layout = nil opt_parser = OptionParser.new do |opts| opts.on('-s', '--slug SLUG', "Use custom slug") do |s| options.slug = s end opts.on('-t', '--title TITLE', "Specifiy title") do |t| options.title = t end opts.on('-l', '--layout PATH', "Specify a custom layout file") do |l| options.layout = l end end options.layout ||= @config.default_layout opt_parser.parse! @params options end
do_move(action)
click to toggle source
action is a string, either ‘publish’ or ‘unpublish’
# File lib/mr_poole/cli.rb, line 61 def do_move(action) options = do_move_options(action) path = @params.first @helper.send("#{action}_usage") unless path fn = @commands.send(action, path, options) puts "#{@src_dir}/#{fn}" end
do_move_options(type)
click to toggle source
pass a string, either publish or unpublish
# File lib/mr_poole/cli.rb, line 97 def do_move_options(type) options = OpenStruct.new opt_parser = OptionParser.new do |opts| if type == 'publish' opts.on('-d', '--keep-draft', "Keep draft post") do |d| options.keep_draft = d end else opts.on('-p', '--keep-post', "Do not delete post") do |p| options.keep_post = p end end opts.on('-t', '--keep-timestamp', "Keep existing timestamp") do |t| options.keep_timestamp = t end end opt_parser.parse! @params options end