jekyll-page-boilerplate 1.0.1 → 2.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: 6a93e2b4e7e502c0d19906f1dae2786f6fb1ceecf39d52c0dbdf82db241215e2
4
- data.tar.gz: 71434d9ca5e0072c25543fc2180b37ee59ce4702d73dde7ea454c16bf14d56cd
3
+ metadata.gz: 598484bc29508c7785e1dd1e24eb2699b6ecc7aa0ba346ee9c67a4d7530f3cc1
4
+ data.tar.gz: e72595d0503e4011384f54fd5d1a076e18796287b380911c1a14a8820d7c33a4
5
5
  SHA512:
6
- metadata.gz: 9cf262a0c5dc30f2af6b428ab50c0a9b5942c7e192c3e5f18a6e56dab04f2c081f3137119dabce88d108fedc9b65703363985df7a292fd70e472bcc15d778228
7
- data.tar.gz: f09fcfbd8dec7ef599e738b9dc45b4616ac181b07088dce6e1025bf3db9ccac32a24b52be9624d24304c03bc011d841cbdda157cdf20e7d8d7b77f12749c7ed9
6
+ metadata.gz: '058701eb91e08f7630642bbcbeeedf3368fc90c533dcb88286570e348207fd12af8a8dab89f0ea56094ff06f097a11c7fc0b061760007c6adcdecf8a16c23483'
7
+ data.tar.gz: f2678c628a1fde61096a8c68c61945796881ed190fcbab82af68ea73ed2e06c3cfcd849eec3806946ac0314f1791a63418ae7415e0c657843473a68bfc3c8276
data/exe/boilerplate CHANGED
@@ -11,10 +11,10 @@ require "mercenary"
11
11
  Mercenary.program(:boilerplate) do |p|
12
12
  p.version JekyllPageBoilerplate::VERSION
13
13
  p.description 'jekyll-page-boilerplate is a gem for jekyll that helps you generate new pages'
14
- p.syntax "jekyll-page <subcommand> [options]"
14
+ p.syntax "boilerplate <subcommand> [options]"
15
15
 
16
16
  p.command(:page) do |c|
17
- c.syntax "create BOILERPLATE_NAME \"NEW PAGE TITLE\""
17
+ c.syntax 'page BOILERPLATE_NAME "NEW PAGE TITLE"'
18
18
  c.description "Creates a page or post from a boilerplate."
19
19
 
20
20
  c.action do |args, _|
@@ -0,0 +1,44 @@
1
+ ---
2
+ _boilerplate: # The config for your boilerplates:
3
+ path: _posts # this is the folder path it will create your new post/page under.
4
+ timestamp: true # when true new post/pages will include the date in the filename.
5
+
6
+ title: TITLE # The title will be overwriten
7
+ created: CREATED # created will be overwriten with the current time
8
+
9
+ layout: post # Anything else in the file will be copied to your new post/page.
10
+ author: John Doe
11
+ ---
12
+
13
+
14
+ A Jekyll Boilerplate Example
15
+ ----------------------------
16
+
17
+
18
+ To create a new page/post from this boilerplate run:
19
+ ```bash
20
+ $ boilerplate page example "Another post about pottery"`
21
+ ```
22
+
23
+ A boilerplate is a markdown file in the `_boilerplates` folder.
24
+
25
+
26
+ This would create a new file:
27
+
28
+ ```text
29
+ _posts/yyyy-mm-dd-another-one-about-pottery.markdown
30
+ ---
31
+ title: Another one about pottery
32
+ created: 'yyyy-mm-dd hh:mm:ss -0000'
33
+ layout: post
34
+ author: John Doe
35
+ ---
36
+
37
+ A Jekyll Boilerplate Example
38
+ ----------------------------
39
+
40
+ To create a new page/post from this boilerplate run:
41
+
42
+ recursion error...
43
+
44
+ ```
@@ -4,7 +4,7 @@ module JekyllPageBoilerplate
4
4
  module Init
5
5
  def self.setup
6
6
  FileUtils.mkpath('_boilerplates')
7
- FileUtils.cp(File.join(__dir__, 'example.yml'), '_boilerplates')
7
+ FileUtils.cp(File.join(__dir__, 'example.md'), '_boilerplates')
8
8
  end
9
9
 
10
10
  end
@@ -4,35 +4,34 @@ module JekyllPageBoilerplate
4
4
 
5
5
  HELP = <<-'HELP'
6
6
 
7
- Create a new jekyll page/post from a boilerplate.
8
-
9
- A boilerplate is a yaml file in the `_boilerplates` folder.
10
-
11
- ie. `_boilerplates/post.yml`
12
- ---
13
- path: _posts
14
- timestap: true
15
-
16
- header:
17
- layout: post
18
- author: John Doe
19
-
20
- Boilerplate yaml settings:
21
- path - the path to create the new page under.
22
- timestamp - when true new post/pages will include the date in the filename.
23
- header - Any yaml you put under `header` will be added to your new pages/post
24
-
7
+ A boilerplate is a markdown file in the `_boilerplates` folder.
25
8
 
26
- `$ boilerplate page post "Another one about pottery"`
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.
27
14
 
28
- would create a new file `_posts/yyyy-mm-dd-another-one-about-pottery.markdown`
29
- ---
30
- title: Another one about pottery
31
- created: 'yyyy-mm-dd hh:mm:ss -0000'
32
- layout: post
33
- author: John Doe
34
- ---
35
-
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`
31
+
32
+ `$ boilerplate page <boilerplate-name> <post-title>`: Creates a new page from a boilerplate
33
+
34
+ `$ boilerplate help`: shows this dialog.
36
35
 
