Class: Mkmatter::App::CLI
Instance Method Summary collapse
-
#__debug ⇒ NilClass
Prints debug info.
-
#__print_info ⇒ NilClass
Prints Gem info.
-
#__print_version ⇒ NilClass
Prints version string.
- #new ⇒ Object
Instance Method Details
#__debug ⇒ NilClass
Prints debug info
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mkmatter/cli/app.rb', line 32 def __debug report = YAML.safe_load(OS.report) rows = { :mkmatter_version => Mkmatter::VERSION, :ruby_version => RbConfig::CONFIG["RUBY_PROGRAM_VERSION"], } rows.merge! report rows.merge!({ "ruby bin" => OS.ruby_bin, :windows => OS.windows?, :posix => OS.posix?, :mac => OS.mac?, "under windows" => OS::Underlying.windows?, "under bsd" => OS::Underlying.bsd?, }) table = ::Terminal::Table.new table.title = "mkmatter Debug Info" table.rows = rows.to_a table.align_column(0, :left) puts table end |
#__print_info ⇒ NilClass
Returns Prints Gem info.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/mkmatter/cli/app.rb', line 59 def __print_info format = [:'info-format'] rows = { 'author(s)': Mkmatter::GemInfo..join(", "), 'e-mail': Mkmatter::GemInfo.email.join(", "), 'mkmatter version': Mkmatter::VERSION, 'Ruby version': RbConfig::CONFIG["RUBY_PROGRAM_VERSION"], 'Platform': RbConfig::CONFIG["build_os"], } case format when "table" table = ::Terminal::Table.new table.style.alignment = :center table.title = "mkmatter Info" table.rows = rows.to_a table.align_column(0, :left) puts table when "yaml" puts rows.stringify_keys.to_yaml else # noop # this doesn't get run because of # the logic of options and their # enum parameter. end end |
#__print_version ⇒ NilClass
Prints version string
24 25 26 |
# File 'lib/mkmatter/cli/app.rb', line 24 def __print_version puts Mkmatter::VERSION end |
#new ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/mkmatter/cli/app.rb', line 94 def new # @questions = Mkmatter::Questions::Post.new(HILINE).ask @questions = Mkmatter::Questions.new.ask([:type], [:include_post_qs]) answers = Mkmatter::Answers.new(@questions, [:publish], [:include_post_qs]) draft_folder = "_drafts" filename = [].concat([answers['slug_date'], '-', Slugity::Convert.slug(answers['title']), '.', answers['file_format'].downcase]).join path = Pathname("./#{filename}").realdirpath hl = HighLine.new if hl.agree("Would you like to put this page into a subdirectory? ", true) hl.say(<<~FOLDERDOC) What path? (directories will be created if they don't exist, relative to Jekyll root) FOLDERDOC folder = hl.ask("? ") do |q| q.confirm = true q.default = "." q.validate = /^[^\/].*$/ q.responses[:not_valid] = "Please enter a valid path, a relative path from the Jekyll root." q.responses[:ask_on_error] = :question end folder = Pathname(folder) if [:'dry-run'] hl.say("Would create #{File.join(Pathname("."), folder)}") else begin FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder)) rescue Errno::EEXIST hl.say("<%= color('Error', :red, :bold) %>:Insufficient Permissions") exit 1 end end if [:'dry-run'] # If dry-run, don't check for the folder # and just use the folder as is. path = Pathname(folder).join(filename) else # Otherwise, check for the folder path = Pathname(folder).realdirpath.join(filename) end end if [:'dry-run'] hl.say("Would create '#{path}'") hl.say("Would output \n#{answers.to_yaml(indentation: 2)}\n---\n\n") else File.open(path.to_path, "a") do |fd| fd.puts answers.to_yaml(indentation: 2) fd.puts "---" end Mkmatter::Methods.launch_editor([:editor], path) end end |