mkmatter 3.0.43 → 3.0.44

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.
@@ -2,86 +2,85 @@ require 'highline'
2
2
  require 'find'
3
3
  require 'yaml'
4
4
  module Mkmatter
5
- class Methods
6
- # @return [Boolean] whether current directory is inside a jekyll site source directory
7
- def Methods.check_if_jekyll
8
- cwd = Pathname.new('.')
5
+ class Methods
6
+ # @return [Boolean] whether current directory is inside a jekyll site source directory
7
+ def Methods.check_if_jekyll
8
+ cwd = Pathname.new('.')
9
+ cwd.ascend do |path|
10
+ if path.join('_config.yml').exist?
11
+ break true
12
+ elsif cwd.to_s == '/'
13
+ # hit root, stop
14
+ break false
15
+ end
16
+ end
17
+ end
18
+
19
+ # @return [Pathname] path of current jekyll site source roo
20
+ def Methods.get_jekyll_root
21
+ if Methods.check_if_jekyll
22
+ cwd = Pathname.new('.').realdirpath
9
23
  cwd.ascend do |path|
10
24
  if path.join('_config.yml').exist?
11
- break true
12
- elsif cwd.to_s == '/'
13
- # hit root, stop
14
- break false
25
+ return path
26
+ else
27
+ next
15
28
  end
16
29
  end
17
30
  end
18
-
19
- # @return [Pathname] path of current jekyll site source roo
20
- def Methods.get_jekyll_root
21
- if Methods.check_if_jekyll
22
- cwd = Pathname.new('.').realdirpath
23
- cwd.ascend do |path|
24
- if path.join('_config.yml').exist?
25
- return path
26
- else
27
- next
28
- end
29
- end
31
+ end
32
+
33
+ # @return [NilClass] nil
34
+ def Methods.launch_editor(editor, file_path)
35
+ hl = HighLine.new($stdin, $stderr, 80)
36
+ if file_path
37
+ if hl.agree("Would you like to open an editor? ('editor' command) ", true)
38
+ pid = spawn("#{} #{file_path}")
39
+ Process.wait pid
30
40
  end
31
41
  end
32
-
33
- # @return [NilClass] nil
34
- def Methods.launch_editor(file_path)
35
- hl = HighLine.new($stdin, $stderr, 80)
36
- if file_path
37
- if hl.agree("Would you like to open an editor? ('editor' command) ", true)
38
- pid = spawn("editor #{file_path}")
39
- Process.wait pid
40
- end
41
- end
42
+ end
43
+
44
+ # @param [String] type type of content
45
+ # @param [String] key root yaml directive to return
46
+ # @return [Hash] front matter
47
+ def Methods.find_front_matter(type, key)
48
+ unless type =~ /^(post|page)$/
49
+ $stderr.puts "#{HighLine.color('Error', :red, :bold)}: Invalid Argument, allowed values: post, page"
50
+ exit 1
42
51
  end
