jekyll-page-boilerplate 4.2.1 → 4.4.1

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: c7fd37de6ea8e3b6858fa19bb1015d60513602ff83e99608c68467cf08c86775
4
- data.tar.gz: 7655f8d5b0afed1e3e86ffd2f5922f9c8ef1a433e4e1ec3c1c57f38e6704bcfd
3
+ metadata.gz: bb95ce2295263ff136c816e08bbeccc5ace0b1aaa55e585f9450387312408729
4
+ data.tar.gz: 82419e9b79e8117d1df87abaa13f2e37c6e08b90ff48ffe27ce8c4b3f00d1577
5
5
  SHA512:
6
- metadata.gz: bef77e3449efe9f265ea6255731ff8aea525fc93bba54c00445ba12dfa4c17055e00e61211184dfded8fbd946e72a10e971378f82f04b1521fcd8ad3350d88a5
7
- data.tar.gz: 476247fa459c5170f7490b1179837800a9ab0b961db857d3442da6e6a8a8ad462151ce82b3f3134b77bab4bba7225014def6af01311d8ca52538563eca9327c4
6
+ metadata.gz: 7059ff250593c82acc0e0bb0f258f80d8d131efc6fcd842acc2717b711d2876271eb99badb2b13b0593b327935a787d9d13dc7ea3a72b9c2feebcc39eb7a050c
7
+ data.tar.gz: b736fbaa7aea45219699902443f61ba95ebebf2cad9cb2a2957328e530f4132d9f1665076fab9664c78e76a4c0eb256b669b24f866337b11163d0c0505083448
@@ -2,10 +2,7 @@
2
2
  module JekyllPageBoilerplate
3
3
 
4
4
  class List
5
-
6
- SPACER = '\n'
7
- REMOVE_SUFFIX = /\.\w+(?=[\s\n\r$])/
8
-
5
+
9
6
  def self.run
10
7
  Dir.glob("_boilerplates/*").map do |f|
11
8
  File.basename(f, '.*')
@@ -6,9 +6,9 @@ A boilerplate is a markdown file you place under the `_boilerplates` folder to g
6
6
  _boilerplate: # boilerplate settings
7
7
  path: _posts # the path to create the new page under.
8
8
  timestamp: true # when true new post/pages will include the date in the filename.
9
- # a custom slug overrides the timestamp setting
10
- slug: '{{ title }}-{{ date }}{{ suffix }}'
11
- # slug is a template for the filename, it cant take the same tags everything else.
9
+ slug: '{{ title }}-{{ num }}'
10
+ # slug is a template for the filename, it cant take the same tags as everything else.
11
+ num: 0
12
12
  title: {{ boilerplate.title }} # tags like this will be replaced
13
13
  layout: post # everthing else will be copied to the new post.
14
14
  author: John Doe
@@ -27,6 +27,6 @@ Available Tags `{{ boilerplate.xxx }}`:
27
27
  - `.title`, `.name`
28
28
  - `.path`, `.file`, `.suffix`
29
29
  - `.time`, `.date`, `.timestamp`
30
- - `.random_url`
30
+ - `.random`
31
31
  - Custom tags you provide in the command `bplate post custom=1`
32
32
  - And anything you put under the `_boilerplate:` header
@@ -1,10 +1,10 @@
1
- A boilerplate is a markdown file you place under the `_boilerplates/<boilerplate>.md` folder to generate new pages for jekyll.
1
+ A boilerplate is a markdown file you place under the `_boilerplates/` folder to generate new pages for jekyll.
2
2
 
3
3
 
4
4
  It can automatically timestamp and title new pages.
5
5
 
6
6
 
7
- It will also replacing any `{{ boilerplate.xxx }}` tags with content. Available tags include `.time, .title, .date, .random_url`.
7
+ It will also replacing any `{{ boilerplate.xxx }}` tags with content. Available tags include `.time, .title, .date, .random`.
8
8
 
9
9
 
10
10
  You can also provide custom tags with `boilerplate post nav_order=1` > `{{ boilerplate.nav_order }}`.
