mkmatter 3.1.19 → 3.2.0

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: 7304c83014128ff9532cd76f7a3b9806b782e0735d47831c98a41b3324f883db
4
- data.tar.gz: 41f7f6dee52f1a6dfd3ee4250cf6d96c58d6d99419a7009a91ea0666d3e4191b
3
+ metadata.gz: 985cf93b9ef0d39c5e217e52fa84bfd67eb7c147fb16e44bd42af61e6b6ba523
4
+ data.tar.gz: 648d7ae5a84fdbe29093f1b2f1645944720e6dc5f65e40b0ee2ecb58704e9327
5
5
  SHA512:
6
- metadata.gz: d5baebb4810de5240b2e2558e9244a235a8a9d9496ce1e4d6a2fc53185f06d3219455d5c3140317e60b267e0067251d36e70d190ac4821afe69f0cd99d69e044
7
- data.tar.gz: 0d74b60662ed5d4aa4364ac81c7e7870195b1732a5e028a9dcdc969005d1a42a26ff7832d69dd5abff9a71f488cd45feff73a4ba21156670651d869f62ed3036
6
+ metadata.gz: d124c6644cee5b680dbb9ceb3638882544ef723df471112bb47cec198bd0b85b4bcf3ad7b5c90b80140c4076ce3e6a82f85de3bc7e9c66eded08fa41ad590539
7
+ data.tar.gz: 0c96a0be07c0fd565d4e9ea5fa390049aae54f1d7f4357b8808fbce1797cb917ecb71b45884023bdfdf836321780bb6fe0d8547911c001616096baec8136b13a
@@ -2,7 +2,7 @@ require 'yaml'
2
2
  require 'time'
3
3
  require 'mkmatter/helpers'
4
4
  module Mkmatter
5
- class Answers
5
+ class Answers < Object
6
6
  attr_accessor :title, :tags, :categories, :date, :draft, :slug_date, \
7
7
  :answer_hash, :published, :file_format, :matter, :extra_fields, :summary
8
8
 
@@ -14,9 +14,11 @@ module Mkmatter
14
14
  end
15
15
  @tags = question_hash[:tags] if question_hash[:tags].nil? == false
16
16
  @categories = question_hash[:categories] if question_hash[:categories].nil? == false
17
- Time.zone = get_time_zone_full(Time.now.getlocal) || 'Eastern Time (US & Canada)' if (include_post_fields == true || @layout == 'post')
17
+ if include_post_fields == true || @layout == 'post'
18
+ Time.zone = get_time_zone_full(Time.now.getlocal) || 'Eastern Time (US & Canada)'
19
+ end
18
20
  # Time.zone = question_hash[:time_zone] || Time.now.zone
19
- @now = Time.zone.now || Time.now.getlocal
21
+ @now = Time.zone.now || Time.now.getlocal
20
22
  @date = @now.to_s if include_post_fields == true
21
23
  @slug_date = @now.strftime('%Y-%m-%d') if include_post_fields == true
22
24
  @published = publish
@@ -26,15 +28,15 @@ module Mkmatter
26
28
  @summary = question_hash[:summary] unless question_hash[:summary].empty?
27
29
  end
28
30
 
