mkmatter 3.1.12 → 3.1.14

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: 9e51dd62ad3fe54420a842a181a3214e3cd8e24ea3f06ad61f93d43d7cb83667
4
- data.tar.gz: 46d59dca27686feb195470b558d7e7b30b25ed5ec7ea809a2b135659363a1539
3
+ metadata.gz: ee1ddb005d017b3ff2770792c609726b0781a610438ded6478fe341fd80fd0c6
4
+ data.tar.gz: 0c0e8e5e6d8a90ad22ec76f55c4e16d04d5ed088a029fc2ecb6e9ed58eb26364
5
5
  SHA512:
6
- metadata.gz: 447dc522fd22a5251b91de493d784280b3538e9b5efba59edb23caa8d7ea6d9eab1b4ed6660f5326f76c0e0a9cc6efbdc127b32d9d36969bde37b938b6e6a452
7
- data.tar.gz: 2298565c0ec52f408054374882a6be678fc5ec365951726f56c31c835a8d68c30504a75b0bd6c3c7d48c79bb36c653ef5929263bdbf1286a16909284baf2ae5d
6
+ metadata.gz: e296cc973212407e248cf12c2d428f9e66edc0b1a06319d40cd2f132b16a74eb114745ecc28cff16e6e93beb5bf971f63eca4f34720b0c13634d5efa4965d58f
7
+ data.tar.gz: 29dd5eb705e9ef85eb0943499703afc9f0fc56b6e66cc96e139895ed429e9c5609d644d0464185b45264697f57f77fb89d5753ac4a29e1a5fd465581b949d00f
@@ -7,7 +7,8 @@ module Mkmatter
7
7
  attr_accessor :date, :draft
8
8
  attr_accessor :slug_date, :answer_hash
9
9
  attr_accessor :published, :file_format
10
- attr_reader :matter
10
+ attr_accessor :matter
11
+ attr_accessor :extra_fields
11
12
 
12
13
  def initialize(question_hash, publish)
13
14
  @title = question_hash[:title]
@@ -19,6 +20,8 @@ module Mkmatter
19
20
  @slug_date = now.strftime('%Y-%m-%d')
20
21
  @published = publish
21
22
  @file_format = question_hash[:file_format]
23
+ @extra_fields = question_hash[:extra_fields]
24
+
22
25
  @matter = {
23
26
  layout: question_hash[:layout],
24
27
  title: @title,
@@ -26,49 +29,11 @@ module Mkmatter
26
29
  tags: @tags,
27
30
  date: @date,
28
31
  }
32
+ if @extra_fields
33
+ @matter.merge!(@extra_fields)
34
+ end
29
35
  @matter[:published] = @published if publish
30
36
  end
31
37
 
32
- # @return [Hash] returns attribute `.matter`
33
- def to_h
34
- @matter
35
- end
36
-
37
- # @param [Hash] hash other hash
38
- # @return [nil] merges hash into attribute `.matter`
39
- def to_h=(hash)
40
- @matter.merge!(hash)
41
- end
42
-
43
- alias_method :inspect, :to_h
44
- #
45
- # Dumps all file applicable metadata to a provided output.
46
- # @return [String] yaml front matter
47
- def dump
48
- custom_fields = nil
49
- hl = HighLine.new($stdin, $stderr, 80)
50
- # Custom matter
51
- if hl.agree('Do you want to add custom fields? (usable as {{LAYOUT_TYPE.FIELD}} in templates) ', true)
52
- hl.say('Your fields should be inputted as FIELD=>TEXT HERE')
53
- hl.say("Type 'EOL' on a new line then press Enter when you are done.")
54
- hl.say("<% HighLine.color('NOTE', :bold, :red) %>: Input is <% HighLine.color('NOT', :bold, :red) %> evaluated!")
55
- custom_fields = hl.ask('Fields?') do |q|
56
- q.gather = /^EOL$/
57
- end
58
- end
59
- if custom_fields
60
- fields = Hash.new
61
- custom_fields.each do |field|
62
- field = field.split(/=>/)
63
- fields.store(field[0].to_s, field[1])
64
- end
65
- self.to_h = fields
66
- elsif custom_fields.nil?
67
- hl.say('No extra fields were added.')
68
- else
69
- end
70
- self.to_h.stringify_keys.to_yaml(indentation: 2)
71
- '---'
72
- end
73
38
  end
