jekyll-page-boilerplate 2.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cda02e5e566768a18e995b7b409ec9d7563553a2ae576b790e2604bc3200d8d8
4
- data.tar.gz: 03cad8782fa41bdf0bc26b52739ac0150868c5ae8a5f18aada88004a25d26689
3
+ metadata.gz: d0bdff35c4fc0b98be3987b90be503a93864c8dcb0dec6358a1cdd07f19fdc88
4
+ data.tar.gz: 8a11dca9014aaa518f9f56d4782077e3791b4342af84a8f917afe8d5b7eecf62
5
5
  SHA512:
6
- metadata.gz: f2a77c95e14d5289aeff92bed9cf6d6fa34982c7a4d16585957880fbeee09069cff4df3e9797a5e15cf53b6c4f436cdbbba932719dd8bd2984dac57015fc4e75
7
- data.tar.gz: fd30ddeacf2a1eef951ba7d4cf28f2996af7961ab707af4548e5872de0be5653501d7be356ad6aa1ea5cb43c10edaedd6abace18d2c2c99c24126bb0c7ccdb8f
6
+ metadata.gz: b9a614357a7bcb5c380ab20587b34779d18d12d06380f0511a15f8187ea22b28547b640aeba05029422de27cc3e0974ac724c0b13746220a6e3455f83abf67be
7
+ data.tar.gz: 7533fd3e0811a14c04f505c444d1e61225bc624c54d9cd2aecace495884172c8628b04810d54e23639137334ea5ccdff4e65ab8dddeb8ed39c33e099e226def0
data/exe/boilerplate CHANGED
@@ -5,47 +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
-
12
-
13
- Mercenary.program(:boilerplate) do |p|
14
- p.version JekyllPageBoilerplate::VERSION
15
- p.description 'jekyll-page-boilerplate is a gem for jekyll that helps you generate new pages'
16
- p.syntax "boilerplate <subcommand> [options]"
17
-
18
- p.command(:page) do |c|
19
- c.syntax 'page BOILERPLATE_NAME "NEW PAGE TITLE"'
20
- c.description "Creates a page or post from a boilerplate."
21
-
22
- c.action do |args, _|
23
- JekyllPageBoilerplate.page args[0], args[1], c
24
- end
25
- end
26
-
27
- p.command(:help) do |c|
28
- c.syntax "help"
29
- c.description "Describe what jekyll-page-boilerplate does."
30
-
31
- c.action do
32
- JekyllPageBoilerplate.help c
33
- end
34
- end
35
-
36
- p.command(:init) do |c|
37
- c.syntax "init"
38
- c.description "Creates an example boilerplate."
39
-
40
- c.action do
41
- JekyllPageBoilerplate.init c
42
- end
43
- end
44
-
45
-
46
-
47
-
48
- p.default_command(:help)
49
- end
50
-
51
-
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,27 @@
1
+ A boilerplate is a markdown file in the `_boilerplates` folder.
2
+
3
+ ie. `_boilerplates/post.yml`
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 page post "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
+ Usage: `$ boilerplate [page|init|help]`
22
+
23
+ `$ boilerplate init`: creates a example boilerplate at `_boilerplates/example.md`
24
+
25
+ `$ boilerplate page <boilerplate-name> <post-title>`: Creates a new page from a boilerplate
26
+
27
+ `$ boilerplate help`: shows this dialog.
@@ -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,144 @@
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 = /[\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]*)/
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).to_s
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.lstrip
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 fill_template key, val
97
+ @head.gsub! /\{{2}\s{0,}boilerplate\.#{key}\s{0,}\}{2}/, @config[key].to_s
98
+ @body.gsub! /\{{2}\s{0,}boilerplate\.#{key}\s{0,}\}{2}/, @config[key].to_s
99
+ end
73
100
 
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
101
+ def get_body markdown
102
+ return markdown
103
+ end
79
104
 
105
+ def get_config head
106
+ return YAML.load(head.match(READ_CONFIG_REGEX).to_s)['_boilerplate']
107
+ end
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
88
- end
109
+ def get_head head
110
+ return head.gsub( READ_CONFIG_REGEX, '')
111
+ end
112
+
89
113
 
114
+ def get_boilerplate_path plate_name
115
+ return Dir.glob(
116
+ "#{File.join(BOILERPLATES_PATH, plate_name)}*"
117
+ ).first
118
+ end
90
119
 
91
120
 
92
- def abort_if_file_exists(file_path)
93
- if File.exist?(file_path)
94
- raise "#{file_path} already exists!"
95
- end
121
+ def get_new_page_filename title
122
+ title = title.to_url
123
+ title = "#{title}#{@config['suffix']}"
124
+ if @config['timestamp']
125
+ title = "#{@config['date']}-#{title}"
96
126
  end
127
+ return title
128
+ end
97
129
 
98
- def abort_unless_file_exists(file_path)
99
- unless File.exist?(file_path)
100
- raise "#{file_path} does not exist!"
101
- end
102
- end
103
130
 
104
131
 
132
+ def abort_if_file_exists(file_path)
133
+ if File.exist?(file_path)
134
+ raise "#{file_path} already exists!"
135
+ end
136
+ end
137
+
138
+ def abort_unless_file_exists(file_path)
139
+ unless File.exist?(file_path)
140
+ raise "The file `#{file_path}` does not exist!"
141
+ end
105
142
  end
106
143
 
107
- end
144
+ end
@@ -1,3 +1,5 @@
1
1
  module JekyllPageBoilerplate
2
- VERSION = "2.1.0"
2
+ VERSION = "4.0.0"
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.1.0
4
+ version: 4.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: 2021-06-08 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