jekyll-page-boilerplate 4.4.1 → 5.0.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: bb95ce2295263ff136c816e08bbeccc5ace0b1aaa55e585f9450387312408729
4
- data.tar.gz: 82419e9b79e8117d1df87abaa13f2e37c6e08b90ff48ffe27ce8c4b3f00d1577
3
+ metadata.gz: 1a209c84ac5eea1c4cf34fd0f5918b29d7e946043b3293309d3d805a77a47d02
4
+ data.tar.gz: dfa1c7e2fd260b72d3cdbe9ca4f197239341ae3cc4eaaf6c8393a9ac01d507a6
5
5
  SHA512:
6
- metadata.gz: 7059ff250593c82acc0e0bb0f258f80d8d131efc6fcd842acc2717b711d2876271eb99badb2b13b0593b327935a787d9d13dc7ea3a72b9c2feebcc39eb7a050c
7
- data.tar.gz: b736fbaa7aea45219699902443f61ba95ebebf2cad9cb2a2957328e530f4132d9f1665076fab9664c78e76a4c0eb256b669b24f866337b11163d0c0505083448
6
+ metadata.gz: 6615e6621fe7cdc7c240332b77a04aa26af0f2050df52e475f2dc655ca8501654d37f7c98cce3170656fcc20479bfa55e564d7f3bdb78539224abd4b0c926b7e
7
+ data.tar.gz: 4a1ec868cd8954916586c1d94460066f0d66d2c74b5ce0bfa3e86f001debb19a1a9d69cf7282b7c129fd2c1d3533a1d3eaf77b47374cdbc5a66df41902fe1264
@@ -14,7 +14,7 @@ A boilerplate is a markdown file you place under the `_boilerplates` folder to g
14
14
  author: John Doe
15
15
 
16
16
 
17
- `$ boilerplate post -T "Another one about pottery"` would create a new file `_posts/yyyy-mm-dd-another-one-about-pottery.markdown`
17
+ `$ boilerplate post "Another one about pottery"` would create a new file `_posts/yyyy-mm-dd-another-one-about-pottery.markdown`
18
18
 
19
19
  ---
20
20
  title: Another one about pottery
@@ -27,7 +27,11 @@ module JekyllPageBoilerplate::Msg
27
27
  begin
28
28
  self.info block.call
29
29
  rescue => e
30
- self.error fatal: e.message
30
+ if e.kind_of?(JekyllPageBoilerplate::Error)
31
+ self.error fatal: e.message
32
+ else
33
+ self.error fatal: e.message, full: e.full_message
34
+ end
31
35
  end
32
36
  end
33
37
 
@@ -14,13 +14,13 @@ class JekyllPageBoilerplate::Page
14
14
 
15
15
  attr_reader :tags
16
16
 
17
- def self.run boilerplate, *options
18
- page = self.new(boilerplate, *options)
17
+ def self.run boilerplate, custom_args, options
18
+ page = self.new(boilerplate, custom_args, options)
19
19
  page.create
20
20
  return "Created "+ File.join(page.tags['path'], page.tags['file'])
21
21
  end
22
22
 
23
- def initialize boilerplate, *options, **params
23
+ def initialize boilerplate, custom_args, options
24
24
  plate_path = get_boilerplate_path(boilerplate)
25
25
  abort_unless_file_exists( plate_path )
26
26
 
@@ -32,8 +32,8 @@ class JekyllPageBoilerplate::Page
32
32
  @tags = JekyllPageBoilerplate::Tags.new(
33
33
  defaults(plate_path),
34
34
  get_header_config(parsed_file['head']),
35
- *options,
36
- params
35
+ options,
36
+ parse_custom_args(custom_args)
37
37
  )
38
38
  @tags[:file] = '{{ date }}-{{ slug }}{{ suffix }}' if @tags.timestamp
39
39
  @tags.fill(:slug, :file, safe: true)
@@ -87,6 +87,10 @@ class JekyllPageBoilerplate::Page
87
87
  end
88
88
  end
89
89
 
