mkmatter 3.0.26

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.
@@ -0,0 +1,159 @@
1
+ require 'highline'
2
+
3
+ require 'mkmatter/cli/descriptions'
4
+ require 'mkmatter/cli/methods'
5
+ require 'mkmatter/questions'
6
+ require 'mkmatter/answers'
7
+ module Mkmatter
8
+ module App
9
+ module Classes
10
+ # Generate 'New' Content
11
+ class NewContent < Thor
12
+ include Thor::Actions
13
+ HILINE = HighLine.new($stdin, $stderr, 80)
14
+ option :publish, :type => :boolean
15
+ option :file, :type => :boolean
16
+ desc 'page [options]', 'make front matter (and possibly content) for a jekyll page'
17
+ long_desc Mkmatter::App::Descriptions::New::PAGE
18
+
19
+ def page
20
+ if options[:file]
21
+
22
+ if Mkmatter::Methods.check_if_jekyll
23
+ @questions = Mkmatter::Questions::Page.new(HighLine.new($stdin, $stderr, 80)).ask
24
+ answers = Mkmatter::Answers.new(@questions, options.fetch(:publish, nil))
25
+ filename = answers.title.to_slug + '.' + answers.file_format.downcase
26
+ path = Pathname("./#{filename}").realdirpath
27
+ if HILINE.agree('Would you like to put this page into a subdirectory?', true)
28
+ HILINE.say("What path? (directories will be created if they don't exist) ")
29
+ HILINE.say("Don't use a path starting with a slash, just put a relative path.")
30
+ HILINE.say('good => path/to/dir ‖ bad => /root/paths/are/bad/mmkay')
31
+ folder = HILINE.ask('? ') do |q|
32
+ q.confirm = true
33
+ q.default = '.'
34
+ q.validate = /^[^\/].*$/
35
+ end
36
+ folder = Pathname(folder)
37
+ begin
38
+ FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
39
+ rescue Errno::EEXIST
40
+ HILINE.say("<%= color('Error', :red, :bold) %>:Insufficient Permissions")
41
+ exit 1
42
+ end
43
+ path = Pathname(folder).realdirpath.join(filename)
44
+ end
45
+ File.open(path.to_path, 'a') do |fd|
46
+ fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
47
+ fd.puts '---'
48
+ end
49
+ Mkmatter::Methods.launch_editor(path)
50
+ else
51
+ puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
52
+ exit 1
53
+ end
54
+ else
55
+ answers = Mkmatter::Answers.new(@questions, options.fetch(:publish, nil))
56
+ puts ''
57
+ puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
58
+ puts '---'
59
+ end
60
+ end
61
+
62
+
63
+ option :publish, :type => :boolean
64
+ option :file, :type => :boolean
65
+ option :draft, :type => :boolean
66
+ desc 'post [options]', 'make front matter (and possibly content) for a jekyll post'
67
+ long_desc Mkmatter::App::Descriptions::New::POST
68
+
69
+ def post
70
+
71
+ if options[:draft] and options[:file]
72
+
73
+ if Mkmatter::Methods.check_if_jekyll
74
+ @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask
75
+ answers = Mkmatter::Answers.new(@questions, options[:publish])
76
+ file_folder = '_drafts'
77
+ filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join
78
+
79
+ path = Pathname("./#{file_folder}/#{filename}").realdirpath
80
+ if HILINE.agree('Would you like to put this page into a subdirectory?', true)
81
+ HILINE.say("What path? (directories will be created if they don't exist)")
82
+ HILINE.say("Don't use a path starting with a slash, just put a relative path.")
83
+ HILINE.say('<%= color(\'Good\', :green, :bold) %>: path/to/dir ‖ <%= color(\'Bad\', :red, :bold) %>: /root/paths/are/bad/mmkay')
84
+ folder = HILINE.ask('? ') do |q|
85
+ q.confirm = true
86
+ q.default = '.'
87
+ q.validate = /^[^\/].*$/
88
+ end
89
+ folder = Pathname(folder)
90
+ begin
91
+ FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
92
+ rescue Errno::EEXIST
93
+ HILINE.say("<%= color('Error', :red, :bold) %>:Insufficient Permissions")
94
+ exit 1
95
+ end
96
+ path = Pathname(folder).realdirpath.join(filename)
97
+ end
98
+ File.open(path.to_path, 'a') do |fd|
99
+ fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
100
+ fd.puts '---'
101
+ end
102
+ Mkmatter::Methods.launch_editor(path)
103
+ else
104
+ puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
105
+ exit 1
106
+ end
107
+ elsif options[:file] and options[:draft].nil? or options[:draft] == false
108
+
109
+ if Mkmatter::Methods.check_if_jekyll
110
+ @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask
111
+ answers = Mkmatter::Answers.new(@questions, options[:publish])
112
+ file_folder = '_posts'
113
+ filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join('')
114
+ path = Pathname("./#{file_folder}/#{filename}").realdirpath
115
+ if HILINE.agree('Would you like to put this post into a subdirectory?', true)
116
+ HILINE.say('What path?')
117
+ HILINE.say('----------------')
118
+ HILINE.say("Don't use a path starting with a slash, just put a relative path.")
119
+ HILINE.say("If you enter a path you don't like, you will have manually remove it if you confirm it.")
120
+ HILINE.say('<%= color(\'Good\', :green, :bold) %>: path/to/dir ‖ <%= color(\'Bad\', :red, :bold) %>: /root/paths/are/bad/mmkay')
121
+ folder = HILINE.ask('? ') do |q|
122
+ q.confirm = true
123
+ q.default = '.'
124
+ q.validate = /^[^\/].*$/
125
+ end
126
+ folder = Pathname("#{file_folder}/#{folder}")
127
+ begin
128
+ FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
129
+ rescue Errno::EEXIST
130
+ HILINE.say("<%= color('Error', :red, :bold) %>:Insufficient Permissions")
131
+ exit 1
132
+ end
133
+ path = Pathname(folder).realdirpath.join(filename)
134
+ end
135
+ File.open(path.to_path, 'a') do |fd|
136
+ fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
137
+ fd.puts '---'
138
+ end
139
+
140
+ Mkmatter::Methods.launch_editor(path)
141
+ else
142
+ puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
143
+ exit 1
144
+ end
145
+
146
+ elsif options[:draft].nil? and options[:file].nil?
147
+ @questions = Mkmatter::Questions::Post.new(HighLine.new($stdin, $stderr, 80)).ask
148
+ answers = Mkmatter::Answers.new(@questions, options[:publish])
149
+ puts ''
150
+ puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
151
+ puts '---'
152
+
153
+ end
154
+
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,59 @@
1
+ require 'thor'
2
+ require 'highline'
3
+ require 'mkmatter/cli/methods'
4
+ require 'mkmatter/cli/tags'
5
+ module Mkmatter
6
+ module App
7
+ module Classes
8
+ class Tags < Thor
9
+ include Thor::Actions
10
+ HILINE = HighLine.new($stdin, $stderr, 80)
11
+
12
+ desc 'find [options] TYPE', 'find content of type TYPE'
13
+ # @param [String] type Type of content
14
+ def find(type)
15
+ if Mkmatter::Methods.check_if_jekyll
16
+ table = Terminal::Table.new
17
+ table.title = 'Tags'
18
+ table.style.all_separators = true
19
+ table.headings = ["#{HILINE.color('Path from Jekyll Root', :bold)}", "#{HILINE.color('Tags', :bold)}"]
20
+
21
+ front_matter = Mkmatter::Methods.find_front_matter(type, 'tags')
22
+ front_matter.each do |path, tags|
23
+ path = path.gsub(/#{Mkmatter::Methods.get_jekyll_root}(\/.*)/, '\1')
24
+ table.add_row([path, "#{tags.join("\n")}"])
25
+ end
26
+ table.align_column(1, :right)
27
+ puts table
28
+ else
29
+ $stderr.puts "#{HILINE.color('Error', :red, :bold)}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
30
+ end
31
+ end
32
+ desc 'new [options] TAG', 'create a new tag'
33
+ # @param [String] tag Tag Name
34
+ def new_tag(tag)
35
+ if Mkmatter::Methods.check_if_jekyll
36
+
37
+ else
38
+ $stderr.puts "#{HILINE.color('Error', :red, :bold)}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
39
+ end
40
+ end
41
+ desc 'gen [options]', 'generate tag files'
42
+ 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))
43
+ 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
49
+ end
50
+ all_tags = tags.flatten.sort.uniq
51
+ all_tags
52
+ else
53
+ $stderr.puts "#{HILINE.color('Error', :red, :bold)}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,2 @@
1
+ require 'mkmatter/cli/subs/new'
2
+ require 'mkmatter/cli/subs/tags'
@@ -0,0 +1,67 @@
1
+ require 'mkmatter/cli/methods'
2
+
3
+ module Mkmatter
4
+ class Tags
5
+
6
+ def Tags.has_tag_folder?
7
+ if Mkmatter::Methods.check_if_jekyll
8
+ if Mkmatter::Methods.get_jekyll_root.join('tag/').exist?
9
+ true
10
+ else
11
+ false
12
+ end
13
+ else
14
+ false
15
+ end
16
+ end
17
+
18
+ def Tags.gen_post_tags
19
+ if Mkmatter::Methods.check_if_jekyll
20
+ if Tags.has_tag_folder?
21
+
22
+ else
23
+ end
24
+ end
25
+ 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$/
52
+ end
53
+ 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
+ end
62
+ end
63
+ front_matter.select! {|k, v| !v.nil?}
64
+ front_matter
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ require 'mkmatter/cli/app'
2
+ require 'mkmatter/cli/descriptions'
3
+ require 'mkmatter/cli/methods'
4
+ require 'mkmatter/cli/runner'
5
+ require 'mkmatter/cli/subs'
@@ -0,0 +1,81 @@
1
+ require 'highline'
2
+ require 'active_support/all'
3
+
4
+ module Mkmatter
5
+ module Common
6
+ attr_accessor :time_zone
7
+ # @param [HighLine] hl A highline context
8
+ # @return [String]
9
+ def get_title(hl)
10
+ title = hl.ask 'Title: '
11
+ if hl.agree("Would you like it 'titleized' (Title instead of title)?", true)
12
+ title.titleize
13
+ else
14
+ title
15
+ end
16
+ end
17
+
18
+ # @param [HighLine] hl A highline context
19
+ # @return [String]
20
+ def get_tags(hl)
21
+ hl.ask('Tags? (space separated list) ', -> (str) {str.split(' ')})
22
+ end
23
+
24
+ # @param [HighLine] hl A highline context
25
+ # @return [String]
26
+ def get_categories(hl)
27
+ hl.ask('Categories? (space separated list) ', -> (str) {str.split(' ')})
28
+ end
29
+
30
+ # @param [HighLine] hl A highline context
31
+ # @return [String]
32
+ def get_time_zone(hl)
33
+ custom = nil
34
+ timezone = hl.choose do |m|
35
+ m.header = 'Time Zone? (select by number)'
36
+ m.choice('Eastern Time (US & Canada)') do
37
+ return 'Eastern Time (US & Canada)'
38
+ end
39
+ m.choice('Central Time (US & Canada)') do
40
+ return 'Central Time (US & Canada)'
41
+ end
42
+ m.choice :neither
43
+ m.prompt = '? '
44
+ end
45
+ case timezone
46
+ when :neither
47
+ custom = hl.ask('Other Time Zone: ', String)
48
+ else
49
+ end
50
+ if custom
51
+ hl.say('Checking TimeZone Validity')
52
+ print '.'
53
+ sleep(0.05)
54
+ 5.times do
55
+ print '.'
56
+ sleep(0.05)
57
+ puts ''
58
+ TimeZone.find_tzinfo custom
59
+ end
60
+ custom
61
+ end
62
+ end
63
+
64
+ # @param [HighLine] hl A highline context
65
+ # @return [String]
66
+ def get_file_format(hl)
67
+ hl.choose do |menu|
68
+ menu.header = 'Choose whether you want HTML or Markdown (md)'
69
+ menu.choice 'html'
70
+ menu.choice 'md'
71
+ menu.prompt = '? '
72
+ end
73
+ 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
+ end
81
+ end
@@ -0,0 +1,22 @@
1
+ require 'mkmatter/version'
2
+ module Mkmatter
3
+ GEM_NAME = 'mkmatter'
4
+ NAME = GEM_NAME
5
+
6
+ #
7
+ # Gem Description
8
+ DESC = %q{A gem helps a user maintain a jekyll site source directory.}
9
+
10
+ #
11
+ # Gem Summary
12
+ SUMMARY = %q{Script facilitating easy content creation and generation for Jekyll Sites}
13
+ class GemInfo
14
+ def self.authors
15
+ ['Ken Spencer']
16
+ end
17
+
18
+ def self.email
19
+ 'me@iotaspencer.me'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,55 @@
1
+ require 'highline'
2
+ require 'mkmatter/common'
3
+ require 'ostruct'
4
+ module Mkmatter
5
+ module Questions
6
+
7
+ class Post
8
+ include Mkmatter::Common
9
+
10
+ attr :answers
11
+ attr :highline_context
12
+
13
+ # @!visibility private
14
+ # @param [HighLine] highline_context a highline context
15
+ def initialize(highline_context)
16
+ @highline_context = highline_context
17
+ @answers = OpenStruct.new
18
+ @answers[:layout] = 'post'
19
+
20
+ end
21
+
22
+ # @return [OpenStruct]
23
+ def ask
24
+ known_questions = self.methods.delete_if { |m| m.to_s !~ /^get_.*$/ }
25
+ known_questions.each do |m|
26
+ @answers[m.to_s.gsub(/^get_/, '')] = self.method(m).call(@highline_context)
27
+ end
28
+ @answers
29
+ end
30
+ end
31
+
32
+ class Page
33
+ include Mkmatter::Common
34
+ attr :answers
35
+ attr :highline_context
36
+
37
+
38
+ # @!visibility private
39
+ def initialize(highline_context)
40
+ @answers = OpenStruct.new
41
+ @answers[:layout] = 'page'
42
+ @highline_context = highline_context
43
+ end
44
+
45
+ # @return [OpenStruct]
46
+ def ask
47
+ known_questions = self.methods.delete_if { |m| m.to_s !~ /^get_.*$/ }
48
+ known_questions.each do |m|
49
+ @answers[m.to_s.gsub(/^get_/, '')] = self.method(m).call(@highline_context)
50
+ end
51
+ @answers
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Mkmatter
2
+ VERSION = '3.0.26'
3
+ end
data/lib/mkmatter.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'mkmatter/common'
2
+ require 'mkmatter/questions'
3
+ require 'mkmatter/answers'
4
+ require 'mkmatter/cli'
5
+ require 'mkmatter/version'
6
+
7
+ require 'json'
8
+ require 'yaml'
9
+
10
+ module Mkmatter
11
+
12
+ end
data/mkmatter.gemspec ADDED
@@ -0,0 +1,54 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'mkmatter/version'
4
+ require 'mkmatter/gem_info'
5
+ Gem::Specification.new do |spec|
6
+ spec.name = Mkmatter::GEM_NAME
7
+ spec.version = Mkmatter::VERSION
8
+ spec.authors = ['Ken Spencer']
9
+ spec.email = 'me@iotaspencer.me'
10
+ spec.summary = Mkmatter::SUMMARY
11
+ spec.description = Mkmatter::DESC
12
+ spec.homepage = 'https://iotaspencer.me/projects/mkmatter'
13
+ spec.license = 'MIT'
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata = {
19
+ 'github_repo' => 'https://github.com/IotaSpencer/mkmatter',
20
+ 'bug_tracker_uri' => 'https://github.com/IotaSpencer/mkmatter/issues',
21
+ 'documentation_uri' => 'https://rubydoc.info/gems/mkmatter',
22
+ 'homepage_uri' => 'https://iotaspencer.me/projects/mkmatter',
23
+ 'source_code_uri' => 'https://github.com/IotaSpencer/mkmatter',
24
+ 'wiki_uri' => 'https://github.com/IotaSpencer/mkmatter/wiki'
25
+ }
26
+ else
27
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
28
+ 'public gem pushes.'
29
+ end
30
+
31
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
32
+ f.match(%r{^(test|spec|features)/})
33
+ end
34
+ spec.required_ruby_version = '~> 2'
35
+ spec.bindir = 'bin'
36
+ spec.executables << 'mkmatter'
37
+ spec.require_paths = ['lib']
38
+
39
+ spec.add_runtime_dependency 'highline', '~> 1.7'
40
+ spec.add_runtime_dependency 'activesupport', '~> 5.1'
41
+ spec.add_runtime_dependency 'git', '~> 1.3'
42
+ spec.add_runtime_dependency 'slugity', '~> 1.1'
43
+ spec.add_runtime_dependency 'thor', '~> 0.20.0'
44
+ spec.add_runtime_dependency 'terminal-table', '~> 1.8'
45
+ spec.add_runtime_dependency 'os', '~> 1.0'
46
+ 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
+ spec.add_development_dependency 'rspec-support', '~> 3.7', '>= 3.7.0'
53
+
54
+ end