@@ -2,31 +2,26 @@
2
2
  require 'yaml'
3
3
  require "stringex"
4
4
  require 'securerandom'
5
+ require 'fileutils'
5
6
 
6
7
  class JekyllPageBoilerplate::Page
7
8
 
8
9
  BOILERPLATES_PATH = '_boilerplates'
9
- FILE_DATE_FORMATE = '%Y-%m-%d'
10
10
  READ_CONFIG_REGEX = /[\r\n\s]{0,}^_boilerplate:(\s*^[\t ]{1,2}.+$)+[\r\s\n]{0,}(?![^\r\s\n])/
11
11
  READ_FILE_REGEX = /^-{3}\s*^(?<head>[\s\S]*)^-{3}\s^(?<body>[\s\S]*)/
12
12
  TAGS_REGEX = /\{{2}\s{0,}boilerplate\.([^\{\}\.\s]+)\s{0,}\}{2}/
13
- TAG_SLUG = /\{{2}\s{0,}([^\{\}\.\s]+)\s{0,}\}{2}/
14
13
 
15
14
 
15
+ attr_reader :tags
16
16
 
17
- attr_reader :config
18
-
19
- def self.run boilerplate, options
20
- page = self.new(boilerplate, options)
17
+ def self.run boilerplate, *options
18
+ page = self.new(boilerplate, *options)
21
19
  page.create
22
- return "Created %s/%s" % [page.config['path'], page.config['file']]
20
+ return "Created "+ File.join(page.tags['path'], page.tags['file'])
23
21
  end
24
22
 
25
- def initialize boilerplate, options
26
- options.compact!
27
- options.transform_keys!(&:to_s)
28
- plate_path = get_boilerplate_path(boilerplate).to_s
29
-
23
+ def initialize boilerplate, *options, **params
24
+ plate_path = get_boilerplate_path(boilerplate)
30
25
  abort_unless_file_exists( plate_path )
31
26
 
32
27
  parsed_file = {}
@@ -34,39 +29,46 @@ class JekyllPageBoilerplate::Page
34
29
  parsed_file = file.read.match(READ_FILE_REGEX).named_captures
35
30
  end
36
31
 
37
- @config = get_config(parsed_file['head']).merge(options)
38
- @config['suffix'] ||= plate_path[/\.\w+$/]
39
- @config['name'] ||= plate_path[/.*(?=\.)/] || plate_path
40
- unless @config['slug']
41
- if @config['timestamp']
42
- @config['slug'] = '{{ date }}-{{ title }}{{ suffix }}'
43
- else
44
- @config['slug'] = '{{ title }}{{ suffix }}'
45
- end
46
- end
32
+ @tags = JekyllPageBoilerplate::Tags.new(
33
+ defaults(plate_path),
34
+ get_header_config(parsed_file['head']),
35
+ *options,
36
+ params
37
+ )
38
+ @tags[:file] = '{{ date }}-{{ slug }}{{ suffix }}' if @tags.timestamp
39
+ @tags.fill(:slug, :file, safe: true)
40
+ @tags.fill(:path, safe: false)
41
+
47
42
  @head = get_head(parsed_file['head'])
48
- @body = get_body(parsed_file['body'])
43
+ @body = parsed_file['body']
49
44
  end
50
45
 
51
46
  def create
52
- @config['time'] ||= Time.now.to_s
53
- @config['date'] ||= Time.now.strftime(FILE_DATE_FORMATE)
54
-
55
- abort_unless_file_exists(@config['path'])
56
-
57
- scan_slug
58
- @config['file'] ||= @config['slug']
47
+ FileUtils.mkdir_p(@tags.path)
59
48
 
60
49
  scan_template :@body
61
50
  scan_template :@head
62
51
 
63
- create_new_page @config['file']
52
+ create_new_page
64
53
  end
65
-
54
+
66
55
  private
67
56
 
