jekyll-page-boilerplate 2.0.0 → 4.0.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: 598484bc29508c7785e1dd1e24eb2699b6ecc7aa0ba346ee9c67a4d7530f3cc1
4
- data.tar.gz: e72595d0503e4011384f54fd5d1a076e18796287b380911c1a14a8820d7c33a4
3
+ metadata.gz: 17477700177377cd7125dcdaab31a6c5ccc853d7f4a2ad866fb055680803f41e
4
+ data.tar.gz: 2b03a6cca499eb059c8842fd1a5c4dbeefef44b538d2bd92df738fd795c9a10b
5
5
  SHA512:
6
- metadata.gz: '058701eb91e08f7630642bbcbeeedf3368fc90c533dcb88286570e348207fd12af8a8dab89f0ea56094ff06f097a11c7fc0b061760007c6adcdecf8a16c23483'
7
- data.tar.gz: f2678c628a1fde61096a8c68c61945796881ed190fcbab82af68ea73ed2e06c3cfcd849eec3806946ac0314f1791a63418ae7415e0c657843473a68bfc3c8276
6
+ metadata.gz: 91381a908df2713f69036642a842f84da601f8616219ea362b18ded8f8c189452498a40d29c972f7e1832ba414ef8d4fdcd0bbf03aa97e8426582acb665c7b66
7
+ data.tar.gz: 7522e8fe98b9beb92b057f1159776ea53c9075fcede91b1a4d0c5632646fb0e25f602931a6b32b84d0bc4c061edaf49ed00715f1d51c70870c4355e0ee809bf0
data/exe/boilerplate CHANGED
@@ -5,45 +5,4 @@ STDOUT.sync = true
5
5
  gem_dir = File.expand_path("..",File.dirname(__FILE__))
6
6
  $LOAD_PATH.unshift gem_dir # Look in gem directory for resources first.
7
7
 