74
39
  end
@@ -19,51 +19,43 @@ module Mkmatter
19
19
  long_desc Mkmatter::App::Descriptions::New::PAGE
20
20
 
21
21
  def page
22
- if options[:file]
23
- if Mkmatter::Methods.check_if_jekyll
24
- @questions = Mkmatter::Questions::Page.new(HILINE).ask
25
- answers = Mkmatter::Answers.new(@questions, options.fetch(:publish, nil))
26
- if options.fetch(:index, nil)
27
- filename = 'index.' + answers.file_format.downcase
28
- else
29
- filename = answers.title.to_slug + '.' + answers.file_format.downcase
30
- end
22
+ if Mkmatter::Methods.check_if_jekyll
23
+ @questions = Mkmatter::Questions::Page.new(HILINE).ask
24
+ answers = Mkmatter::Answers.new(@questions, options.fetch(:publish, nil))
25
+ if options.fetch(:index, nil)
26
+ filename = 'index.' + answers.file_format.downcase
27
+ else
28
+ filename = answers.title.to_slug + '.' + answers.file_format.downcase
29
+ end
31
30
 
32
- path = Pathname("./#{filename}").realdirpath
33
- if HILINE.agree('Would you like to put this page into a subdirectory?', true)
34
- HILINE.say("What path? (directories will be created if they don't exist) ")
35
- HILINE.say("Don't use a path starting with a slash, just put a relative path.")
36
- HILINE.say('good => path/to/dir ‖ bad => /absolute/paths/are/bad/mmkay')
37
- folder = HILINE.ask('? ') do |q|
38
- q.confirm = true
39
- q.default = '.'
40
- q.validate = /^[^\/].*$/
41
- end
42
- folder = Pathname(folder)
43
- begin
44
- FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
45
- rescue Errno::EEXIST
46
- HILINE.say("<%= Paint['Error', 'red', :bold] %>: Insufficient Permissions")
47
- exit 1
48
- end
49
- path = Pathname(folder).realdirpath.join(filename)
31
+ path = Pathname("./#{filename}").realdirpath
32
+ if HILINE.agree('Would you like to put this page into a subdirectory?', true)
33
+ HILINE.say("What path? (directories will be created if they don't exist) ")
34
+ HILINE.say("Don't use a path starting with a slash, just put a relative path.")
35
+ HILINE.say('good => path/to/dir ‖ bad => /absolute/paths/are/bad/mmkay')
36
+ folder = HILINE.ask('? ') do |q|
37
+ q.confirm = true
38
+ q.default = '.'
39
+ q.validate = /^[^\/].*$/
50
40
  end
51
- File.open(path.to_path, 'a') do |fd|
52
- answers.to_h = {:layout => 'page'}
53
- fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
54
- fd.puts '---'
41
+ folder = Pathname(folder)
42
+ begin
43
+ FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
44
+ rescue Errno::EEXIST
45
+ HILINE.say("<%= Paint['Error', 'red', :bold] %>: Insufficient Permissions")
46
+ exit 1
55
47
  end
56
- Mkmatter::Methods.launch_editor(options[:editor], path)
57
- else
58
- $stderr.puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
59
- exit 1
48
+ path = Pathname(folder).realdirpath.join(filename)
60
49
  end
50
+ File.open(path.to_path, 'a') do |fd|
51
+ answers.to_h = {:layout => 'page'}
52
+ fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
53
+ fd.puts '---'
54
+ end
55
+ Mkmatter::Methods.launch_editor(options[:editor], path)
61
56
  else
