jekyll-load 0.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 +7 -0
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +21 -0
- data/Rakefile +8 -0
- data/jekyll-load.gemspec +25 -0
- data/lib/jekyll/load.rb +2 -0
- data/lib/jekyll/load/loader.rb +54 -0
- data/lib/jekyll/load/version.rb +5 -0
- data/test/fixtures/_data/about.yml +1 -0
- data/test/fixtures/_data/index.yml +1 -0
- data/test/fixtures/_data/people/index.yml +1 -0
- data/test/fixtures/_data/people/jack.yml +1 -0
- data/test/fixtures/_data/people/jill.yml +1 -0
- data/test/fixtures/about.md +3 -0
- data/test/fixtures/index.md +3 -0
- data/test/fixtures/people/index.md +3 -0
- data/test/fixtures/people/jack.md +3 -0
- data/test/fixtures/people/jill.md +3 -0
- data/test/jekyll/load_test.rb +56 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a682d2628712f40d9119aebb9fd0f6f2b347f9f
|
4
|
+
data.tar.gz: efd187ad30e152ed5baf3947fd7ed50c96d97dd0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 56689e6687da8f337b5f4c7b2e4530d253a580080b61b42dac654246d0ac823568925cbbe02e199b86a1eae3da33a0477887d77d4d536c49264a7d2e15e4b9aa
|
7
|
+
data.tar.gz: df1a061516a2df18feef48ec10951783f3d4f5d333667bfd7af429119b192ff1cec9ec0d1a8ee312a4926431dd0e7708f61baaf58221f4facae800b9216b19bc
|
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,21 @@
|
|
1
|
+
# Jekyll::Load
|
2
|
+
|
3
|
+
Loads data into Jekyll pages.
|
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 `_data` directory in your Jekyll project.
|
12
|
+
2. Inside the `_data` directory, create `.yml` files that correspond to your `.md` Jekyll pages. For example, if you have a `/people/jill.md` Jekyll page then create a `_data/people/jill.yml` file.
|
13
|
+
3. Inside the `.yml` files, define data that will be loaded into the corresponding Jekyll pages.
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it (https://github.com/gregoryjscott/jekyll-load/fork).
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
21
|
+
5. Create a new Pull Request.
|
data/Rakefile
ADDED
data/jekyll-load.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/load/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = 'jekyll-load'
|
9
|
+
spec.version = Jekyll::Load::VERSION
|
10
|
+
spec.authors = ['Greg Scott']
|
11
|
+
spec.email = ['i@gregoryjscott.com']
|
12
|
+
spec.summary = %q{Loads data into Jekyll pages.}
|
13
|
+
spec.homepage = 'https://github.com/gregoryjscott/jekyll-load'
|
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/load.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Load
|
5
|
+
class Loader < Jekyll::Generator
|
6
|
+
|
7
|
+
priority :high
|
8
|
+
|
9
|
+
def generate(site)
|
10
|
+
@site = site
|
11
|
+
Dir.chdir(@site.source) { load_pages }
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_pages
|
15
|
+
data_files = Dir[File.join('_data', '**', '*.yml')]
|
16
|
+
data_files.each do |data_file|
|
17
|
+
data = YAML.load_file(data_file)
|
18
|
+
data = merge_data data_file, data
|
19
|
+
add_to_index data_file, data unless is_index data_file
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def merge_data(data_file, data)
|
24
|
+
page = find_page(data_file)
|
25
|
+
page.data.merge! data
|
26
|
+
page.data['url'] = page.url
|
27
|
+
page.data
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_page(data_file)
|
31
|
+
path = data_file.gsub("_data#{File::SEPARATOR}", '').gsub('.yml', '.md')
|
32
|
+
@site.pages.detect { |page| page.path == path }
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_to_index(data_file, data)
|
36
|
+
page = find_corresponding_index data_file
|
37
|
+
page.data['items'] = [] if page.data['items'].nil?
|
38
|
+
page.data['items'].push data
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_corresponding_index(data_file)
|
42
|
+
path = 'index.md'
|
43
|
+
nesting = data_file.match(/_data\/(?<resource>.+)\//)
|
44
|
+
path = File.join nesting[1], path unless nesting.nil?
|
45
|
+
page = @site.pages.detect { |page| page.path == path }
|
46
|
+
end
|
47
|
+
|
48
|
+
def is_index(data_file)
|
49
|
+
data_file.end_with? 'index.yml'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
data: this is data
|
@@ -0,0 +1 @@
|
|
1
|
+
data: this is data
|
@@ -0,0 +1 @@
|
|
1
|
+
data: this is data
|
@@ -0,0 +1 @@
|
|
1
|
+
data: this is data
|
@@ -0,0 +1 @@
|
|
1
|
+
data: this is data
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'jekyll/load'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
describe 'Load' do
|
5
|
+
|
6
|
+
let(:config) do
|
7
|
+
Jekyll.configuration({
|
8
|
+
'source' => 'test/fixtures',
|
9
|
+
'permalink' => 'pretty',
|
10
|
+
'quiet' => true
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:site) { Jekyll::Site.new(config) }
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
site.process
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'loads data into pages' do
|
21
|
+
site.pages.each do |page|
|
22
|
+
assert_equal 'this is data', page.data['data']
|
23
|
+
assert_equal 'this is front matter', page.data['front matter']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'adds item list to index page' do
|
28
|
+
page = site.pages.detect { |page| page.path == 'index.md' }
|
29
|
+
assert_equal 1, page.data['items'].count
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'adds item list to nested index pages' do
|
33
|
+
page = site.pages.detect { |page| page.path == 'people/index.md' }
|
34
|
+
assert_equal 2, page.data['items'].count
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'puts page data into items' do
|
38
|
+
pages = site.pages.select { |page| page.path.end_with? 'index.md' }
|
39
|
+
pages.each do |page|
|
40
|
+
page.data['items'].each do |item|
|
41
|
+
assert_equal 'this is data', item['data']
|
42
|
+
assert_equal 'this is front matter', item['front matter']
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'adds page url to items' do
|
48
|
+
pages = site.pages.select { |page| page.path.end_with? 'index.md' }
|
49
|
+
pages.each do |page|
|
50
|
+
page.data['items'].each do |item|
|
51
|
+
assert_instance_of String, item['url']
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-load
|
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-29 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-load.gemspec
|
68
|
+
- lib/jekyll/load.rb
|
69
|
+
- lib/jekyll/load/loader.rb
|
70
|
+
- lib/jekyll/load/version.rb
|
71
|
+
- test/fixtures/_data/about.yml
|
72
|
+
- test/fixtures/_data/index.yml
|
73
|
+
- test/fixtures/_data/people/index.yml
|
74
|
+
- test/fixtures/_data/people/jack.yml
|
75
|
+
- test/fixtures/_data/people/jill.yml
|
76
|
+
- test/fixtures/about.md
|
77
|
+
- test/fixtures/index.md
|
78
|
+
- test/fixtures/people/index.md
|
79
|
+
- test/fixtures/people/jack.md
|
80
|
+
- test/fixtures/people/jill.md
|
81
|
+
- test/jekyll/load_test.rb
|
82
|
+
homepage: https://github.com/gregoryjscott/jekyll-load
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Loads data into Jekyll pages.
|
106
|
+
test_files:
|
107
|
+
- test/fixtures/_data/about.yml
|
108
|
+
- test/fixtures/_data/index.yml
|
109
|
+
- test/fixtures/_data/people/index.yml
|
110
|
+
- test/fixtures/_data/people/jack.yml
|
111
|
+
- test/fixtures/_data/people/jill.yml
|
112
|
+
- test/fixtures/about.md
|
113
|
+
- test/fixtures/index.md
|
114
|
+
- test/fixtures/people/index.md
|
115
|
+
- test/fixtures/people/jack.md
|
116
|
+
- test/fixtures/people/jill.md
|
117
|
+
- test/jekyll/load_test.rb
|