37
36
  HELP
38
37
 
@@ -7,69 +7,81 @@ module JekyllPageBoilerplate
7
7
 
8
8
  BOILERPLATES_PATH = '_boilerplates'
9
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]*)/
10
12
 
11
13
 
12
- def initialize boilerplate, suffix: '.yml'
13
- plate_path = File.join(BOILERPLATES_PATH, "#{boilerplate}#{suffix}")
14
+ def initialize boilerplate
15
+
16
+ plate_path = get_boilerplate_path(boilerplate)
14
17
 
15
- set_boilerplate_from_yaml_file( plate_path )
16
- end
18
+ abort_unless_file_exists( plate_path )
19
+
20
+ parsed_file = {}
21
+ File.open(plate_path, 'r') do |file|
22
+ parsed_file = file.read.match(READ_FILE_REGEX).named_captures
23
+ end
24
+
25
+ @config = get_config(parsed_file['head'])
26
+ @head = get_head(parsed_file['head'])
27
+ @body = get_body(parsed_file['body'])
28
+ end
17
29
 
18
30
  def create title
19
- abort_unless_file_exists(@boilerplate['path'])
20
-
21
- add_header_title( title )
22
- add_header_created()
31
+ abort_unless_file_exists(@config['path'])
23
32
 
24
- create_new_page( title )
33
+ set_header_entry 'title', title.gsub(/[&-]/, '&'=>'&amp;', '-'=>' ')
34
+ set_header_entry 'created', Time.now.to_s
25
35
 
26
- @boilerplate
36
+ create_new_page get_new_page_filename(title)
27
37
  end
28
38
 
29
39
  private
30
-
31
- def create_new_page title
32
- filename = get_new_page_filename( title )
33
-
34
- new_file_path = File.join( @boilerplate['path'], filename )
40
+
41
+ def create_new_page filename
42
+ new_file_path = File.join( @config['path'], filename )
35
43
 
36
44
  abort_if_file_exists(new_file_path)
37
45
 
38
46
  open(new_file_path, 'w') do |page|
39
- page.puts @boilerplate['header'].to_yaml
40
47
  page.puts '---'
48
+ page.puts @head
49
+ page.puts '---'
50
+ page.puts @body
41
51
  page.puts ''
42
- page.print @boilerplate['content']
43
- page.puts ''
44
- end
45
-
52
+ end
46
53
  end
47
54
 
48
55
 
49
- def add_header_created
50
- @boilerplate['header']['created'] = Time.now.to_s
56
+ def set_header_entry key, val
57
+ @head << "\n#{key}: null" unless @head.match /^#{key}:.*$/
58
+ @head.gsub! /^#{key}:.*$/, "#{key}: #{val}"
51
59
  end