62
- @questions = Mkmatter::Questions::Page.new(HILINE).ask
63
- answers = Mkmatter::Answers.new(@questions, options.fetch(:publish, nil))
64
- puts ''
65
- puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
66
- puts '---'
57
+ $stderr.puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
58
+ exit 1
67
59
  end
68
60
  end
69
61
 
@@ -75,94 +67,85 @@ module Mkmatter
75
67
  long_desc Mkmatter::App::Descriptions::New::POST
76
68
 
77
69
  def post
78
- if options[:draft] and options[:file]
79
- if Mkmatter::Methods.check_if_jekyll
80
- # @questions = Mkmatter::Questions::Post.new(HILINE).ask
81
- @questions = Mkmatter::Questions::Post.new.ask
82
- answers = Mkmatter::Answers.new(@questions, options[:publish])
83
- file_folder = '_drafts'
84
- filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join
70
+ if Mkmatter::Methods.check_if_jekyll
71
+ # @questions = Mkmatter::Questions::Post.new(HILINE).ask
72
+ @questions = Mkmatter::Questions::Post.new.ask
73
+ answers = Mkmatter::Answers.new(@questions, options[:publish])
74
+ draft_folder = '_drafts'
75
+ filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join
85
76
 
86
- path = Pathname("./#{file_folder}/#{filename}").realdirpath
87
- if HILINE.agree('Would you like to put this page into a subdirectory?', true)
88
- HILINE.say("What path? (directories will be created if they don't exist)")
89
- HILINE.say("Don't use a path starting with a slash, just put a relative path.")
90
- HILINE.say("<% Paint['Good', 'green', :bold] %>: path/to/dir ‖ <%= color('Bad', 'red', :bold) %>: /absolute/paths/are/bad/mmkay")
91
- folder = HILINE.ask('? ') do |q|
92
- q.confirm = true
93
- q.default = '.'
94
- q.validate = /^[^\/].*$/
95
- end
96
- folder = Pathname(folder)
97
- begin
98
- FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
99
- rescue Errno::EEXIST
100
- HILINE.say("<% Paint['Error', 'red', :bold] %>:Insufficient Permissions")
101
- exit 1
102
- end
103
- path = Pathname(folder).realdirpath.join(filename)
77
+ path = Pathname("./#{file_folder}/#{filename}").realdirpath
78
+ if HILINE.agree('Would you like to put this page into a subdirectory?', true)
79
+ HILINE.say("What path? (directories will be created if they don't exist)")
80
+ HILINE.say("Don't use a path starting with a slash, just put a relative path.")
81
+ HILINE.say("<% Paint['Good', 'green', :bold] %>: path/to/dir ‖ <%= color('Bad', 'red', :bold) %>: /absolute/paths/are/bad/mmkay")
82
+ folder = HILINE.ask('? ') do |q|
83
+ q.confirm = true
84
+ q.default = '.'
85
+ q.validate = /^[^\/].*$/
104
86
  end
105
- File.open(path.to_path, 'a') do |fd|
106
- answers.to_h = {:layout => 'post'}
107
- fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
108
- fd.puts '---'
87
+ folder = Pathname(folder)
88
+ begin
89
+ FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
90
+ rescue Errno::EEXIST
91
+ HILINE.say("<% Paint['Error', 'red', :bold] %>:Insufficient Permissions")
92
+ exit 1
109
93
  end
110
- Mkmatter::Methods.launch_editor(options[:editor], path)
111
- else
112
- puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
113
- exit 1
94
+ path = Pathname(folder).realdirpath.join(filename)
114
95
  end
