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 +4 -4
- data/lib/mkmatter/answers.rb +7 -42
- data/lib/mkmatter/cli/subs/new.rb +103 -120
- data/lib/mkmatter/questions.rb +15 -7
- data/lib/mkmatter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee1ddb005d017b3ff2770792c609726b0781a610438ded6478fe341fd80fd0c6
|
4
|
+
data.tar.gz: 0c0e8e5e6d8a90ad22ec76f55c4e16d04d5ed088a029fc2ecb6e9ed58eb26364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e296cc973212407e248cf12c2d428f9e66edc0b1a06319d40cd2f132b16a74eb114745ecc28cff16e6e93beb5bf971f63eca4f34720b0c13634d5efa4965d58f
|
7
|
+
data.tar.gz: 29dd5eb705e9ef85eb0943499703afc9f0fc56b6e66cc96e139895ed429e9c5609d644d0464185b45264697f57f77fb89d5753ac4a29e1a5fd465581b949d00f
|
data/lib/mkmatter/answers.rb
CHANGED
@@ -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
|
-
|
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
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
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
|
-
|
63
|
-
|
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
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
data/lib/mkmatter/questions.rb
CHANGED
@@ -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("<%
|
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
|
-
|
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
|
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 [
|
222
|
+
# @return [String]
|
215
223
|
def get_006_extra_fields
|
216
224
|
hl = @hl
|
217
225
|
custom_fields = nil
|
data/lib/mkmatter/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2025-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|