43
-
44
- # @param [String] type type of content
45
- # @param [String] key root yaml directive to return
46
- # @return [Hash] front matter
47
- def Methods.find_front_matter(type, key)
48
- unless type =~ /^(post|page)$/
49
- $stderr.puts "#{HighLine.color('Error', :red, :bold)}: Invalid Argument, allowed values: post, page"
50
- exit 1
51
- end
52
- yaml_loader = ->(string) {YAML.load(string)}
53
- files = {}
54
- html_front_matter = []
55
- md_front_matter = []
56
- front_matter = {}
57
- case type
58
- when 'page'
59
- Find.find(Methods.get_jekyll_root.to_s) do |path|
60
- Find.prune if path =~ /(_includes|_layouts|_docs|_site)/ # don't include layouts, includes, site, docs
61
- Find.prune if path =~ /(_posts)/ # don't include our own posts either
62
- Find.prune if path =~ /(vendor\/bundle)/ # don't include vendor/
63
- Find.prune if path =~ /(\/tag\/)/ # don't include our own tags
64
- html_front_matter << path if path =~ /.*\.html$/
65
- md_front_matter << path if path =~ /.*\.md$/
66
- end
67
-
68
- when 'post'
69
- Find.find(Pathname(Methods.get_jekyll_root).join('_posts').to_path) do |path|
70
- html_front_matter << path if path =~ /.*\.html$/
71
- md_front_matter << path if path =~ /.*\.md$/
72
- end
73
- else
74
- # noop
75
- end
76
- files['html'] = html_front_matter
77
- files['md'] = md_front_matter
78
- files.each do |ftype, array|
79
- array.each do |ele|
80
- front_matter[ele] = YAML.load_file(ele)[key]
52
+ files = {}
53
+ html_front_matter = []
54
+ md_front_matter = []
55
+ front_matter = {}
56
+ case type
57
+ when 'page'
58
+ Find.find(Methods.get_jekyll_root.to_s) do |path|
59
+ Find.prune if path =~ /(_includes|_layouts|_docs|_site)/ # don't include layouts, includes, site, docs
60
+ Find.prune if path =~ /(_posts)/ # don't include our own posts either
61
+ Find.prune if path =~ /(vendor\/bundle)/ # don't include vendor/
62
+ Find.prune if path =~ /(\/tag\/)/ # don't include our own tags
63
+ html_front_matter << path if path =~ /.*\.html$/
64
+ md_front_matter << path if path =~ /.*\.md$/
65
+ end
66
+
67
+ when 'post'
68
+ Find.find(Pathname(Methods.get_jekyll_root).join('_posts').to_path) do |path|
69
+ html_front_matter << path if path =~ /.*\.html$/
70
+ md_front_matter << path if path =~ /.*\.md$/
81
71
  end
72
+ else
73
+ # noop
74
+ end
75
+ files['html'] = html_front_matter
76
+ files['md'] = md_front_matter
77
+ files.each do |ftype, array|
78
+ array.each do |ele|
79
+ front_matter[ele] = YAML.load_file(ele)[key]
82
80
  end
83
- front_matter.select! {|k, v| !v.nil?}
84
- front_matter
85
81
  end
82
+ front_matter.select! {|k, v| !v.nil?}
83
+ front_matter
86
84
  end
87
- end
85
+ end
86
+ end
@@ -24,7 +24,7 @@ module Mkmatter
24
24
  # The ruby interpreter would pipe this to STDERR and exit 1 in the case of an unhandled exception
25
25
  b = e.backtrace
26
26
  @stderr.puts("#{b.shift}: #{e.message} (#{e.class})")
27
- @stderr.puts(b.map {|s| "\tfrom #{s}"}.join("\n"))
27
+ @stderr.puts(b.map { |s| "\tfrom #{s}" }.join("\n"))
28
28
  1
29
29
  rescue SystemExit => e
30
30
  e.status
@@ -1,4 +1,5 @@
1
1
  require 'highline'
2
+ require 'thor'
2
3
 
3
4
  require 'mkmatter/cli/descriptions'
4
5
  require 'mkmatter/cli/methods'
@@ -10,7 +11,7 @@ module Mkmatter
10
11
  # Generate 'New' Content
11
12
  class NewContent < Thor
12
13
  include Thor::Actions
13
- HILINE = HighLine.new($stdin, $stderr, 80)
14
+ HILINE = HighLine.new($stdin, $stderr, 40)
14
15
  option :publish, :type => :boolean
15
16
  option :file, :type => :boolean
16
17
  desc 'page [options]', 'make front matter (and possibly content) for a jekyll page'
@@ -18,9 +19,8 @@ module Mkmatter
18
19
 
19
20
  def page
20
21
  if options[:file]
21
-
22
22
  if Mkmatter::Methods.check_if_jekyll