115
- elsif options[:file] and options[:draft].nil? or options[:draft] == false
116
-
117
- if Mkmatter::Methods.check_if_jekyll
118
- # @questions = Mkmatter::Questions::Post.new(HILINE).ask
119
- @questions = Mkmatter::Questions::Post.new.ask
120
- answers = Mkmatter::Answers.new(@questions, options[:publish])
121
- file_folder = '_posts'
122
- filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join('')
123
- path = Pathname("./#{file_folder}/#{filename}").realdirpath
124
- if HILINE.agree('Would you like to put this post into a subdirectory?', true)
125
- HILINE.say('What path?')
126
- HILINE.say('----------------')
127
- HILINE.say("Don't use a path starting with a slash, just put a relative path.")
128
- HILINE.say("If you enter a path you don't like, you will have manually remove it if you confirm it.")
129
- HILINE.say("<% Paint['Good', 'green', :bold] %>: path/to/dir ‖ <% Paint['Bad', :red, :bold] %>: /root/paths/are/bad/mmkay")
130
- folder = HILINE.ask('? ') do |q|
131
- q.confirm = true
132
- q.default = '.'
133
- q.validate = /^[^\/].*$/
134
- end
135
- folder = Pathname("#{file_folder}/#{folder}")
136
- begin
137
- FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
138
- rescue Errno::EEXIST
139
- HILINE.say("<% Paint['Error', 'red', :bold] %>:Insufficient Permissions")
140
- exit 1
141
- end
142
- path = Pathname(folder).realdirpath.join(filename)
143
- end
144
- File.open(path.to_path, 'a') do |fd|
145
- answers.to_h = {:layout => 'post'}
146
- fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
147
- fd.puts '---'
148
- end
149
-
150
- Mkmatter::Methods.launch_editor(options[:editor], path)
151
- else
152
- puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
153
- exit 1
96
+ File.open(path.to_path, 'a') do |fd|
97
+ answers.to_h = {:layout => 'post'}
98
+ fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
99
+ fd.puts '---'
154
100
  end
155
- elsif options[:draft].nil? and options[:file].nil?
156
- @questions = Mkmatter::Questions::Post.new.ask
157
- # @questions = Mkmatter::Questions::Post.new(HILINE).ask
158
- answers = Mkmatter::Answers.new(@questions, options[:publish])
159
- puts ''
160
- puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
161
- puts '---'
162
-
101
+ Mkmatter::Methods.launch_editor(options[:editor], path)
102
+ else
103
+ puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
104
+ exit 1
163
105
  end
164
106
  end
165
107
  end
166
108
  end
167
109
  end
168
110
  end
111
+ elsif options[:draft].nil? or options[:draft] == false
112
+
113
+ # if Mkmatter::Methods.check_if_jekyll
114
+ # # @questions = Mkmatter::Questions::Post.new(HILINE).ask
115
+ # @questions = Mkmatter::Questions::Post.new.ask
116
+ # answers = Mkmatter::Answers.new(@questions, options[:publish])
117
+ # file_folder = '_posts'
118
+ # filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join('')
119
+ # path = Pathname("./#{file_folder}/#{filename}").realdirpath
120
+ # if HILINE.agree('Would you like to put this post into a subdirectory?', true)
121
+ # HILINE.say('What path?')
122
+ # HILINE.say('----------------')
123
+ # HILINE.say("Don't use a path starting with a slash, just put a relative path.")
124
+ # HILINE.say("If you enter a path you don't like, you will have manually remove it if you confirm it.")
125
+ # HILINE.say("<% Paint['Good', 'green', :bold] %>: path/to/dir ‖ <% Paint['Bad', :red, :bold] %>: /root/paths/are/bad/mmkay")
126
+ # folder = HILINE.ask('? ') do |q|
127
+ # q.confirm = true
128
+ # q.default = '.'
129
+ # q.validate = /^[^\/].*$/
130
+ # end
131
+ # folder = Pathname("#{file_folder}/#{folder}")
132
+ # begin
133
+ # FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
134
+ # rescue Errno::EEXIST
135
+ # HILINE.say("<% Paint['Error', 'red', :bold] %>:Insufficient Permissions")
136
+ # exit 1
137
+ # end
138
+ # path = Pathname(folder).realdirpath.join(filename)
139
+ # end
140
+ # File.open(path.to_path, 'a') do |fd|
141
+ # answers.to_h = {:layout => 'post'}
142
+ # fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
143
+ # fd.puts '---'
144
+ # end
145
+
146
+ # Mkmatter::Methods.launch_editor(options[:editor], path)
147
+ # else
148
+ # puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
149
+ # exit 1
150
+ # end
151
+ # end
@@ -1,4 +1,5 @@
1
1
  require 'highline'