29
- @matter = {
30
- layout: @layout,
31
- title: @title,
31
+ @matter = {
32
+ layout: @layout,
33
+ title: @title
32
34
  }
33
- if @layout == 'post' or include_post_fields
34
- @matter[:tags] = @tags if @tags
35
+ if @layout == 'post' || include_post_fields
36
+ @matter[:tags] = @tags if @tags
35
37
  @matter[:categories] = @categories if @categories
36
- @matter[:summary] = @summary if @summary
37
- @matter[:date] = @date
38
+ @matter[:summary] = @summary if @summary
39
+ @matter[:date] = @date
38
40
 
39
41
  end
40
42
  if @draft
@@ -46,19 +48,22 @@ module Mkmatter
46
48
  @matter[:published] = @published if publish
47
49
  end
48
50
 
49
- # @return [Hash] returns attribute `.matter`
51
+ # @return [Hash] returns attribute `.matter`
50
52
  def to_h
51
53
  @matter
52
54
  end
53
55
 
56
+ def [](arg)
57
+ self.instance_variable_get("@#{arg}")
58
+ end
54
59
  # @param [Hash] hash other hash
55
60
  # @return [nil] merges hash into attribute `.matter`
56
61
  def to_h=(hash)
57
62
  @matter.merge!(hash)
58
63
  end
64
+
59
65
  def to_yaml(*args, **kwargs)
60
66
  @matter.stringify_keys.to_yaml(*args, **kwargs)
61
67
  end
62
-
63
68
  end
64
69
  end
@@ -1,14 +1,14 @@
1
- require "thor"
2
- require "highline"
3
- require "slugity/extend_string"
4
- require "yaml"
5
1
  require "active_support/all"
6
- require "terminal-table"
7
- require "os"
8
- require "rbconfig"
2
+ require "highline"
9
3
  require "mkmatter/version"
10
4
  require "mkmatter/cli/subs"
11
5
  require 'mkmatter/cli/descriptions'
6
+ require "os"
7
+ require "rbconfig"
8
+ require "slugity"
9
+ require "terminal-table"
10
+ require "thor"
11
+ require "yaml"
12
12
 
13
13
  module Mkmatter
14
14
  module App
@@ -96,15 +96,16 @@ module Mkmatter
96
96
  @questions = Mkmatter::Questions.new.ask(options[:type], options[:include_post_qs])
97
97
  answers = Mkmatter::Answers.new(@questions, options[:publish], options[:include_post_qs])
98
98
  draft_folder = "_drafts"
99
- filename = [].concat([answers.slug_date, "-", answers.title.to_slug, ".", answers.file_format.downcase]).join
99
+ filename = [].concat([answers['slug_date'], '-', Slugity::Convert.slug(answers['title']), '.', answers['file_format'].downcase]).join
100
100
 
101
101
  path = Pathname("./#{filename}").realdirpath
102
- if HILINE.agree("Would you like to put this page into a subdirectory? ", true)
103
- HILINE.say(<<~FOLDERDOC)
102
+ hl = HighLine.new
103
+ if hl.agree("Would you like to put this page into a subdirectory? ", true)
104
+ hl.say(<<~FOLDERDOC)
104
105
  What path? (directories will be created if they don't exist, relative to Jekyll root)
105
-
106
+
106
107
  FOLDERDOC
107
- folder = HILINE.ask("? ") do |q|
108
+ folder = hl.ask("? ") do |q|
108
109
  q.confirm = true
109
110
  q.default = "."
110
111
  q.validate = /^[^\/].*$/
@@ -113,12 +114,12 @@ module Mkmatter
113
114
  end
114
115
  folder = Pathname(folder)
115
116
  if options[:'dry-run']
116
- HILINE.say("Would create #{File.join(Pathname("."), folder)}")
117
+ hl.say("Would create #{File.join(Pathname("."), folder)}")
117
118
  else
118
119
  begin
119
120
  FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
120
121
  rescue Errno::EEXIST
121
- HILINE.say("<%= color('Error', :red, :bold) %>:Insufficient Permissions")
122
+ hl.say("<%= color('Error', :red, :bold) %>:Insufficient Permissions")
122
123
  exit 1
123
124
  end
124
125
  end
@@ -132,8 +133,8 @@ module Mkmatter
132
133
  end
133
134
  end
134
135
  if options[:'dry-run']
135
- HILINE.say("Would create '#{path}'")
136
- HILINE.say("Would output \n#{answers.to_yaml(indentation: 2)}\n---\n\n")
136
+ hl.say("Would create '#{path}'")
137
+ hl.say("Would output \n#{answers.to_yaml(indentation: 2)}\n---\n\n")
137
138
  else
138
139
  File.open(path.to_path, "a") do |fd|
139
140
  fd.puts answers.to_yaml(indentation: 2)
@@ -30,12 +30,11 @@ module Mkmatter
30
30
  end
31
31
  known_questions.each do |m|
32
32
  @answers[:layout] = type
33
- @answers[m.to_s.gsub(/^get_[0-9]{3}_/, '')] = method(m).call
33
+ @answers[m.to_s.gsub(/^get_[0-9]{3}_/, '').to_sym] = method(m).call
34
34
  end
35
35
  @answers
36
36
  end
37
37
 
38
- # @!visibility private
39
38
  def initialize
40
39
  @answers = {}
41
40
  end
@@ -47,13 +46,15 @@ module Mkmatter
47
46
  else
48
47
  title
49
48
  end
49
+ title # =>
50
50
  end
51
51
 
52
52
  # @return [Array]
53
53
  def get_002_tags
54
- @@hl.ask("Tags? (write one on each line, then press '.' then press 'Enter')") do |q|
54
+ tags = @@hl.ask("Tags? (write one on each line, then press '.' then press 'Enter') ") do |q|
55
55
  q.gather = '.'
56
56
  end
57
+ tags
57
58
  end
58
59
 
59
60
  # @return [Array]
@@ -80,7 +81,7 @@ module Mkmatter
80
81
  # @return [String]
81
82
  def get_005_extra_fields
82
83
  fields = {}
83
- custom_fields = nil
84
+ custom_fields = []
84
85
  cfh = nil
85
86
  if @@hl.agree("Do you want to add custom fields? ", true)
86
87
  @@hl.say(<<~EXTRA_FIELDS)
@@ -93,7 +94,7 @@ module Mkmatter
93
94
  q.gather = '.'
94
95
  end
95
96
  end
96
- if !custom_fields.empty?
97
+ unless custom_fields.empty?
97
98
  custom_fields.each do |field|
98
99
  fields.store(field.to_sym, 'nil')
99
100
  end
@@ -102,7 +103,7 @@ module Mkmatter
102
103
  @@hl.say('No extra fields were added.')
103
104
  return
104
105
  else
105
- @@hl.say("#{fields} #{fields.class}")
106
+ # @@hl.say("#{fields} #{fields.class}")
106
107
  cfh = @@hl.ask("Value of field '<%= key %>'?") do |q|
107
108
  q.gather = fields
108
109
  end
@@ -123,7 +124,7 @@ module Mkmatter
123
124
  q.gather = '.'
124
125
  end
125
126
  end
126
- summary.join("\n")
127
+ summary.join("\n") if summary
127
128
  end
128
129
  end
129
130
  end
@@ -1,5 +1,5 @@
1
1
  module Mkmatter
2
- VERSION = '3.1.19'
2
+ VERSION = '3.2.0'
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.19
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Spencer