mkmatter 3.1.15 → 3.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05a4a05afeef47d494bfec52fbdec68affd6547210f3431d8c5186eaab7edb9c
4
- data.tar.gz: 8fb4ffa355cadc7fab89a0108938e715341c9545d8d19380771e0e5f883177ad
3
+ metadata.gz: 47fee00496b10e79638131fcd6057d8081317402bdc0fa5d397e9cadd32b2300
4
+ data.tar.gz: 0b3f1765bb4e51ec71cad1a0652def7f6c417374ad6e1f7b37ffa7b4ac52d65e
5
5
  SHA512:
6
- metadata.gz: e2d41b3e387681029538ccb00db1bd84a647e82f3466245fcd66d56f50f4f1f098b7c21ab07b1ac3af8d10763dc7dd3ea78df5e835b90f588b3eb89c9563dc79
7
- data.tar.gz: e5e12b8928600ad86c2bd8e9957e397241e181f50634d2ff0758613f6f2e4d27ff1be5a45954b9b6ff517bf763b1b6ea81521bd712c480949dcdd111852d31d6
6
+ metadata.gz: cf35d19b5d39860f65a83604429269d0c369703893a3da1f3ba2b229c822eebe08fb4929224b3216d35f4fc95c8f7613f0f77ea47957317d74da0c8263fe81e3
7
+ data.tar.gz: 5f3e8c56988553660144aa9bd91209c63d9645169c4ba6da73e444e635a5c5a596989c2618e9acf224b29e90d16527d8d287c9e9030ed13bc4975b165fbbfa03
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.7
1
+ 3.4.1
data/README.md CHANGED
@@ -1,10 +1,7 @@
1
1
  # mkmatter
2
2
 
