jekyll-page-boilerplate 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a93e2b4e7e502c0d19906f1dae2786f6fb1ceecf39d52c0dbdf82db241215e2
4
+ data.tar.gz: 71434d9ca5e0072c25543fc2180b37ee59ce4702d73dde7ea454c16bf14d56cd
5
+ SHA512:
6
+ metadata.gz: 9cf262a0c5dc30f2af6b428ab50c0a9b5942c7e192c3e5f18a6e56dab04f2c081f3137119dabce88d108fedc9b65703363985df7a292fd70e472bcc15d778228
7
+ data.tar.gz: f09fcfbd8dec7ef599e738b9dc45b4616ac181b07088dce6e1025bf3db9ccac32a24b52be9624d24304c03bc011d841cbdda157cdf20e7d8d7b77f12749c7ed9
@@ -0,0 +1,49 @@
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'
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 "jekyll-page <subcommand> [options]"
15
+
16
+ p.command(:page) do |c|
17
+ c.syntax "create 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
+
@@ -0,0 +1,33 @@
1
+ require "jekyll_page_boilerplate/version"
2
+ require "jekyll_page_boilerplate/page"
3
+ require "jekyll_page_boilerplate/msg"
4
+ require "jekyll_page_boilerplate/init"
5
+
6
+ module JekyllPageBoilerplate
7
+ class Error < StandardError; end
8
+
9
+
10
+ def self.init cmd
11
+ begin
12
+ Init.setup
13
+ rescue => e
14
+ cmd.logger.fatal e.message
15
+ end
16
+ end
17
+
18
+
19
+ def self.help cmd
20
+ cmd.logger.info Msg::HELP
21
+ end
22
+
23
+
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
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,43 @@
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
+ #
@@ -0,0 +1,11 @@
1
+ require 'fileutils'
2
+
3
+ module JekyllPageBoilerplate
4
+ module Init
5
+ def self.setup
6
+ FileUtils.mkpath('_boilerplates')
7
+ FileUtils.cp(File.join(__dir__, 'example.yml'), '_boilerplates')
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+
2
+ module JekyllPageBoilerplate
3
+ module Msg
4
+
5
+ HELP = <<-'HELP'
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
+
25
+
26
+ `$ boilerplate page post "Another one about pottery"`
27
+
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
+
36
+
37
+ HELP
38
+
39
+ end
40
+ end
@@ -0,0 +1,95 @@
1
+
2
+ require 'yaml'
3
+ require "stringex"
4
+
5
+ module JekyllPageBoilerplate
6
+ class Page
7
+
8
+ BOILERPLATES_PATH = '_boilerplates'
9
+ FILE_DATE_FORMATE = '%Y-%m-%d'
10
+
11
+
12
+ def initialize boilerplate, suffix: '.yml'
13
+ plate_path = File.join(BOILERPLATES_PATH, "#{boilerplate}#{suffix}")
14
+
15
+ set_boilerplate_from_yaml_file( plate_path )
16
+ end
17
+
18
+ def create title
19
+ abort_unless_file_exists(@boilerplate['path'])
20
+
21
+ add_header_title( title )
22
+ add_header_created()
23
+
24
+ create_new_page( title )
25
+
26
+ @boilerplate
27
+ end
28
+
29
+ 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 )
35
+
36
+ abort_if_file_exists(new_file_path)
37
+
38
+ open(new_file_path, 'w') do |page|
39
+ page.puts @boilerplate['header'].to_yaml
40
+ page.puts '---'
41
+ page.puts ''
42
+ page.print @boilerplate['content']
43
+ page.puts ''
44
+ end
45
+
46
+ end
47
+
48
+
49
+ def add_header_created
50
+ @boilerplate['header']['created'] = Time.now.to_s
51
+ end
52
+
53
+ def add_header_title title
54
+ @boilerplate['header']['title'] = title.gsub(/[&-]/, '&'=>'&amp;', '-'=>' ')
55
+ end
56
+
57
+
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
66
+ end
67
+
68
+
69
+ def get_new_page_filename title
70
+ title = title.to_url
71
+ title = "#{title}#{@boilerplate['suffix'] || '.markdown'}"
72
+ if @boilerplate['timestamp']
73
+ title = "#{Time.now.strftime(FILE_DATE_FORMATE)}-#{title}"
74
+ end
75
+ return title
76
+ end
77
+
78
+
79
+
80
+ def abort_if_file_exists(file_path)
81
+ if File.exist?(file_path)
82
+ raise "#{file_path} already exists!"
83
+ end
84
+ end
85
+
86
+ def abort_unless_file_exists(file_path)
87
+ unless File.exist?(file_path)
88
+ raise "#{file_path} does not exist!"
89
+ end
90
+ end
91
+
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllPageBoilerplate
2
+ VERSION = "1.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-page-boilerplate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Ferney
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mercenary
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: stringex
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A jekyll plugin that allows you to create new pages or posts from a boilerplate
42
+ through the terminal.
43
+ email:
44
+ - sean@codekarma.dev
45
+ executables:
46
+ - boilerplate
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - exe/boilerplate
51
+ - lib/jekyll_page_boilerplate.rb
52
+ - lib/jekyll_page_boilerplate/example.yml
53
+ - lib/jekyll_page_boilerplate/init.rb
54
+ - lib/jekyll_page_boilerplate/msg.rb
55
+ - lib/jekyll_page_boilerplate/page.rb
56
+ - lib/jekyll_page_boilerplate/version.rb
57
+ homepage: https://github.com/CodeKarmaDev/jekyll-page-boilerplate
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/CodeKarmaDev/jekyll-page-boilerplate
62
+ source_code_uri: https://github.com/CodeKarmaDev/jekyll-page-boilerplate
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.0.8
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A jekyll plugin that create new pages from boilerplates
82
+ test_files: []