23
- @questions = Mkmatter::Questions::Page.new(HighLine.new($stdin, $stderr, 80)).ask
23
+ @questions = Mkmatter::Questions::Page.new(HILINE).ask
24
24
  answers = Mkmatter::Answers.new(@questions, options.fetch(:publish, nil))
25
25
  filename = answers.title.to_slug + '.' + answers.file_format.downcase
26
26
  path = Pathname("./#{filename}").realdirpath
@@ -46,7 +46,7 @@ module Mkmatter
46
46
  fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
47
47
  fd.puts '---'
48
48
  end
49
- Mkmatter::Methods.launch_editor(path)
49
+ Mkmatter::Methods.launch_editor(options[:editor], path)
50
50
  else
51
51
  puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
52
52
  exit 1
@@ -71,7 +71,7 @@ module Mkmatter
71
71
  if options[:draft] and options[:file]
72
72
 
73
73
  if Mkmatter::Methods.check_if_jekyll
74
- @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask
74
+ @questions = Mkmatter::Questions::Post.new(HILINE).ask
75
75
  answers = Mkmatter::Answers.new(@questions, options[:publish])
76
76
  file_folder = '_drafts'
77
77
  filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join
@@ -99,7 +99,7 @@ module Mkmatter
99
99
  fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
100
100
  fd.puts '---'
101
101
  end
102
- Mkmatter::Methods.launch_editor(path)
102
+ Mkmatter::Methods.launch_editor(options[:editor], path)
103
103
  else
104
104
  puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
105
105
  exit 1
@@ -107,7 +107,7 @@ module Mkmatter
107
107
  elsif options[:file] and options[:draft].nil? or options[:draft] == false
108
108
 
109
109
  if Mkmatter::Methods.check_if_jekyll
110
- @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask
110
+ @questions = Mkmatter::Questions::Post.new(HILINE).ask
111
111
  answers = Mkmatter::Answers.new(@questions, options[:publish])
112
112
  file_folder = '_posts'
113
113
  filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join('')
@@ -137,21 +137,19 @@ module Mkmatter
137
137
  fd.puts '---'
138
138
  end
139
139
 
140
- Mkmatter::Methods.launch_editor(path)
140
+ Mkmatter::Methods.launch_editor(options[:editor], path)
141
141
  else
142
142
  puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
143
143
  exit 1
144
144
  end
145
-
146
145
  elsif options[:draft].nil? and options[:file].nil?
147
- @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask
146
+ @questions = Mkmatter::Questions::Post.new(HILINE).ask
148
147
  answers = Mkmatter::Answers.new(@questions, options[:publish])
149
148
  puts ''
150
149
  puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
151
150
  puts '---'
152
151
 
153
152
  end
154
-
155
153
  end
156
154
  end
157
155
  end
@@ -8,7 +8,7 @@ module Mkmatter
8
8
  class Tags < Thor
9
9
  include Thor::Actions
10
10
  HILINE = HighLine.new($stdin, $stderr, 80)
11
-
11
+
12
12
  desc 'find [options] TYPE', 'find content of type TYPE'
13
13
  # @param [String] type Type of content
14
14
  def find(type)
@@ -17,7 +17,7 @@ module Mkmatter
17
17
  table.title = 'Tags'
18
18
  table.style.all_separators = true
19
19
  table.headings = ["#{HILINE.color('Path from Jekyll Root', :bold)}", "#{HILINE.color('Tags', :bold)}"]
20
-
20
+
21
21
  front_matter = Mkmatter::Methods.find_front_matter(type, 'tags')
22
22
  front_matter.each do |path, tags|