90
+ def parse_custom_args args
91
+ Hash[args.map {|x| x.match /(\w+)=['"]{0,1}([^"']+)['"]{0,1}/}.compact.map {|x| x.captures }]
92
+ end
93
+
90
94
  def get_header_config head
91
95
  return YAML.load(head.match(READ_CONFIG_REGEX).to_s)['_boilerplate']
92
96
  end
@@ -96,18 +100,18 @@ class JekyllPageBoilerplate::Page
96
100
  end
97
101
 
98
102
  def get_boilerplate_path plate_name
99
- return Dir.glob( "#{File.join(BOILERPLATES_PATH, plate_name)}*" ).first.to_s
103
+ return Dir.glob( "#{File.join(BOILERPLATES_PATH, plate_name.to_s)}*" ).first.to_s
100
104
  end
101
105
 
102
106
  def abort_if_file_exists(file_path)
103
107
  if File.exist?(file_path)
104
- raise "#{file_path} already exists!"
108
+ raise JekyllPageBoilerplate::Error.new, "#{file_path} already exists!"
105
109
  end
106
110
  end
107
111
 
108
112
  def abort_unless_file_exists(file_path)
109
113
  unless File.exist?(file_path)
110
- raise "The file `#{file_path}` does not exist!"
114
+ raise JekyllPageBoilerplate::Error.new, "The file `#{file_path}` does not exist!"
111
115
  end
112
116
  end
113
117
 
@@ -67,4 +67,4 @@ class JekyllPageBoilerplate::Tags
67
67
  def method_missing key
68
68
  @tags[key.to_s]
69
69
  end
70
- end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module JekyllPageBoilerplate
2
- VERSION = "4.4.1"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -25,9 +25,9 @@ module JekyllPageBoilerplate
25
25
  Msg.file 'description.md'
26
26
  end
27
27
 
28
- def self.page boilerplate_name, options
28
+ def self.page boilerplate_name, args, options
29
29
  Msg.try_and_report do
30
- Page.run(boilerplate_name, options)
30
+ Page.run(boilerplate_name, args, options)
31
31
  end
32
32
  end
33
33
 
@@ -1,62 +1,64 @@
1
- require "bales"
1
+ require 'thor'
2
2
  require 'jekyll_page_boilerplate'
3
3
 
4
- class JekyllPageBoilerplate::Application < Bales::Application
5
- version JekyllPageBoilerplate::VERSION
6
- description JekyllPageBoilerplate::Msg.description
7
- summary JekyllPageBoilerplate::Msg::SUMMARY
8
- # `boilerplate <page>`
9
- option :title, type: String, long_form: '--title', short_form: '-T',
10
- description: "`path/<title>.md`"
11
- option :path, type: String, long_form: '--path', short_form: '-p',
12
- description: "`<path>/title.md`"
13
- option :slug, type: String, long_form: '--slug', short_form: '-u',
14
- description: "`path/<slug-template>.md` `{{title}}-{{date}}`"
15
- option :timestamp, type: TrueClass, long_form: '--timestamp', short_form: '-s',
16
- description: "`path/<time.now>-title.md`"
17
- option :suffix, type: String, long_form: '--suffix', short_form: '-x',
18
- description: "`path/title.<md, markdown, txt>`"
19
-
20
- action do |plate, *custom, title: nil, slug: nil, path: nil, timestamp: nil, suffix: nil|
21
- custom = Hash[custom.map {|v| v.split('=')}]
22
- JekyllPageBoilerplate.page plate, custom.merge({
23
- title: title, path: path, slug: slug,
24
- suffix: suffix, timestamp: timestamp
25
- })
4
+
5
+
6
+ class JekyllPageBoilerplate::Application < Thor
7
+
8
+ SHARED_OPTIONS = {
9
+ title: { type: :string, aliases: [:t], desc: "`path/<title>.md` `'Foo Bar' > foo-bar.md`" },
10
+ path: { type: :string, aliases: [:p], desc: "`<path>/title.md`" },
11
+ slug: { type: :string, aliases: [:u], desc: "`path/<slug-template>.md` `{{title}}-{{date}}`" },
12
+ timestamp: { type: :boolean, aliases: [:s], desc: "`path/<time.now>-title.md`" },
13
+ suffix: { type: :string, aliases: [:x], desc: "`path/title.<md, markdown, txt>`" }
14
+ # TODO: rename suffix to ext ^^^
15
+ }
16
+
17
+ desc "version", "Print the current version."
18
+ def version
19
+ puts JekyllPageBoilerplate::VERSION.to_s
26
20
  end
27
21
 
28
- # `boilerplate help`
29
- command 'help', parent: Bales::Command::Help
22
+ desc "init", "Creates an example boilerplate."
23
+ def init
24
+ puts JekyllPageBoilerplate.init
25
+ end
30
26
 
31
- # `boilerplate init`
32
- command 'init' do
33
- summary "Creates an example boilerplate."
34
- action do
35
- JekyllPageBoilerplate.init
36
- end
27
+ desc "list", "List all the boilerplates."
28
+ def list
29
+ JekyllPageBoilerplate.list
37
30
  end
38
-
39
- # `boilerplate list`
40
- command 'list' do
41
- summary "List all the boilerplates"
42
- action do
43
- JekyllPageBoilerplate.list
44
- end
31
+
32
+ desc "create BOILERPLATE TITLE [CUSTOM] (--options)", "Generates a new file from a boilerplate."
33
+ SHARED_OPTIONS.each do |name, opt_args|
34
+ option name, **opt_args
35
+ end
36
+ def create plate, title = nil, *args
37
+ _options = options.dup.transform_values(&:dup) || {}
38
+ _options[:title] ||= title if title
39
+ JekyllPageBoilerplate.page plate, args, _options
40
+ end
41
+
42
+ desc "readme", "Print out the readme"
43
+ def readme
44
+ JekyllPageBoilerplate.readme
45
45
  end
46
-
47
46
 
48
- def self.run(*args, **opts)
49
- begin
50
- super
51
- rescue => e
52
- JekyllPageBoilerplate.readme
47
+ Dir['_boilerplates/*'].each do |file|
48
+ cmd = File.basename(file, '.*').to_sym
49
+ desc "#{cmd} TITLE [CUSTOM] (--options)", "Alias for `bplate create #{cmd} ...`"
50
+ SHARED_OPTIONS.each do |name, opt_args|
51
+ option name, **opt_args
52
+ end
53
+ define_method cmd do |title = nil, *args|
54
+ _options = options.dup.transform_values(&:dup) || {}
55
+ _options[:title] ||= title if title
56
+ JekyllPageBoilerplate.page cmd, args, _options
53
57
  end
54
58
  end
55
59
 
60
+ default_task :readme
56
61
  end
57
62
 
58
- JekyllPageBoilerplate::Application.parse_and_run
63
+ JekyllPageBoilerplate::Application.start(ARGV)
59
64
 
60
-
61
-
62
-
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-page-boilerplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Ferney
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-27 00:00:00.000000000 Z
11
+ date: 2023-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bales
14
+ name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.3
19
+ version: '1.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: 0.1.3
29
+ version: '1.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: stringex
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -102,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
108
  - !ruby/object:Gem::Version
103
109
  version: '0'
104
110
  requirements: []
105
- rubygems_version: 3.2.3
111
+ rubygems_version: 3.4.1
106
112
  signing_key:
107
113
  specification_version: 4
108
114
  summary: A jekyll plugin that allows you to create new pages or posts from a boilerplate