2
+ require 'highline/color'
2
3
  require 'ostruct'
3
4
  module Mkmatter
4
5
  module Questions
@@ -14,7 +15,6 @@ module Mkmatter
14
15
 
15
16
  class Post
16
17
  attr :answers
17
- attr :extra_fields
18
18
  @hl = HighLine.new
19
19
 
20
20
  def ask
@@ -109,7 +109,7 @@ module Mkmatter
109
109
  if hl.agree('Do you want to add custom fields? (usable as {{LAYOUT_TYPE.FIELD}} in templates) ', true)
110
110
  hl.say('Your fields should be inputted as FIELD=>TEXT HERE')
111
111
  hl.say("Type 'EOL' on a new line then press Enter when you are done.")
112
- hl.say("<% HighLine.color('NOTE', :bold, :red) %>: Input is <% HighLine.color('NOT', :bold, :red) %> evaluated!")
112
+ hl.say("<% color('NOTE', :bold, :red) %>: Input is <% color('NOT', :bold, :red) %> evaluated!")
113
113
  custom_fields = hl.ask('Fields?') do |q|
114
114
  q.gather = /^EOL$/
115
115
  end
@@ -120,7 +120,7 @@ module Mkmatter
120
120
  field = field.split(/=>/)
121
121
  fields.store(field[0].to_s, field[1])
122
122
  end
123
- self.extra_fields = fields
123
+
124
124
  elsif custom_fields.nil?
125
125
  hl.say('No extra fields were added.')
126
126
  return
@@ -130,15 +130,23 @@ module Mkmatter
130
130
  end
131
131
  # @return [OpenStruct]
132
132
  end
133
-
134
133
  class Page
135
134
  attr :answers
136
135
  @hl = HighLine.new
137
136
 
137
+ def ask
138
+ known_questions = methods.sort.delete_if { |m| m.to_s !~ /^get_.*$/ }
139
+ known_questions.each do |m|
140
+ @answers[:layout] = 'page'
141
+ @answers[m.to_s.gsub(/^get_[0-9]{3}_/, '')] = method(m).call
142
+ end
143
+ @answers
144
+ end
145
+
138
146
  # @!visibility private
139
147
  def initialize
140
148
  @answers = OpenStruct.new
141
-
149
+ @hl = HighLine.new
142
150
  end
143
151
 
144
152
  def get_001_title
@@ -162,7 +170,7 @@ module Mkmatter
162
170
  # @return [Array]
163
171
  def get_003_categories
164
172
  hl = @hl
165
- hl.ask("Categories? (write one on each line, then type '.') ") do |q|
173
+ hl.ask("Categories? (write one on each line, then type '.') ") do |q|
166
174
  q.gather = '.'
167
175
  end
168
176
  end
@@ -211,7 +219,7 @@ module Mkmatter
211
219
  menu.prompt = '? '
212
220
  end
213
221
  end
214
- # @return [Array[Hash]]
222
+ # @return [String]
215
223
  def get_006_extra_fields
216
224
  hl = @hl
217
225
  custom_fields = nil
@@ -1,5 +1,5 @@
1
1
  module Mkmatter
2
- VERSION = '3.1.12'
2
+ VERSION = '3.1.14'
3
3
 
4
4
  # Return gem information for certain commands and options
5
5
  class GemInfo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkmatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.12
4
+ version: 3.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Spencer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-30 00:00:00.000000000 Z
11
+ date: 2025-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline