lib/mkmatter/cli/subs/new.rb in mkmatter-3.0.43 vs lib/mkmatter/cli/subs/new.rb in mkmatter-3.0.44

- old
+ new

@@ -1,6 +1,7 @@ require 'highline' +require 'thor' require 'mkmatter/cli/descriptions' require 'mkmatter/cli/methods' require 'mkmatter/questions' require 'mkmatter/answers' @@ -8,21 +9,20 @@ module App module Classes # Generate 'New' Content class NewContent < Thor include Thor::Actions - HILINE = HighLine.new($stdin, $stderr, 80) + HILINE = HighLine.new($stdin, $stderr, 40) option :publish, :type => :boolean option :file, :type => :boolean desc 'page [options]', 'make front matter (and possibly content) for a jekyll page' long_desc Mkmatter::App::Descriptions::New::PAGE def page if options[:file] - if Mkmatter::Methods.check_if_jekyll - @questions = Mkmatter::Questions::Page.new(HighLine.new($stdin, $stderr, 80)).ask + @questions = Mkmatter::Questions::Page.new(HILINE).ask answers = Mkmatter::Answers.new(@questions, options.fetch(:publish, nil)) filename = answers.title.to_slug + '.' + answers.file_format.downcase path = Pathname("./#{filename}").realdirpath if HILINE.agree('Would you like to put this page into a subdirectory?', true) HILINE.say("What path? (directories will be created if they don't exist) ") @@ -44,11 +44,11 @@ end File.open(path.to_path, 'a') do |fd| fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2) fd.puts '---' end - Mkmatter::Methods.launch_editor(path) + Mkmatter::Methods.launch_editor(options[:editor], path) else puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)" exit 1 end else @@ -69,11 +69,11 @@ def post if options[:draft] and options[:file] if Mkmatter::Methods.check_if_jekyll - @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask + @questions = Mkmatter::Questions::Post.new(HILINE).ask answers = Mkmatter::Answers.new(@questions, options[:publish]) file_folder = '_drafts' filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join path = Pathname("./#{file_folder}/#{filename}").realdirpath @@ -97,19 +97,19 @@ end File.open(path.to_path, 'a') do |fd| fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2) fd.puts '---' end - Mkmatter::Methods.launch_editor(path) + Mkmatter::Methods.launch_editor(options[:editor], path) else puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)" exit 1 end elsif options[:file] and options[:draft].nil? or options[:draft] == false if Mkmatter::Methods.check_if_jekyll - @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask + @questions = Mkmatter::Questions::Post.new(HILINE).ask answers = Mkmatter::Answers.new(@questions, options[:publish]) file_folder = '_posts' filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join('') path = Pathname("./#{file_folder}/#{filename}").realdirpath if HILINE.agree('Would you like to put this post into a subdirectory?', true) @@ -135,24 +135,22 @@ File.open(path.to_path, 'a') do |fd| fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2) fd.puts '---' end - Mkmatter::Methods.launch_editor(path) + Mkmatter::Methods.launch_editor(options[:editor], path) else puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)" exit 1 end - elsif options[:draft].nil? and options[:file].nil? - @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask + @questions = Mkmatter::Questions::Post.new(HILINE).ask answers = Mkmatter::Answers.new(@questions, options[:publish]) puts '' puts answers.to_h.stringify_keys.to_yaml(indentation: 2) puts '---' end - end end end end end \ No newline at end of file