23
23
  path = path.gsub(/#{Mkmatter::Methods.get_jekyll_root}(\/.*)/, '\1')
@@ -29,29 +29,48 @@ module Mkmatter
29
29
  $stderr.puts "#{HILINE.color('Error', :red, :bold)}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
30
30
  end
31
31
  end
32
+
32
33
  desc 'new [options] TAG', 'create a new tag'
33
34
  # @param [String] tag Tag Name
34
35
  def new_tag(tag)
35
36
  if Mkmatter::Methods.check_if_jekyll
36
-
37
+
37
38
  else
38
39
  $stderr.puts "#{HILINE.color('Error', :red, :bold)}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
39
40
  end
40
41
  end
42
+
41
43
  desc 'gen [options]', 'generate tag files'
42
44
  option(:'tag-index', type: :string, default: nil, desc: "configures whether generation of tag files will give them a layout file for a tag index, if you don't want generation to give layouts, omit --tag-index", aliases: %w(-i))
45
+ option(:'dry-run', type: :boolean, default: false, desc: 'Performs a dry run and prints out what it was going to do')
46
+
43
47
  def gen # only used for posts
44
- if Mkmatter::Tags.has_tag_folder?
45
- front_matter = Mkmatter::Methods.find_front_matter('post', 'tags')
46
- tags = []
47
- front_matter.each do |key, value|
48
- tags << value
48
+ if options[:'dry-run']
49
+ if Mkmatter::Tags.has_tag_folder?
50
+ front_matter = Mkmatter::Methods.find_front_matter('post', 'tags')
51
+ tags = []
52
+ front_matter.each do |key, value|
53
+ tags << value
54
+ end
55
+ all_tags = tags.flatten.sort.uniq
56
+ Mkmatter::Tags.dry_gen all_tags
57
+ else
58
+ HILINE.say "<% color('Error', :red, :bold) %>: No tag folder"
49
59
  end
50
- all_tags = tags.flatten.sort.uniq
51
- all_tags
52
60
  else
53
- $stderr.puts "#{HILINE.color('Error', :red, :bold)}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
61
+ if Mkmatter::Tags.has_tag_folder?
62
+ front_matter = Mkmatter::Methods.find_front_matter('post', 'tags')
63
+ tags = []
64
+ front_matter.each do |key, value|
65
+ tags << value
66
+ end
67
+ all_tags = tags.flatten.sort.uniq
68
+ Mkmatter::Tags.gen_post_tags all_tags
69
+ else
70
+ $stderr.puts "#{HILINE.color('Error', :red, :bold)}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
71
+ end
54
72
  end
73
+
55
74
  end
56
75
  end
57
76
  end
@@ -1,7 +1,11 @@
1
1
  require 'mkmatter/cli/methods'
2
-
2
+ require 'thor'
3
+ require 'front_matter_parser'
4
+ require 'active_support/inflector'
3
5
  module Mkmatter
4
- class Tags
6
+ class Tags < Thor
7
+ include Thor::Actions
8
+ HILINE = HighLine.new($stdin, $stderr, 80)
5
9
 
6
10
  def Tags.has_tag_folder?
7
11
  if Mkmatter::Methods.check_if_jekyll
@@ -15,51 +19,60 @@ module Mkmatter
15
19
  end
16
20
  end
17
21
 
18
- def Tags.gen_post_tags
22
+ # @param [Array] tags Array of tags to generate pages for
23
+ # @return [Boolean] whether generation was successful
24
+ def Tags.dry_gen(tags)
19
25
  if Mkmatter::Methods.check_if_jekyll
20
26
  if Tags.has_tag_folder?
21
-
27
+ tags.each do |tag|
28
+ file = "#{Mkmatter::Methods.get_jekyll_root}/tag/#{tag}.md"
29
+ puts <<-PUTS.strip_heredoc
30
+ ---
31
+
32
+ title: #{tag.titleize}
33
+ tag: #{tag}
34
+ ---
35
+ PUTS
36
+ end
22
37
  else
23
38
  end
24
39
  end
25
40
  end
26
-
27
- # @param [String] type Gets tags from content type TYPE
28
- def Tags.get_tags_of_type(type)
29
- unless type =~ /^(post|page)$/
30
- raise ArgumentError
31
- end
32
- yaml_loader = ->(string) {YAML.load(string)}
33
- files = {}
34
- html_front_matter = []
35
- md_front_matter = []
36
- front_matter = {}
37
- case type
38
- when 'page'
39
- Find.find(Methods.get_jekyll_root.to_s) do |path|
40
- Find.prune if path =~ /(_includes|_layouts|_docs|_site)/ # don't include layouts, includes, site, docs
41
- Find.prune if path =~ /(_posts)/ # don't include our own posts either
42
- Find.prune if path =~ /(vendor\/bundle)/ # don't include vendor/
43
- Find.prune if path =~ /(\/tag\/)/ # don't include our own tags
44
- html_front_matter << path if path =~ /.*\.html$/
45
- md_front_matter << path if path =~ /.*\.md$/
46
- end
47
-
48
- when 'post'
49
- Find.find(Pathname(Methods.get_jekyll_root).join('_posts').to_path) do |path|
50
- html_front_matter << path if path =~ /.*\.html$/
51
- md_front_matter << path if path =~ /.*\.md$/
41
+
42
+ def Tags.gen_post_tags(tags)
43
+ if Mkmatter::Methods.check_if_jekyll
44
+ if Tags.has_tag_folder?
45
+ tags.each do |tag|
46
+ file = "#{Mkmatter::Methods.get_jekyll_root}/tag/#{tag}.md"
47
+ self.new.create_file file do
48
+ <<-PUTS
49
+ ---
50
+ #{tag_index unless tag_index.nil?}
51
+ title: #{tag.titleize}
52
+ tag: #{tag}
53
+ ---
54
+ PUTS
55
+ end
52
56
  end
53
57
  else
54
- # noop
55
- end
56
- files['html'] = html_front_matter
57
- files['md'] = md_front_matter
58
- files.each do |ftype, array|
59
- array.each do |ele|
60
- front_matter[ele] = FrontMatterParser::Parser.parse_file(ele, syntax_parser: :md, loader: yaml_loader)[key]
61
58
  end
62
59
  end
60
+ end
61
+
62
+ def Tags.get_tags
63
+ yaml_loader = ->(string) {YAML.load(string)}
64
+ files = []
65
+ front_matter = {}
66
+
67
+ Find.find(Pathname(Methods.get_jekyll_root).join('_posts').to_path) do |path|
68
+ files << path if path =~ /.*(\.html|\.md)$/
69
+ end
70
+ files.each do |ele|
71
+ yaml = FrontMatterParser::Parser.parse_file(ele, syntax_parser: :md, loader: yaml_loader).front_matter
72
+ front_matter[ele] = yaml['tags'] if yaml['tags']
73
+ front_matter[ele] = yaml['tag'] if yaml['tag']
74
+
75
+ end
63
76
  front_matter.select! {|k, v| !v.nil?}
64
77
  front_matter
65
78
  end
data/lib/mkmatter/cli.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'mkmatter/cli/app'
2
2
  require 'mkmatter/cli/descriptions'
3
3
  require 'mkmatter/cli/methods'
4
- require 'mkmatter/cli/runner'
5
- require 'mkmatter/cli/subs'
4
+ require 'mkmatter/cli/subs'
5
+ require 'mkmatter/cli/runner'
@@ -8,7 +8,7 @@ module Mkmatter
8
8
  # @return [String]
9
9
  def get_title(hl)
10
10
  title = hl.ask 'Title: '
11
- if hl.agree("Would you like it 'titleized' (Title instead of title)?", true)
11
+ if hl.agree("Would you like it 'titleized' (Title instead of title)? ", true)
12
12
  title.titleize
13
13
  else
14
14
  title
@@ -18,13 +18,13 @@ module Mkmatter
18
18
  # @param [HighLine] hl A highline context
19
19
  # @return [String]
20
20
  def get_tags(hl)
21
- hl.ask('Tags? (space separated list) ', -> (str) {str.split(' ')})
21
+ hl.ask 'Tags? (this would be a comma separated list.) ', -> (str) {str.split(',')}
22
22
  end
23
23
 
24
24
  # @param [HighLine] hl A highline context
25
25
  # @return [String]
26
26
  def get_categories(hl)
27
- hl.ask('Categories? (space separated list) ', -> (str) {str.split(' ')})
27
+ hl.ask 'Categories? (space separated list) ', -> (str) {str.split(' ')}
28
28
  end
29
29
 
30
30
  # @param [HighLine] hl A highline context
@@ -42,10 +42,9 @@ module Mkmatter
42
42
  m.choice :neither
43
43
  m.prompt = '? '
44
44
  end
45
- case timezone
46
- when :neither
45
+ case
46
+ when timezone == :neither
47
47
  custom = hl.ask('Other Time Zone: ', String)
48
- else
49
48
  end
50
49
  if custom
51
50
  hl.say('Checking TimeZone Validity')
@@ -71,11 +70,5 @@ module Mkmatter
71
70
  menu.prompt = '? '
72
71
  end
73
72
  end
74
- def get_keywords(hl)
75
- hl.ask("Meta Keywords? (example: 'space 'spaced', comma separated, page keywords, goes here') ")
76
- end
77
- def get_description(hl)
78
- hl.ask("Meta Description? (example: 'This page is a bunch of right nonsense.' ")
79
- end
80
73
  end
81
74
  end
@@ -1,3 +1,3 @@
1
1
  module Mkmatter
2
- VERSION = '3.0.43'
2
+ VERSION = '3.0.44'
3
3
  end
data/mkmatter.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  end
30
30
 
31
31
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
32
- f.match(%r{^(test|spec|features)/})
32
+ f.match(%r{^(test)/})
33
33
  end
34
34
  spec.required_ruby_version = '~> 2'
35
35
  spec.bindir = 'bin'
@@ -40,14 +40,19 @@ Gem::Specification.new do |spec|
40
40
  spec.add_runtime_dependency 'activesupport', '~> 5.1'
41
41
  spec.add_runtime_dependency 'git', '~> 1.3'
42
42
  spec.add_runtime_dependency 'slugity', '~> 1.1'
43
- spec.add_runtime_dependency 'thor', '~> 0.20.0'
43
+ spec.add_runtime_dependency 'thor', '~> 0.20'
44
44
  spec.add_runtime_dependency 'terminal-table', '~> 1.8'
45
45
  spec.add_runtime_dependency 'os', '~> 1.0'
46
+ spec.add_runtime_dependency 'front_matter_parser', '~> 0.1'
47
+ spec.add_runtime_dependency 'rake', '~> 10.0'
48
+ spec.add_runtime_dependency 'micro_install', '~> 0.1.0'
46
49
  spec.add_development_dependency 'bundler', '~> 1.16'
47
- spec.add_development_dependency 'rake', '~> 10.0'
48
- spec.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
49
- spec.add_development_dependency 'rspec-core', '~> 3.7', '>= 3.7.0'
50
- spec.add_development_dependency 'rspec-mocks', '~> 3.7', '>= 3.7.0'
51
- spec.add_development_dependency 'rspec-expectations', '~> 3.7', '>= 3.7.0'
52
-
50
+ spec.add_development_dependency 'minitest', '~> 5'
51
+ spec.add_development_dependency 'minitest-reporters', '~> 1.1'
52
+ spec.post_install_message = [
53
+ "Thanks for installing 'mkmatter', It means a lot to me.",
54
+ "If you'd like to install 'micro', a text editor bundled with 'mkmatter'.",
55
+ "Then just run 'bundle exec micro-install' or 'micro-install',",
56
+ "depending on how you installed 'mkmatter'."
57
+ ].join("\n")
53
58
  end