52
-
53
- def add_header_title title
54
- @boilerplate['header']['title'] = title.gsub(/[&-]/, '&'=>'&amp;', '-'=>' ')
60
+
61
+ def get_body markdown
62
+ return markdown
55
63
  end
56
64
 
65
+ def get_config head
66
+ return YAML.load(head.match(READ_CONFIG_REGEX).to_s)['_boilerplate']
67
+ end
57
68
 
58
- def set_boilerplate_from_yaml_file yaml_path
59
- abort_unless_file_exists( yaml_path )
60
-
61
- @boilerplate = {}
62
-
63
- File.open(yaml_path, 'r') do |yaml_file|
64
- @boilerplate = YAML.load( yaml_file.read )
65
- end
69
+ def get_head head
70
+ return head.gsub READ_CONFIG_REGEX, ''
66
71
  end
67
72
 
68
73
 
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
79
+
80
+
69
81
  def get_new_page_filename title
70
82
  title = title.to_url
71
- title = "#{title}#{@boilerplate['suffix'] || '.markdown'}"
72
- if @boilerplate['timestamp']
83
+ title = "#{title}#{@config['suffix'] || '.markdown'}"
84
+ if @config['timestamp']
73
85
  title = "#{Time.now.strftime(FILE_DATE_FORMATE)}-#{title}"
74
86
  end
75
87
  return title
@@ -1,3 +1,3 @@
1
1
  module JekyllPageBoilerplate
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
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: 1.0.1
4
+ version: 2.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: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mercenary
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: stringex
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.8'
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: '0'
36
+ version: 2.8.5
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.8'
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: 2.8.5
41
47
  description: A jekyll plugin that allows you to create new pages or posts from a boilerplate
42
48
  through the terminal.
43
49
  email:
@@ -49,7 +55,7 @@ extra_rdoc_files: []
49
55
  files:
50
56
  - exe/boilerplate
51
57
  - lib/jekyll_page_boilerplate.rb
52
- - lib/jekyll_page_boilerplate/example.yml
58
+ - lib/jekyll_page_boilerplate/example.md
53
59
  - lib/jekyll_page_boilerplate/init.rb
54
60
  - lib/jekyll_page_boilerplate/msg.rb
55
61
  - lib/jekyll_page_boilerplate/page.rb
@@ -75,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
81
  - !ruby/object:Gem::Version
76
82
  version: '0'
77
83
  requirements: []
78
- rubygems_version: 3.0.8
84
+ rubygems_version: 3.2.3
79
85
  signing_key:
80
86
  specification_version: 4
81
- summary: A jekyll plugin that create new pages from boilerplates
87
+ summary: A jekyll plugin that creates new pages from boilerplates
82
88
  test_files: []
@@ -1,43 +0,0 @@
1
- ---
2
-
3
- # Create a new jekyll page/post from a boilerplate.
4
-
5
- # A boilerplate is a yaml file in the `_boilerplates` folder.
6
-
7
- # `$ boilerplate page example "Another post about pottery"`
8
-
9
- # the path to create the new page under.
10
- path: _posts
11
-
12
- # when true new post/pages will include the date in the filename.
13
- timestamp: true
14
-
15
- # Any yaml you put under `header` will be added to your new pages/post
16
- header:
17
- layout: post
18
- author: John Doe
19
-
20
- # the boilerplate markdown content for your page
21
- content: '
22
-
23
- # Heading
24
-
25
-
26
- Some stuff that changes a little bit but that I don't want to bother copying and pasting.'
27
-
28
-
29
- # This would create a new file:
30
- # _posts/yyyy-mm-dd-another-one-about-pottery.markdow`
31
- # ---
32
- # title: Another one about pottery
33
- # created: 'yyyy-mm-dd hh:mm:ss -0000'
34
- # layout: post
35
- # author: John Doe
36
- # ---
37
- #
38
- # Heading
39
- # -------
40
- #
41
- # Some stuff that changes a little bit but that I don't want to bother copying and pasting.
42
- #
43
- #