8
- require 'jekyll_page_boilerplate'
9
- require "mercenary"
10
-
11
- Mercenary.program(:boilerplate) do |p|
12
- p.version JekyllPageBoilerplate::VERSION
13
- p.description 'jekyll-page-boilerplate is a gem for jekyll that helps you generate new pages'
14
- p.syntax "boilerplate <subcommand> [options]"
15
-
16
- p.command(:page) do |c|
17
- c.syntax 'page BOILERPLATE_NAME "NEW PAGE TITLE"'
18
- c.description "Creates a page or post from a boilerplate."
19
-
20
- c.action do |args, _|
21
- JekyllPageBoilerplate.page args[0], args[1], c
22
- end
23
- end
24
-
25
- p.command(:help) do |c|
26
- c.syntax "help"
27
- c.description "Describe what jekyll-page-boilerplate does."
28
-
29
- c.action do
30
- JekyllPageBoilerplate.help c
31
- end
32
- end
33
-
34
- p.command(:init) do |c|
35
- c.syntax "init"
36
- c.description "Creates an example boilerplate."
37
-
38
- c.action do
39
- JekyllPageBoilerplate.init c
40
- end
41
- end
42
-
43
-
44
-
45
-
46
- p.default_command(:help)
47
- end
48
-
49
-
8
+ require 'jekyll_page_boilerplate_cli'
data/exe/bplate ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDOUT.sync = true
4
+
5
+ gem_dir = File.expand_path("..",File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift gem_dir # Look in gem directory for resources first.
7
+
8
+ require 'jekyll_page_boilerplate_cli'
@@ -3,8 +3,8 @@ _boilerplate: # The config for your boilerplates:
3
3
  path: _posts # this is the folder path it will create your new post/page under.
4
4
  timestamp: true # when true new post/pages will include the date in the filename.
5
5
 
6
- title: TITLE # The title will be overwriten
7
- created: CREATED # created will be overwriten with the current time
6
+ title: {{ boilerplate.title }} # -T or --title options
7
+ created: {{ boilerplate.time }} # the current time.
8
8
 
9
9
  layout: post # Anything else in the file will be copied to your new post/page.
10
10
  author: John Doe
@@ -17,7 +17,7 @@ A Jekyll Boilerplate Example
17
17
 
18
18
  To create a new page/post from this boilerplate run:
19
19
  ```bash
20
- $ boilerplate page example "Another post about pottery"`
20
+ $ boilerplate create example "Another post about pottery"`
21
21
  ```
22
22
 
23
23
  A boilerplate is a markdown file in the `_boilerplates` folder.
@@ -1,11 +1,16 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module JekyllPageBoilerplate
4
- module Init
4
+ class Init
5
+
6
+ def self.run
7
+ self.setup
8
+ return 'Created _boilerplates/example.md'
9
+ end
10
+
5
11
  def self.setup
6
12
  FileUtils.mkpath('_boilerplates')
7
13
  FileUtils.cp(File.join(__dir__, 'example.md'), '_boilerplates')
8
14
  end
9
-
10
15
  end
11
- end
16
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module JekyllPageBoilerplate
3
+
4
+ class List
5
+
6
+ SPACER = '\n'
7
+ REMOVE_SUFFIX = /\.\w+(?=[\s\n\r$])/
8
+
9
+ def self.run
10
+ Dir.glob("_boilerplates/*").map do |f|
11
+ File.basename(f, '.*')
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ A boilerplate is a markdown file in the `_boilerplates` folder.
2
+
3
+ ie. `_boilerplates/post.md`
4
+ ---
5
+ _boilerplate: # boilerplate settings
6
+ path: _posts # the path to create the new page under.
7
+ timestap: true # when true new post/pages will include the date in the filename.
8
+
9
+ title: {{ boilerplate.title }}
10
+ layout: post # everthing else will be copied to the new post.
11
+ author: John Doe
12
+
13
+ `$ boilerplate post -T "Another one about pottery"` would create a new file `_posts/yyyy-mm-dd-another-one-about-pottery.markdown`
14
+ ---
15
+ title: Another one about pottery
16
+ created: 'yyyy-mm-dd hh:mm:ss -0000'
17
+ layout: post
18
+ author: John Doe
19
+ ---
20
+
21
+ Available Tags with `{{ boilerplate.xxx }}`:
22
+ - `.title`, `.name`
23
+ - `.path`, `.file`, `.suffix`
24
+ - `.time`, `.date`, `.timestamp`
25
+ - `.random_url`
26
+ - And anything you put under the `_boilerplate:` header
27
+
28
+
29
+
30
+ Use `boilerplate help` for more details
@@ -1,39 +1,24 @@
1
1
 
2
- module JekyllPageBoilerplate
3
- module Msg
2
+ module JekyllPageBoilerplate::Msg
4
3
 
5
- HELP = <<-'HELP'
6
-
7
- A boilerplate is a markdown file in the `_boilerplates` folder.
8
-
9
- ie. `_boilerplates/post.yml`
10
- ---
11
- _boilerplate: # boilerplate settings
12
- path: _posts # the path to create the new page under.
13
- timestap: true # when true new post/pages will include the date in the filename.
14
-
15
- layout: post # everthing else will be copied to the new post.
16
- author: John Doe
17
-
18
-
19
- `$ boilerplate page post "Another one about pottery"` would create a new file `_posts/yyyy-mm-dd-another-one-about-pottery.markdown`
20
- ---
21
- title: Another one about pottery
22
- created: 'yyyy-mm-dd hh:mm:ss -0000'
23
- layout: post
24
- author: John Doe
25
- ---
26
-
27
-
28
- Usage: `$ boilerplate [page|init|help]`
29
-
30
- `$ boilerplate init`: creates a example boilerplate at `_boilerplates/example.md`
4
+ def self.file name
5
+ puts File.read(File.join(__dir__, 'msg', name))
6
+ end
31
7
 
32
- `$ boilerplate page <boilerplate-name> <post-title>`: Creates a new page from a boilerplate
8
+ def self.error(**msgs)
9
+ msgs.each {|k,v| puts(k.to_s.capitalize!+': '+v)}
10
+ end
33
11
 
34
- `$ boilerplate help`: shows this dialog.
12
+ def self.info msg
13
+ puts msg
14
+ end
35
15
 
36
- HELP
37
-
16
+ def self.try_and_report &block
17
+ begin
18
+ self.info block.call
19
+ rescue => e
20
+ self.error fatal: e.message
21
+ end
38
22
  end
39
- end
23
+
24
+ end
@@ -1,107 +1,139 @@
1
1
 
2
2
  require 'yaml'
3
3
  require "stringex"
4
+ require 'securerandom'
5
+
6
+ class JekyllPageBoilerplate::Page
7
+
8
+ BOILERPLATES_PATH = '_boilerplates'
9
+ FILE_DATE_FORMATE = '%Y-%m-%d'
10
+ READ_CONFIG_REGEX = /[\r\n\s]{0,}^_boilerplate:(\s*^[\t ]{1,2}.+$)+[\r\s\n]{0,}(?![^\r\s\n])/
11
+ READ_FILE_REGEX = /^-{3}\s*^(?<head>[\s\S]*)^-{3}\s^(?<body>[\s\S]*)/
12
+ TAGS_REGEX = /(?<tag>\{{2}\s{0,}boilerplate\.(?<key>[^\{\}\.\s]+)\s{0,}\}{2})/
13
+
14
+ attr_reader :config
15
+
16
+ def self.run boilerplate, options
17
+ page = self.new(boilerplate, options)
18
+ page.create
19
+ return "Created %s/%s" % [page.config['path'], page.config['file']]
20
+ end
4
21
 
5
- module JekyllPageBoilerplate
6
- class Page
22
+ def initialize boilerplate, options
23
+ options.compact!
24
+ options.transform_keys! {|k| k.to_s}
25
+ plate_path = get_boilerplate_path(boilerplate).to_s
7
26
 
8
- BOILERPLATES_PATH = '_boilerplates'
9
- FILE_DATE_FORMATE = '%Y-%m-%d'
10
- READ_CONFIG_REGEX = /^_boilerplate:(\s*^[\t ]{1,2}.+$)+/
11
- READ_FILE_REGEX = /^-{3}\s*$(?<head>[\s\S]*)^-{3}\s$(?<body>[\s\S]*)/
27
+ abort_unless_file_exists( plate_path )
12
28
 
29
+ parsed_file = {}
30
+ File.open(plate_path, 'r') do |file|
31
+ parsed_file = file.read.match(READ_FILE_REGEX).named_captures
32
+ end
13
33
 
14
- def initialize boilerplate
34
+ @config = get_config(parsed_file['head']).merge(options)
35
+ @config['suffix'] ||= plate_path[/\.\w+$/]
36
+ @config['name'] ||= plate_path[/.*(?=\.)/] || plate_path
37
+ @head = get_head(parsed_file['head'])
38
+ @body = get_body(parsed_file['body'])
39
+ end
40
+
41
+ def create
42
+ @config['time'] ||= Time.now.to_s
43
+ @config['date'] ||= Time.now.strftime(FILE_DATE_FORMATE)
15
44
 
16
- plate_path = get_boilerplate_path(boilerplate)
17
-
18
- abort_unless_file_exists( plate_path )
45
+ abort_unless_file_exists(@config['path'])
46
+
47
+ @config['file'] ||= get_new_page_filename(@config['title'] || @config['name'])
19
48
 
20
- parsed_file = {}
21
- File.open(plate_path, 'r') do |file|
22
- parsed_file = file.read.match(READ_FILE_REGEX).named_captures
23
- end
49
+ scan_template :@body
50
+ scan_template :@head
24
51
 
25
- @config = get_config(parsed_file['head'])
26
- @head = get_head(parsed_file['head'])
27
- @body = get_body(parsed_file['body'])
28
- end
29
-
30
- def create title
31
- abort_unless_file_exists(@config['path'])
32
-
33
- set_header_entry 'title', title.gsub(/[&-]/, '&'=>'&amp;', '-'=>' ')
34
- set_header_entry 'created', Time.now.to_s
52
+ create_new_page @config['file']
53
+ end
35
54
 
36
- create_new_page get_new_page_filename(title)
37
- end
55
+ private
56
+
57
+ def create_new_page filename
58
+ new_file_path = File.join( @config['path'], filename )
38
59
 
39
- private
40
-
41
- def create_new_page filename
42
- new_file_path = File.join( @config['path'], filename )
43
-
44
- abort_if_file_exists(new_file_path)
45
-
46
- open(new_file_path, 'w') do |page|
47
- page.puts '---'
48
- page.puts @head
49
- page.puts '---'
50
- page.puts @body
51
- page.puts ''
52
- end
53
- end
60
+ abort_if_file_exists(new_file_path)
54
61
 
62
+ open(new_file_path, 'w') do |page|
63
+ page.puts '---'
64
+ page.puts @head.lstrip
65
+ page.puts '---'
66
+ page.puts @body
67
+ page.puts ''
68
+ end
69
+ end
55
70
 
56
- def set_header_entry key, val
57
- @head << "\n#{key}: null" unless @head.match /^#{key}:.*$/
58
- @head.gsub! /^#{key}:.*$/, "#{key}: #{val}"
71
+ def scan_template var
72
+ instance_variable_get(var).scan(TAGS_REGEX).uniq.each do |tag, key|
73
+ instance_variable_get(var).gsub! /\{{2}\s{0,}boilerplate\.#{key}\s{0,}\}{2}/, get_tag_value(key)
59
74
  end
75
+ end
60
76
 
61
- def get_body markdown
62
- return markdown
63
- end
77
+ def get_tag_value(key)
78
+ return @config[key] if @config[key]
79
+ key = key.split('=')
80
+ return Tag.send(key[0].to_sym, *key[1]&.split(','))
81
+ end
82
+
83
+ class Tag
84
+ class << self
85
+ def missing_method
86
+ nil
87
+ end
64
88
 
65
- def get_config head
66
- return YAML.load(head.match(READ_CONFIG_REGEX).to_s)['_boilerplate']
89
+ def random_url length = nil
90
+ length && length = length.to_i
91
+ SecureRandom.urlsafe_base64(length)
92
+ end
67
93
  end
94
+ end
68
95
 
69
- def get_head head
70
- return head.gsub READ_CONFIG_REGEX, ''
71
- end
72
-
96
+ def get_body markdown
97
+ return markdown
98
+ end
73
99
 
74
- def get_boilerplate_path plate_name
75
- return Dir.glob(
76
- "#{File.join(BOILERPLATES_PATH, plate_name)}.{md,markdown,MD,MARKDOWN}"
77
- ).first
78
- end
100
+ def get_config head
101
+ return YAML.load(head.match(READ_CONFIG_REGEX).to_s)['_boilerplate']
102
+ end
79
103
 
104
+ def get_head head
105
+ return head.gsub( READ_CONFIG_REGEX, '')
106
+ end
107
+
80
108
 
81
- def get_new_page_filename title
82
- title = title.to_url
83
- title = "#{title}#{@config['suffix'] || '.markdown'}"
84
- if @config['timestamp']
85
- title = "#{Time.now.strftime(FILE_DATE_FORMATE)}-#{title}"
86
- end
87
- return title
109
+ def get_boilerplate_path plate_name
110
+ return Dir.glob(
111
+ "#{File.join(BOILERPLATES_PATH, plate_name)}*"
112
+ ).first
113
+ end
114
+
115
+
116
+ def get_new_page_filename title
117
+ title = title.to_url
118
+ title = "#{title}#{@config['suffix']}"
119
+ if @config['timestamp']
120
+ title = "#{@config['date']}-#{title}"
88
121
  end
122
+ return title
123
+ end
89
124
 
90
125
 
91
126
 
92
- def abort_if_file_exists(file_path)
93
- if File.exist?(file_path)
94
- raise "#{file_path} already exists!"
95
- end
127
+ def abort_if_file_exists(file_path)
128
+ if File.exist?(file_path)
129
+ raise "#{file_path} already exists!"
96
130
  end
131
+ end
97
132
 
98
- def abort_unless_file_exists(file_path)
99
- unless File.exist?(file_path)
100
- raise "#{file_path} does not exist!"
101
- end
133
+ def abort_unless_file_exists(file_path)
134
+ unless File.exist?(file_path)
135
+ raise "The file `#{file_path}` does not exist!"
102
136
  end
103
-
104
-
105
137
  end
106
138
 
107
- end
139
+ end
@@ -1,3 +1,5 @@
1
1
  module JekyllPageBoilerplate
2
- VERSION = "2.0.0"
2
+ VERSION = "4.0.1"
3
+
4
+ DESCRIPTION = "A jekyll plugin that allows you to create new pages or posts from a boilerplate through the terminal."
3
5
  end
@@ -1,33 +1,33 @@
1
1
  require "jekyll_page_boilerplate/version"
2
- require "jekyll_page_boilerplate/page"
3
2
  require "jekyll_page_boilerplate/msg"
3
+ require "jekyll_page_boilerplate/page"
4
4
  require "jekyll_page_boilerplate/init"
5
+ require "jekyll_page_boilerplate/list"
6
+
5
7
 
6
8
  module JekyllPageBoilerplate
7
9
  class Error < StandardError; end
8
10
 
9
-
10
- def self.init cmd
11
- begin
12
- Init.setup
13
- rescue => e
14
- cmd.logger.fatal e.message
11
+ def self.init
12
+ Msg.try_and_report do
13
+ Init.run
15
14
  end
16
15
  end
17
16
 
18
-
19
- def self.help cmd
20
- cmd.logger.info Msg::HELP
17
+ def self.list
18
+ Msg.try_and_report do
19
+ List.run
20
+ end
21
21
  end
22
22
 
23
+ def self.readme
24
+ Msg.file 'readme.md'
25
+ end
23
26
 
24
- def self.page boilerplate_name, page_title, cmd
25
- page = Page.new(boilerplate_name)
26
- begin
27
- page.create(page_title)
28
- rescue => e
29
- cmd.logger.fatal e.message
27
+ def self.page boilerplate_name, options
28
+ Msg.try_and_report do
29
+ Page.run(boilerplate_name, options)
30
30
  end
31
- end
31
+ end
32
32
 
33
33
  end
@@ -0,0 +1,64 @@
1
+ require "bales"
2
+ require 'jekyll_page_boilerplate'
3
+
4
+ class JekyllPageBoilerplate::Application < Bales::Application
5
+ version JekyllPageBoilerplate::VERSION
6
+ description JekyllPageBoilerplate::DESCRIPTION
7
+
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 :timestamp, type: TrueClass, long_form: '--timestamp', short_form: '-s',
14
+ description: "`path/<time.now>-title.md`"
15
+ option :suffix, type: String, long_form: '--suffix', short_form: '-x',
16
+ description: "`path/title.<md, markdown, txt>`"
17
+
18
+ action do |plate, title: nil, path: nil, timestamp: nil, suffix: nil|
19
+ JekyllPageBoilerplate.page plate, {title: title, path: path, suffix: suffix, timestamp: timestamp}
20
+ end
21
+
22
+ # `boilerplate readme`
23
+ command 'readme' do
24
+ description "Helpful info"
25
+ action do
26
+ JekyllPageBoilerplate.readme
27
+ end
28
+ end
29
+
30
+ # `boilerplate help`
31
+ command 'help', parent: Bales::Command::Help
32
+
33
+ # `boilerplate init`
34
+ command 'init' do
35
+ description "Creates an example boilerplate."
36
+ action do
37
+ JekyllPageBoilerplate.init
38
+ end
39
+ end
40
+
41
+ # `boilerplate list`
42
+ command 'list' do
43
+ description "List all the boilerplates"
44
+ action do
45
+ JekyllPageBoilerplate.list
46
+ end
47
+ end
48
+
49
+
50
+ def self.run(*args, **opts)
51
+ begin
52
+ super
53
+ rescue => e
54
+ JekyllPageBoilerplate.readme
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ JekyllPageBoilerplate::Application.parse_and_run
61
+
62
+
63
+
64
+
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-page-boilerplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 4.0.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: 2021-05-25 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: mercenary
14
+ name: bales
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.0
19
+ version: 0.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.0
26
+ version: 0.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: stringex
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,16 +50,21 @@ email:
50
50
  - sean@codekarma.dev
51
51
  executables:
52
52
  - boilerplate
53
+ - bplate
53
54
  extensions: []
54
55
  extra_rdoc_files: []
55
56
  files:
56
57
  - exe/boilerplate
58
+ - exe/bplate
57
59
  - lib/jekyll_page_boilerplate.rb
58
60
  - lib/jekyll_page_boilerplate/example.md
59
61
  - lib/jekyll_page_boilerplate/init.rb
62
+ - lib/jekyll_page_boilerplate/list.rb
60
63
  - lib/jekyll_page_boilerplate/msg.rb
64
+ - lib/jekyll_page_boilerplate/msg/readme.md
61
65
  - lib/jekyll_page_boilerplate/page.rb
62
66
  - lib/jekyll_page_boilerplate/version.rb
67
+ - lib/jekyll_page_boilerplate_cli.rb
63
68
  homepage: https://github.com/CodeKarmaDev/jekyll-page-boilerplate
64
69
  licenses:
65
70
  - MIT