3
- [![Travis branch](https://img.shields.io/travis/IotaSpencer/mkmatter/dev.svg?style=for-the-badge)](https://travis-ci.org/IotaSpencer/mkmatter)
4
- [![Travis branch](https://img.shields.io/travis/IotaSpencer/mkmatter/master.svg?style=for-the-badge)](https://travis-ci.org/IotaSpencer/mkmatter)
5
-
6
3
  [![Gem](https://img.shields.io/gem/v/mkmatter.svg?style=for-the-badge)](https://rubygems.org/gems/mkmatter)
7
- [![GitHub tag](https://img.shields.io/github/tag/IotaSpencer/mkmatter.svg?style=for-the-badge)](https://github.com/IotaSpencer/mkmatter/tree/v3.0.27)
4
+ [![GitHub tag](https://img.shields.io/github/tag/IotaSpencer/mkmatter.svg?style=for-the-badge)](https://github.com/IotaSpencer/mkmatter/tree/)
8
5
 
9
6
  [![Gem](https://img.shields.io/gem/dt/mkmatter.svg?style=for-the-badge)](https://rubygems.org/gems/mkmatter)
10
7
  [![Gem](https://img.shields.io/gem/dtv/mkmatter.svg?style=for-the-badge)](https://rubygems.org/gems/mkmatter)
@@ -16,11 +13,11 @@
16
13
 
17
14
  ## Contact
18
15
 
19
- [![E-mail](https://img.shields.io/badge/Email-Me-green.svg?style=for-the-badge)](mailto:me@iotaspencer.me)
20
- [![Twitter Follow](https://img.shields.io/twitter/follow/IotaEcode.svg?label=Follow%20Me%20on%20Twitter&style=for-the-badge)](https://twitter.com/iotaspencer)
16
+ If you install `mkmatter` Please let me know, I'd love to know the people using this!
21
17
 
18
+ [![E-mail](https://img.shields.io/badge/Email-Me-green.svg?style=for-the-badge)](mailto:me@iotaspencer.me)
19
+ [![Twitter Follow](https://img.shields.io/twitter/follow/KenISpencer.svg?label=Follow%20Me%20on%20Twitter&style=for-the-badge)](https://twitter.com/KenISpencer)
22
20
  [![Website](https://img.shields.io/website-up-down-green-red/https/iotaspencer.me.svg?label=My%20Site%20-%20IotaSpencer%2Eme&style=for-the-badge)](https://iotaspencer.me)
23
-
24
21
  [![E-mail](https://img.shields.io/badge/mkmatter%20on%20IotaSpencer%2eme-Project-green.svg?style=for-the-badge)](https://iotaspencer.me/projects/mkmatter)
25
22
 
26
23
  ## About mkmatter
@@ -43,6 +40,11 @@ Add
43
40
  ```shell
44
41
  PATH="$HOME/bin:$HOME/.local/bin:$PATH"
45
42
  ```
43
+ then do
44
+
45
+ ```
46
+ bundle exec micro-install
47
+ ```
46
48
 
47
49
  If you do install micro, it will use micro by default unless you override it with `--editor=EDITOR`
48
50
 
@@ -85,20 +87,39 @@ $ sudo gem install mkmatter
85
87
  $ gem install --user-install mkmatter
86
88
  ```
87
89
 
90
+
88
91
  ## Usage
89
92
 
90
93
  **See [Wiki](https://github.com/IotaSpencer/mkmatter/wiki)**
91
94
 
95
+ **Tutorial**: [mkmatter Tutorial on IotaSpencer.me](https://iotaspencer.me/2025-XX-XX-mkmatter-tutorial)
96
+
92
97
  ## Contributing
93
98
 
94
- * I am open to the idea of adding more questions/modules if there are plugins that require more configuration in the front matter. Just let me know!
99
+ ### Notes
100
+
101
+ * I am open to the idea of adding more questions/modules if there are plugins that require more configuration in the front matter. Just let me know!
102
+ * Most layouts are accounted for via `--type=CUSTOM_TYPE` and then the application asking if there are custom fields you want to add `Mkmatter::Questions.006_get_custom_fields`
103
+
104
+ ### Ways to Contribute
95
105
 
96
106
  * [Bug Reports](https://github.com/IotaSpencer/mkmatter/issues)
97
107
  * [Pull Requests](https://github.com/IotaSpencer/mkmatter/pulls)
98
108
 
99
- <!--
100
- **Tutorial**: [mkmatter Tutorial on IotaSpencer.me](https://iotaspencer.me/2018-02-XX-mkmatter-tutorial)
101
- -->
109
+ ### Testing
110
+
111
+ * Due to the nature of how varied the input to the application can be, `mkmatter new --type=TYPE` is not tested in the traditional sense, and is only tested via using `--dry-run` in a non-ci environment, everything else is tested, or known to work via testing of libraries themselves.
112
+ * That is to say, if it asked its questions, and outputted the yaml via `--dry-run` it will more than likely create the directories/files if run without.
113
+ * Therefore; Bugs encountered during Highline prompting inside the `Mkmatter::Questions` class, (most likely `mkmatter new --type=TYPE`), must be reproducable before being looked into.
114
+ * Otherwise Please email [me](mailto:me@iotaspencer.me) if something goes wrong, or create an issue.
115
+
116
+ #### Cases
117
+ * If YAML errors out because you put a `:` in a keyname, that's on you.
118
+ * If creating a directory, creates an error, because of a syntax error, that's on you.
119
+ * Idiot proofing is not a case for tests. Don't be an idiot and create problems for yourself. Know the syntax you are using.
120
+
121
+ * If you know a way I can test some cases, then please contact me.
122
+
102
123
 
103
124
  ## License
104
125
 
data/bin/console CHANGED
@@ -1,16 +1,16 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mkmatter'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- #require 'irb'
14
- #IRB.start(__FILE__)
15
- require 'pry'
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mkmatter'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ #require 'irb'
14
+ #IRB.start(__FILE__)
15
+ require 'pry'
16
16
  Pry.start
data/bin/mkmatter CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/ruby
2
- require 'mkmatter'
3
- Signal.trap('INT') do
4
- $stderr.puts
5
- $stderr.puts 'Got INT.. Exiting'
6
- exit 0
7
- end
1
+ #!/usr/bin/env ruby
2
+ require 'mkmatter'
3
+ Signal.trap('INT') do
4
+ $stderr.puts
5
+ $stderr.puts 'Got INT.. Exiting'
6
+ exit 0
7
+ end
8
8
  Mkmatter::App::Runner.new(ARGV).execute!
data/bin/setup CHANGED
@@ -1,7 +1,7 @@
1
- #!/bin/sh
2
- #
3
-
4
- bundle install
5
- if [ $1 = "micro" ]; then
6
- bundle exec micro-install
1
+ #!/bin/sh
2
+ #
3
+
4
+ bundle install
5
+ if [ $1 = "micro" ]; then
6
+ bundle exec micro-install
7
7
  fi
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
- require 'active_support/all'
2
+ require 'time'
3
3
  require 'highline'
4
+ require 'mkmatter/helpers'
4
5
  module Mkmatter
5
6
  class Answers
6
7
  attr_accessor :title, :tags, :categories
@@ -9,31 +10,61 @@ module Mkmatter
9
10
  attr_accessor :published, :file_format
10
11
  attr_accessor :matter
11
12
  attr_accessor :extra_fields
13
+ attr_accessor :summary
12
14
 
13
- def initialize(question_hash, publish)
14
- @title = question_hash[:title]
15
- @tags = question_hash[:tags]
16
- @categories = question_hash[:categories]
17
- Time.zone = question_hash[:time_zone]
18
- now = Time.zone.now
19
- @date = now.to_s
20
- @slug_date = now.strftime('%Y-%m-%d')
21
- @published = publish
22
- @file_format = question_hash[:file_format]
15
+ def initialize(question_hash, publish, include_post_fields = true)
16
+ @title = question_hash[:title]
17
+ @layout = question_hash[:layout]
18
+ if @layout == 'post'
19
+ include_post_fields = true
20
+ end
21
+ @tags = question_hash[:tags] if question_hash[:tags].nil? == false
22
+ @categories = question_hash[:categories] if question_hash[:categories].nil? == false
23
+ Time.zone = get_time_zone_full(Time.now.getlocal) || 'Eastern Time (US & Canada)' if (include_post_fields == true || @layout == 'post')
24
+ # Time.zone = question_hash[:time_zone] || Time.now.zone
25
+ @now = Time.zone.now || Time.now.getlocal
26
+ @date = @now.to_s if include_post_fields == true
27
+ @slug_date = @now.strftime('%Y-%m-%d') if include_post_fields == true
28
+ @published = publish
29
+ @file_format = question_hash[:file_format]
23
30
  @extra_fields = question_hash[:extra_fields]
31
+ if question_hash[:summary]
32
+ @summary = question_hash[:summary] unless question_hash[:summary].empty?
33
+ end
24
34
 
25
35
  @matter = {
26
- layout: question_hash[:layout],
36
+ layout: @layout,
27
37
  title: @title,
28
- categories: @categories,
29
- tags: @tags,
30
- date: @date,
31
38
  }
39
+ if @layout == 'post' or include_post_fields
40
+ @matter[:tags] = @tags if @tags
41
+ @matter[:categories] = @categories if @categories
42
+ @matter[:summary] = @summary if @summary
43
+ @matter[:date] = @date
44
+
45
+ end
46
+ if @draft
47
+ @matter[:draft] = @draft
48
+ end
32
49
  if @extra_fields
33
50
  @matter.merge!(@extra_fields)
34
51
  end
35
52
  @matter[:published] = @published if publish
36
53
  end
37
54
 
55
+ # @return [Hash] returns attribute `.matter`
56
+ def to_h
57
+ @matter
58
+ end
59
+
60
+ # @param [Hash] hash other hash
61
+ # @return [nil] merges hash into attribute `.matter`
62
+ def to_h=(hash)
63
+ @matter.merge!(hash)
64
+ end
65
+ def to_yaml(*args, **kwargs)
66
+ @matter.stringify_keys.to_yaml(*args, **kwargs)
67
+ end
68
+
38
69
  end
39
70
  end
@@ -1,13 +1,14 @@
1
- require 'thor'
2
- require 'highline'
3
- require 'slugity/extend_string'
4
- require 'yaml'
5
- require 'active_support/all'
6
- require 'terminal-table'
7
- require 'os'
8
- require 'rbconfig'
9
- require 'mkmatter/version'
10
- require 'mkmatter/cli/subs'
1
+ require "thor"
2
+ require "highline"
3
+ require "slugity/extend_string"
4
+ require "yaml"
5
+ require "active_support/all"
6
+ require "terminal-table"
7
+ require "os"
8
+ require "rbconfig"
9
+ require "mkmatter/version"
10
+ require "mkmatter/cli/subs"
11
+ require 'mkmatter/cli/descriptions'
11
12
 
12
13
  module Mkmatter
13
14
  module App
@@ -15,7 +16,8 @@ module Mkmatter
15
16
  # \(see {http://www.rubydoc.info/gems/highline/HighLine#initialize-instance_method HighLine#new}\)
16
17
  HILINE = HighLine.new($stdin, $stderr, 80)
17
18
  map %w[--version -v] => :__print_version
18
- desc '--version, -v', 'Print the version'
19
+ desc "--version, -v", "Print the version"
20
+ package_name "mkmatter"
19
21
 
20
22
  # Prints version string
21
23
  # @return [NilClass] nil
@@ -24,76 +26,127 @@ module Mkmatter
24
26
  end
25
27
 
26
28
  map %w[--debug -d] => :__debug
27
- desc '--debug, -d', 'Prints debug info about the script/gem'
29
+ desc "--debug, -d", "Prints debug info about the script/gem"
28
30
  # Prints debug info
29
31
  # @return [NilClass] returns nil
30
32
  def __debug
31
33
  report = YAML.safe_load(OS.report)
32
- rows = {
33
- :mkmatter_version => Mkmatter::VERSION,
34
- :ruby_version => RbConfig::CONFIG['RUBY_PROGRAM_VERSION'],
34
+ rows = {
35
+ :mkmatter_version => Mkmatter::VERSION,
36
+ :ruby_version => RbConfig::CONFIG["RUBY_PROGRAM_VERSION"],
35
37
  }
36
38
  rows.merge! report
37
39
  rows.merge!({
38
- 'ruby bin' => OS.ruby_bin,
39
- :windows => OS.windows?,
40
- :posix => OS.posix?,
41
- :mac => OS.mac?,
42
- 'under windows' => OS::Underlying.windows?,
43
- 'under bsd' => OS::Underlying.bsd?,
40
+ "ruby bin" => OS.ruby_bin,
41
+ :windows => OS.windows?,
42
+ :posix => OS.posix?,
43
+ :mac => OS.mac?,
44
+ "under windows" => OS::Underlying.windows?,
45
+ "under bsd" => OS::Underlying.bsd?,
44
46
  })
45
- table = ::Terminal::Table.new
46
- table.title = 'mkmatter Debug Info'
47
- table.rows = rows.to_a
47
+ table = ::Terminal::Table.new
48
+ table.title = "mkmatter Debug Info"
49
+ table.rows = rows.to_a
48
50
  table.align_column(0, :left)
49
51
 
50
52
  puts table
51
53
  end
52
54
 
53
55
  map %w[--info -i] => :__print_info
54
- desc '--info, -i', 'Print script/gem info'
55
- method_option :'info-format', :type => :string, desc: 'The format of info', enum: %w(table yaml), default: 'table'
56
+ desc "--info, -i", "Print script/gem info"
57
+ method_option :'info-format', :type => :string, desc: "The format of info", enum: %w(table yaml), default: "table"
56
58
  # @return [NilClass] Prints Gem info
57
59
  def __print_info
58
60
  format = options[:'info-format']
59
- rows = {
60
- 'author(s)': Mkmatter::GemInfo.authors.join(', '),
61
- 'e-mail': Mkmatter::GemInfo.email.join(', '),
62
- 'mkmatter version': Mkmatter::VERSION,
63
- 'Ruby version': RbConfig::CONFIG['RUBY_PROGRAM_VERSION'],
64
- 'Platform': RbConfig::CONFIG['build_os'],
61
+ rows = {
62
+ 'author(s)': Mkmatter::GemInfo.authors.join(", "),
63
+ 'e-mail': Mkmatter::GemInfo.email.join(", "),
64
+ 'mkmatter version': Mkmatter::VERSION,
65
+ 'Ruby version': RbConfig::CONFIG["RUBY_PROGRAM_VERSION"],
66
+ 'Platform': RbConfig::CONFIG["build_os"],
65
67
  }
66
68
  case format
67
- when 'table'
68
- table = ::Terminal::Table.new
69
- table.style.alignment = :center
70
- table.title = 'mkmatter Info'
71
- table.rows = rows.to_a
72
- table.align_column(0, :left)
69
+ when "table"
70
+ table = ::Terminal::Table.new
71
+ table.style.alignment = :center
72
+ table.title = "mkmatter Info"
73
+ table.rows = rows.to_a
74
+ table.align_column(0, :left)
73
75
 
74
- puts table
75
- when 'yaml'
76
- puts rows.stringify_keys.to_yaml
77
- else
78
- # noop
79
- # this doesn't get run because of
80
- # the logic of options and their
81
- # enum parameter.
76
+ puts table
77
+ when "yaml"
78
+ puts rows.stringify_keys.to_yaml
79
+ else
80
+ # noop
81
+ # this doesn't get run because of
82
+ # the logic of options and their
83
+ # enum parameter.
82
84
  end
83
85
  end
84
86
 
85
- if Pathname(Dir.home).join('.local/bin/micro').exist?
86
- class_option(:editor, type: :string, default: "#{Dir.home}/.local/bin/micro")
87
+ option :publish, :type => :boolean
88
+ option :index, :type => :boolean, :default => nil
89
+ option :type, :type => :string, :default => "page"
90
+ option :draft, :type => :boolean, :default => nil
91
+ option :'include-post-qs', :type => :boolean, :default => false,
92
+ desc: "Include post questions in the prompt"
93
+ option :'dry-run', :type => :boolean, :default => false
94
+ desc "new [options]", "make front matter (and possibly content) for a jekyll site"
95
+ long_desc Mkmatter::App::Descriptions::New::NEW
96
+ def new
97
+ # @questions = Mkmatter::Questions::Post.new(HILINE).ask
98
+ @questions = Mkmatter::Questions.new.ask(options[:type], options[:include_post_qs])
99
+ answers = Mkmatter::Answers.new(@questions, options[:publish], options[:include_post_qs])
100
+ draft_folder = "_drafts"
101
+ filename = [].concat([answers.slug_date, "-", answers.title.to_slug, ".", answers.file_format.downcase]).join
87
102
 
88
- elsif Methods.which('micro')
89
- class_option(:editor, type: :string, default: 'micro')
90
- else
91
- class_option(:editor, type: :string, default: 'nano')
103
+ path = Pathname("./#{filename}").realdirpath
104
+ if HILINE.agree("Would you like to put this page into a subdirectory? ", true)
105
+ HILINE.say(<<~FOLDERDOC)
106
+ What path? (directories will be created if they don't exist, relative to Jekyll root)
107
+
108
+ FOLDERDOC
109
+ folder = HILINE.ask("? ") do |q|
110
+ q.confirm = true
111
+ q.default = "."
112
+ q.validate = /^[^\/].*$/
113
+ q.responses[:not_valid] = "Please enter a valid path, a relative path from the Jekyll root."
114
+ q.responses[:ask_on_error] = :question
115
+ end
116
+ folder = Pathname(folder)
117
+ if options[:'dry-run']
118
+ HILINE.say("Would create #{File.join(Pathname("."), folder)}")
119
+ else
120
+ begin
121
+ FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
122
+ rescue Errno::EEXIST
123
+ HILINE.say("<%= color('Error', :red, :bold) %>:Insufficient Permissions")
124
+ exit 1
125
+ end
126
+ end
127
+ if options[:'dry-run']
128
+ # If dry-run, don't check for the folder
129
+ # and just use the folder as is.
130
+ path = Pathname(folder).join(filename)
131
+ else
132
+ # Otherwise, check for the folder
133
+ path = Pathname(folder).realdirpath.join(filename)
134
+ end
135
+ end
136
+ if options[:'dry-run']
137
+ HILINE.say("Would create '#{path}'")
138
+ HILINE.say("Would output \n#{answers.to_yaml(indentation: 2)}\n---\n\n")
139
+ else
140
+ File.open(path.to_path, "a") do |fd|
141
+ fd.puts answers.to_yaml(indentation: 2)
142
+ fd.puts "---"
143
+ end
144
+ Mkmatter::Methods.launch_editor(options[:editor], path)
145
+ end
92
146
  end
93
- desc 'new SUBCOMMAND [options]', 'Make new content'
94
- subcommand 'new', Mkmatter::App::Classes::NewContent
95
- desc 'tags SUBCOMMAND [options]', 'Generate or Create tags'
96
- subcommand 'tags', Mkmatter::App::Classes::Tags
147
+
148
+ desc "tags SUBCOMMAND [options]", "Generate or Create tags"
149
+ subcommand "tags", Mkmatter::App::Classes::Tags
97
150
  end
98
151
  end
99
152
  end
@@ -1,21 +1,17 @@
1
- require 'highline'
2
- require 'paint'
1
+ require "highline"
2
+ require "paint"
3
3
  HighLine.colorize_strings
4
4
 
5
5
  module Mkmatter
6
6
  module App
7
7
  module Descriptions
8
8
  module New
9
- PAGE = ERB.new(<<-PAGE
10
- --`mkmatter new page` will run you through making a jekyll page.
11
- --Given the above options/flags you can modify how the script
9
+ NEW = ERB.new(<<-NEW
10
+ --`mkmatter new --type=page` will run you through making a jekyll page.
11
+ --Given the above options/flags you can either output the 'front matter'
12
+ --to STDOUT, or to a file.
12
13
  --outputs your front matter, or whether to mark it as published.
13
- --<%= Paint['OPTIONS', 'green', :bold] %>:
14
-
15
- PAGE
16
- ).result
17
-
18
- POST = ERB.new(<<-POSTDOC
14
+
19
15
  --`mkmatter new post` will run you through making a jekyll post.
20
16
  --Given the above options/flags you can modify how the script
21
17
  --outputs your front matter, and whether to mark it as published,
@@ -26,7 +22,16 @@ module Mkmatter
26
22
  ----so you have to explicitly use --no-publish to set
27
23
  ----`<%= HighLine.color('published', :yellow) %>: <%= HighLine.color('false', :yellow, :bold) %>`
28
24
 
29
- POSTDOC
25
+ --`mkmatter new --type=LAYOUT_TYPE` will run you through making a page using a custom
26
+ --layout type. This is useful for making a page that is not a post or a page.
27
+ --
28
+ --Examples of this include:
29
+ ----A bulma-clean-theme showcase page (--type=showcase)
30
+ ----A bulma-clean-theme recipe page (--type=recipe)
31
+ ----A bulma-clean-theme products page (--type=products)
32
+ --<%= Paint['OPTIONS', 'green', :bold] %>:
33
+
34
+ NEW
30
35
  ).result
31
36
  end
32
37