Class: Mkmatter::App::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/mkmatter/cli/app.rb

Constant Summary collapse

HILINE =

(see HighLine#new)

HighLine.new($stdin, $stderr, 80)

Instance Method Summary collapse

Instance Method Details

#__debugNilClass

Prints debug info

Returns:

  • (NilClass)

    returns nil



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_infoNilClass

Returns Prints Gem info.

Returns:

  • (NilClass)

    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 = options[:'info-format']
  rows = {
    'author(s)': Mkmatter::GemInfo.authors.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_versionNilClass

Prints version string

Returns:

  • (NilClass)

    nil



24
25
26
# File 'lib/mkmatter/cli/app.rb', line 24

def __print_version
  puts Mkmatter::VERSION
end

#newObject



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
146
# File 'lib/mkmatter/cli/app.rb', line 96

def new
  # @questions = Mkmatter::Questions::Post.new(HILINE).ask
  @questions = Mkmatter::Questions.new.ask(options[:type], options[:include_post_qs])
  answers = Mkmatter::Answers.new(@questions, options[:publish], options[:include_post_qs])
  draft_folder = "_drafts"
  filename = [].concat([answers.slug_date, "-", answers.title.to_slug, ".", answers.file_format.downcase]).join

  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, relative to Jekyll root)\n      \n    FOLDERDOC\n    folder = HILINE.ask(\"? \") do |q|\n      q.confirm = true\n      q.default = \".\"\n      q.validate = /^[^\\/].*$/\n      q.responses[:not_valid] = \"Please enter a valid path, a relative path from the Jekyll root.\"\n      q.responses[:ask_on_error] = :question\n    end\n    folder = Pathname(folder)\n    if options[:'dry-run']\n      HILINE.say(\"Would create \#{File.join(Pathname(\".\"), folder)}\")\n    else\n      begin\n        FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))\n      rescue Errno::EEXIST\n        HILINE.say(\"<%= color('Error', :red, :bold) %>:Insufficient Permissions\")\n        exit 1\n      end\n    end\n    if options[:'dry-run']\n      # If dry-run, don't check for the folder\n      # and just use the folder as is.\n      path = Pathname(folder).join(filename)\n    else\n      # Otherwise, check for the folder\n      path = Pathname(folder).realdirpath.join(filename)\n    end\n  end\n  if options[:'dry-run']\n    HILINE.say(\"Would create '\#{path}'\")\n    HILINE.say(\"Would output \\n\#{answers.to_yaml(indentation: 2)}\\n---\\n\\n\")\n  else\n    File.open(path.to_path, \"a\") do |fd|\n      fd.puts answers.to_yaml(indentation: 2)\n      fd.puts \"---\"\n    end\n    Mkmatter::Methods.launch_editor(options[:editor], path)\n  end\nend\n")