jekyll-prep 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +8 -0
- data/jekyll-prep.gemspec +25 -0
- data/lib/jekyll/prep.rb +3 -0
- data/lib/jekyll/prep/runner.rb +48 -0
- data/lib/jekyll/prep/script.rb +8 -0
- data/lib/jekyll/prep/version.rb +5 -0
- data/test/fixtures/_prep/index.rb +9 -0
- data/test/fixtures/_prep/people/jill.rb +11 -0
- data/test/fixtures/about.md +2 -0
- data/test/fixtures/index.md +2 -0
- data/test/fixtures/people/index.md +2 -0
- data/test/fixtures/people/jack.md +2 -0
- data/test/fixtures/people/jill.md +2 -0
- data/test/jekyll/prep_test.rb +34 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b9e910451c643dec5a83d1f4f898ce6e9ecce92
|
4
|
+
data.tar.gz: 976d2ab8a82db6575ad518400ef43229a210b7ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ffe8268dcb135a8035fea7979077071e84c3c09624853f0eb8d642729112bcde7887e254f21f0a43ba71c8df4eb524360c092f8069046028805a3a21bf99ab52
|
7
|
+
data.tar.gz: 05f0c2d1a5271124cb316b79cd85e3e2873b29e788ce674ad675b18bc0d9872bc126410e2256675b1225cf1cae46eb309d85b3e5db662ba67afe545f5a56ad1c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Greg Scott
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Jekyll::Prep
|
2
|
+
|
3
|
+
Prepare Jekyll page data using Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
See [Jekyll's documentation for installing Jekyll plugins](http://jekyllrb.com/docs/plugins/#installing-a-plugin).
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
1. Create a `_prep` directory in your Jekyll project.
|
12
|
+
2. Inside the `_prep` directory, create `.rb` files that correspond to your `.md` Jekyll pages. For example, if you have a `/people/jill.md` Jekyll page then create a `_prep/people/jill.rb` file.
|
13
|
+
3. Inside the `.rb` files, define subclasses of `Jekyll::Prep::Script` that define a `prepare` method that will receive an instance of Jekyll::Page. The subclass namespaces must align with the `.rb` file paths minus the leading underscore. For example, the file `_prep/people/jill.rb` should contain `Prep::People::Jill`.
|
14
|
+
4. Inside the prepare methods, do whatever you want to `page.data`.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# _prep/people/jill.rb
|
18
|
+
|
19
|
+
module Prep
|
20
|
+
module People
|
21
|
+
class Jill < Jekyll::Prep::Script
|
22
|
+
|
23
|
+
def prepare(page)
|
24
|
+
page.data['something new'] = 'was added during prep'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it (https://github.com/gregoryjscott/jekyll-prep/fork).
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
38
|
+
5. Create a new Pull Request.
|
data/Rakefile
ADDED
data/jekyll-prep.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll/prep/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = 'jekyll-prep'
|
9
|
+
spec.version = Jekyll::Prep::VERSION
|
10
|
+
spec.authors = ['Greg Scott']
|
11
|
+
spec.email = ['i@gregoryjscott.com']
|
12
|
+
spec.summary = %q{Prepare Jekyll page data using Ruby.}
|
13
|
+
spec.homepage = 'https://github.com/gregoryjscott/jekyll-prep'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'jekyll', '~> 2.5'
|
24
|
+
|
25
|
+
end
|
data/lib/jekyll/prep.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Prep
|
5
|
+
class Runner < Jekyll::Generator
|
6
|
+
|
7
|
+
def generate(site)
|
8
|
+
@site = site
|
9
|
+
Dir.chdir(@site.source) { prepare_pages }
|
10
|
+
end
|
11
|
+
|
12
|
+
def prepare_pages
|
13
|
+
require_files
|
14
|
+
scripts = instantiate_scripts
|
15
|
+
|
16
|
+
@site.pages.each do |page|
|
17
|
+
script = find_script(page, scripts)
|
18
|
+
script.prepare(page) unless script.nil?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def require_files
|
23
|
+
files = Dir[File.join('_prep', '**', '*.rb')]
|
24
|
+
files.each do |file|
|
25
|
+
path = File.expand_path(file)
|
26
|
+
require path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def instantiate_scripts
|
31
|
+
@site.instantiate_subclasses(Jekyll::Prep::Script)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_script(page, scripts)
|
35
|
+
namespace = 'prep'
|
36
|
+
|
37
|
+
path = File.dirname(page.path).gsub(File::SEPARATOR, '::')
|
38
|
+
namespace << "::#{path}" unless path == '.'
|
39
|
+
|
40
|
+
class_name = File.basename(page.path, '.*')
|
41
|
+
namespace << "::#{class_name}"
|
42
|
+
|
43
|
+
scripts.detect { |script| script.class.to_s.downcase == namespace }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'jekyll/prep'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
describe 'Prep' do
|
5
|
+
|
6
|
+
let(:config) do
|
7
|
+
Jekyll.configuration({
|
8
|
+
'source' => 'test/fixtures',
|
9
|
+
'quiet' => true
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:site) { Jekyll::Site.new(config) }
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
site.process
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'prepares pages' do
|
20
|
+
page = site.pages.detect { |page| page.path == 'index.md' }
|
21
|
+
assert page.data['prepared']
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'prepares nested pages' do
|
25
|
+
page = site.pages.detect { |page| page.path == 'people/jill.md' }
|
26
|
+
assert page.data['prepared']
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'leaves other pages alone' do
|
30
|
+
page = site.pages.detect { |page| page.path == 'people/jack.md' }
|
31
|
+
assert_nil page.data['prepared']
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-prep
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Greg Scott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jekyll
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.5'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- i@gregoryjscott.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- jekyll-prep.gemspec
|
68
|
+
- lib/jekyll/prep.rb
|
69
|
+
- lib/jekyll/prep/runner.rb
|
70
|
+
- lib/jekyll/prep/script.rb
|
71
|
+
- lib/jekyll/prep/version.rb
|
72
|
+
- test/fixtures/_prep/index.rb
|
73
|
+
- test/fixtures/_prep/people/jill.rb
|
74
|
+
- test/fixtures/about.md
|
75
|
+
- test/fixtures/index.md
|
76
|
+
- test/fixtures/people/index.md
|
77
|
+
- test/fixtures/people/jack.md
|
78
|
+
- test/fixtures/people/jill.md
|
79
|
+
- test/jekyll/prep_test.rb
|
80
|
+
homepage: https://github.com/gregoryjscott/jekyll-prep
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.2.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Prepare Jekyll page data using Ruby.
|
104
|
+
test_files:
|
105
|
+
- test/fixtures/_prep/index.rb
|
106
|
+
- test/fixtures/_prep/people/jill.rb
|
107
|
+
- test/fixtures/about.md
|
108
|
+
- test/fixtures/index.md
|
109
|
+
- test/fixtures/people/index.md
|
110
|
+
- test/fixtures/people/jack.md
|
111
|
+
- test/fixtures/people/jill.md
|
112
|
+
- test/jekyll/prep_test.rb
|