68
- def create_new_page filename
69
- new_file_path = File.join( @config['path'], filename )
57
+ def defaults(plate_path, timestamp: false)
58
+ basename = File.basename(plate_path, '.*')
59
+ {
60
+ suffix: plate_path[/\.\w+$/],
61
+ name: plate_path[/.*(?=\.)/] || plate_path,
62
+ basename: basename,
63
+ title: basename,
64
+ slug: '{{ title }}',
65
+ path: '_posts/',
66
+ file: '{{ slug }}{{ suffix }}',
67
+ }
68
+ end
69
+
70
+ def create_new_page
71
+ new_file_path = File.join( @tags.path, @tags.file )
70
72
 
71
73
  abort_if_file_exists(new_file_path)
72
74
 
@@ -81,43 +83,11 @@ class JekyllPageBoilerplate::Page
81
83
 
82
84
  def scan_template var
83
85
  instance_variable_get(var).scan(TAGS_REGEX).flatten.uniq.each do |tag|
84
- instance_variable_get(var).gsub! /\{{2}\s{0,}boilerplate\.#{tag}\s{0,}\}{2}/, get_tag_value(tag)
86
+ instance_variable_get(var).gsub! /\{{2}\s{0,}boilerplate\.#{tag}\s{0,}\}{2}/, @tags[tag].to_s
85
87
  end
86
88
  end
87
89
 
88
- def scan_slug
89
- @config['slug'].scan(TAG_SLUG).flatten.uniq do |tag|
90
- @config['slug'].gsub! /\{{2}\s{0,}#{tag}\s{0,}\}{2}/, get_tag_value(tag)
91
- end
92
- @config['slug'].gsub!(/[^0-9A-Za-z\.\-_]/, '-')
93
- @config['slug'].downcase!
94
- end
95
-
96
- def get_tag_value(key)
97
- return @config[key] if @config[key]
98
- return @config['name'] if key == 'title'
99
- key = key.split('=')
100
- return Tag.send(key[0].to_sym, *key[1]&.split(','))
101
- end
102
-
103
- class Tag
104
- class << self
105
- def method_missing *args
106
- ''
107
- end
108
-
109
- def random_url length = nil
110
- length && length = length.to_i
111
- SecureRandom.urlsafe_base64(length)
112
- end
113
- end
114
- end
115
-
116
- def get_body markdown
117
- return markdown
118
- end
119
-
120
- def get_config head
90
+ def get_header_config head
121
91
  return YAML.load(head.match(READ_CONFIG_REGEX).to_s)['_boilerplate']
122
92
  end
123
93
 
@@ -125,15 +95,10 @@ class JekyllPageBoilerplate::Page
125
95
  return head.gsub( READ_CONFIG_REGEX, '')
126
96
  end
127
97
 
128
-
129
98
  def get_boilerplate_path plate_name
130
- return Dir.glob(
131
- "#{File.join(BOILERPLATES_PATH, plate_name)}*"
132
- ).first
99
+ return Dir.glob( "#{File.join(BOILERPLATES_PATH, plate_name)}*" ).first.to_s
133
100
  end
134
101
 
135
-
136
-
137
102
  def abort_if_file_exists(file_path)
138
103
  if File.exist?(file_path)
139
104
  raise "#{file_path} already exists!"
@@ -0,0 +1,70 @@
1
+
2
+ class JekyllPageBoilerplate::Tags
3
+
4
+ FILE_DATE_FORMATE = '%Y-%m-%d'
5
+ FILL_SCAN = /\{{2}\s{0,}([^\{\}\.\s]+)\s{0,}\}{2}/
6
+
7
+ def self.[] *args
8
+ self.new *args
9
+ end
10
+
11
+ def initialize *args, **params
12
+ @tags = {}
13
+ add(*args, params)
14
+ end
15
+
16
+ def []= key, val
17
+ @tags[key.to_s] = val
18
+ end
19
+
20
+ def add *args, **params
21
+ args.map! {|h| h.transform_keys(&:to_s).compact }
22
+ params.transform_keys!(&:to_s).compact!
23
+ @tags.merge!(*args, params)
24
+ self
25
+ end
26
+
27
+ def [] key
28
+ key = key.to_s
29
+ @tags[key] ||= fetch(*key.split(/\s*=\s*|\s*,\s*/))
30
+ end
31
+
32
+ def fill *keys, safe: false
33
+ keys.map!(&:to_s)
34
+ keys.each do |k|
35
+ @tags[k].scan(FILL_SCAN).flatten.uniq.each do |tag|
36
+ @tags[k].gsub! /\{{2}\s{0,}#{tag.to_s}\s{0,}\}{2}/, self[tag].to_s
37
+ end
38
+ end
39
+ if safe
40
+ keys.each do |k|
41
+ @tags[k] = safe(k)
42
+ end
43
+ end
44
+ self
45
+ end
46
+
47
+ def safe key
48
+ self[key].to_s.downcase.gsub(/[^0-9a-z\.\-\/]+/, '-')
49
+ end
50
+
51
+ def fetch key, *params
52
+ case key
53
+ when 'safe'
54
+ safe(params.join(','))
55
+ when 'time'
56
+ Time.now.to_s
57
+ when 'date'
58
+ Time.now.strftime(FILE_DATE_FORMATE)
59
+ when 'random'
60
+ SecureRandom.hex(*params.map(&:to_i))
61
+ else
62
+ ''
63
+ end
64
+ end
65
+
66
+
67
+ def method_missing key
68
+ @tags[key.to_s]
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module JekyllPageBoilerplate
2
- VERSION = "4.2.1"
2
+ VERSION = "4.4.1"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "jekyll_page_boilerplate/version"
2
2
  require "jekyll_page_boilerplate/msg"
3
+ require "jekyll_page_boilerplate/tags"
3
4
  require "jekyll_page_boilerplate/page"
4
5
  require "jekyll_page_boilerplate/init"
5
6
  require "jekyll_page_boilerplate/list"
@@ -11,7 +11,7 @@ class JekyllPageBoilerplate::Application < Bales::Application
11
11
  option :path, type: String, long_form: '--path', short_form: '-p',
12
12
  description: "`<path>/title.md`"
13
13
  option :slug, type: String, long_form: '--slug', short_form: '-u',
14
- description: "`path/<slug-template>` `{{title}}-{{date}}{{suffix}}`"
14
+ description: "`path/<slug-template>.md` `{{title}}-{{date}}`"
15
15
  option :timestamp, type: TrueClass, long_form: '--timestamp', short_form: '-s',
16
16
  description: "`path/<time.now>-title.md`"
17
17
  option :suffix, type: String, long_form: '--suffix', short_form: '-x',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-page-boilerplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.4.1
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-12 00:00:00.000000000 Z
11
+ date: 2022-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bales
@@ -45,13 +45,13 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.8.5
47
47
  description: |+
48
- A boilerplate is a markdown file you place under the `_boilerplates/<boilerplate>.md` folder to generate new pages for jekyll.
48
+ A boilerplate is a markdown file you place under the `_boilerplates/` folder to generate new pages for jekyll.
49
49
 
50
50
 
51
51
  It can automatically timestamp and title new pages.
52
52
 
53
53
 
54
- It will also replacing any `{{ boilerplate.xxx }}` tags with content. Available tags include `.time, .title, .date, .random_url`.
54
+ It will also replacing any `{{ boilerplate.xxx }}` tags with content. Available tags include `.time, .title, .date, .random`.
55
55
 
56
56
 
57
57
  You can also provide custom tags with `boilerplate post nav_order=1` > `{{ boilerplate.nav_order }}`.
@@ -78,6 +78,7 @@ files:
78
78
  - lib/jekyll_page_boilerplate/msg/description.md
79
79
  - lib/jekyll_page_boilerplate/msg/gem_description.md
80
80
  - lib/jekyll_page_boilerplate/page.rb
81
+ - lib/jekyll_page_boilerplate/tags.rb
81
82
  - lib/jekyll_page_boilerplate/version.rb
82
83
  - lib/jekyll_page_boilerplate_cli.rb
83
84
  homepage: https://github.com/CodeKarmaDev/jekyll-page-boilerplate