mkmatter 3.1.12 → 3.1.13

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: 90665a1c1eabe3028319ef3fdbde4770ebe1eeb22273bb6aa421a10a37455825
4
+ data.tar.gz: 7a8806195aee81dcacdc0e06895cf9873fe8b0db37f4fdd4a109b4aadc1369ed
5
5
  SHA512:
6
- metadata.gz: 447dc522fd22a5251b91de493d784280b3538e9b5efba59edb23caa8d7ea6d9eab1b4ed6660f5326f76c0e0a9cc6efbdc127b32d9d36969bde37b938b6e6a452
7
- data.tar.gz: 2298565c0ec52f408054374882a6be678fc5ec365951726f56c31c835a8d68c30504a75b0bd6c3c7d48c79bb36c653ef5929263bdbf1286a16909284baf2ae5d
6
+ metadata.gz: 0abe5786bea69019220f0b1248729602effcae72161f0b2f2f65f271c7508d396deb1c06b60c37d57ebf6080daa3fb7dfeb30fbba2aa5e697b16f084b9d30168
7
+ data.tar.gz: b954bf3927f4ce7306c3b9a3e95f2232ccfd0ad639fdf9edb82af65a1b30dc105ee724fdd3f801fe145c736effb1564644c7b331f1b39cfb6c3b2c3910f95ec3
@@ -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
@@ -15,6 +15,7 @@ module Mkmatter
15
15
  class Post
16
16
  attr :answers
17
17
  attr :extra_fields
18
+ @extra_fields = nil
18
19
  @hl = HighLine.new
19
20
 
20
21
  def ask
@@ -130,15 +131,25 @@ module Mkmatter
130
131
  end
131
132
  # @return [OpenStruct]
132
133
  end
133
-
134
134
  class Page
135
135
  attr :answers
136
+ attr :extra_fields
137
+ @extra_fields = nil
136
138
  @hl = HighLine.new
137
139
 
140
+ def ask
141
+ known_questions = methods.sort.delete_if { |m| m.to_s !~ /^get_.*$/ }
142
+ known_questions.each do |m|
143
+ @answers[:layout] = 'page'
144
+ @answers[m.to_s.gsub(/^get_[0-9]{3}_/, '')] = method(m).call
145
+ end
146
+ @answers
147
+ end
148
+
138
149
  # @!visibility private
139
150
  def initialize
140
151
  @answers = OpenStruct.new
141
-
152
+ @hl = HighLine.new
142
153
  end
143
154
 
144
155
  def get_001_title
@@ -162,7 +173,7 @@ module Mkmatter
162
173
  # @return [Array]
163
174
  def get_003_categories
164
175
  hl = @hl
165
- hl.ask("Categories? (write one on each line, then type '.') ") do |q|
176
+ hl.ask("Categories? (write one on each line, then type '.') ") do |q|
166
177
  q.gather = '.'
167
178
  end
168
179
  end
@@ -211,7 +222,7 @@ module Mkmatter
211
222
  menu.prompt = '? '
212
223
  end
213
224
  end
214
- # @return [Array[Hash]]
225
+ # @return [String]
215
226
  def get_006_extra_fields
216
227
  hl = @hl
217
228
  custom_fields = nil
@@ -1,5 +1,5 @@
1
1
  module Mkmatter
2
- VERSION = '3.1.12'
2
+ VERSION = '3.1.13'
3
3
 
4
4
  # Return gem information for certain commands and options
5
5
  class GemInfo
metadata CHANGED
@@ -1,7 +1,7 @@
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.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Spencer