jekyll-api 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b656a91c009904f95b4956eb10729f36c4e21abb
4
+ data.tar.gz: 4236602b696a518f49716c1ed897e6ff8aea6125
5
+ SHA512:
6
+ metadata.gz: b198d7fdb00e690a68153ff6d25600923a2b3b852697b3007fe1449967f1514507bff4c1329db5d58f1f251fcc43060393c36cf4a67f98aeb21eb52bcbfae947
7
+ data.tar.gz: ba07b2fb4383520ea1aebeb3c01de06088643d5cea6d34024d0afb56a5f556e5e8c12e59c54c35ebf70e67b12e5949c33bbdc38063712bbc202a9ae2d4cc58c5
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /_site/
2
+ /.bundle/
3
+ /Gemfile.lock
4
+ /pkg/
5
+ /test/fixtures/**/data.json
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Jekyll::API
2
+
3
+ Create APIs from Jekyll page data.
4
+
5
+ ## Installation
6
+
7
+ Follow [Jekyll's instructions for installing Jekyll plugins](http://jekyllrb.com/docs/plugins/#installing-a-plugin). The **Jekyll::API** plugin is available from the `jekyll-api` gem.
8
+
9
+ ## Usage
10
+
11
+ 1. Define data as front-matter in your Markdown Jekyll pages.
12
+ 2. Enjoy the API.
13
+
14
+ For example, the **Jekyll::API** plugin will generate a `/people/jill/data.json` file
15
+
16
+ ```json
17
+ {
18
+ "title": "Jill"
19
+ }
20
+ ```
21
+
22
+ from the Jekyll page data in `/people/jill.md`.
23
+ ```yaml
24
+ ---
25
+ title: Jill
26
+ ---
27
+ Hi, my name is {{ page.title }}
28
+ ```
29
+
30
+ If you set `permalink: pretty` in `_config.yml`, the resulting HTTP endpoints will be:
31
+ * HTML - `/people/jill/`
32
+ * JSON - `/people/jill/data.json`
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it (https://github.com/gregoryjscott/jekyll-api/fork).
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
39
+ 4. Push to the branch (`git push origin my-new-feature`).
40
+ 5. Create a new Pull Request.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ desc 'Run tests'
4
+ task :test do
5
+ system 'ruby -Ilib test/jekyll/api_test.rb'
6
+ end
7
+
8
+ task :default => :test
@@ -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/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = 'jekyll-api'
9
+ spec.version = Jekyll::API::VERSION
10
+ spec.authors = ['Greg Scott']
11
+ spec.email = ['i@gregoryjscott.com']
12
+ spec.summary = %q{Create APIs from Jekyll page data.}
13
+ spec.homepage = 'https://github.com/gregoryjscott/jekyll-api'
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.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'jekyll', '~> 2.5'
24
+
25
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module API
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'fileutils'
2
+
3
+ module Jekyll
4
+ module API
5
+ class Writer < Jekyll::Generator
6
+
7
+ def generate(site)
8
+ @site = site
9
+ Dir.chdir(@site.source) { write_json }
10
+ end
11
+
12
+ def write_json
13
+ @site.pages.each do |page|
14
+ page_dir = File.dirname(page.path)
15
+ page_name = File.basename(page.path, ".*")
16
+ sub_dir = ''
17
+ sub_dir = File.join(sub_dir, page_dir) unless page_dir == '.'
18
+ sub_dir = File.join(sub_dir, page_name) unless page_name == 'index'
19
+
20
+ path = @site.source
21
+ path = File.join(path, sub_dir) unless sub_dir == ''
22
+ FileUtils.mkdir_p(path) unless Dir.exists?(path)
23
+
24
+ name = 'data.json'
25
+ File.write(File.join(path, name), JSON.dump(page.data))
26
+ json_file = Jekyll::StaticFile.new(@site, @site.source, sub_dir, name)
27
+ @site.static_files << json_file
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
data/lib/jekyll/api.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'jekyll'
2
+ require 'jekyll/api/version'
3
+ require 'jekyll/api/writer'
@@ -0,0 +1,4 @@
1
+ ---
2
+ title: Test
3
+ ---
4
+ # {{ page.title }}
@@ -0,0 +1,4 @@
1
+ ---
2
+ title: Jill
3
+ ---
4
+ Hi, my name is {{ page.title }}
@@ -0,0 +1,34 @@
1
+ require 'jekyll/api'
2
+ require 'minitest/autorun'
3
+
4
+ describe 'Jekyll::API' 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
+ clean
18
+ site.process
19
+ end
20
+
21
+ it 'creates JSON files for all pages' do
22
+ json_files_count = json_files.count { |file| File.file?(file) }
23
+ assert_equal site.pages.count, json_files_count
24
+ end
25
+
26
+ def json_files
27
+ Dir[File.join('_site', '**', 'data.json')]
28
+ end
29
+
30
+ def clean
31
+ json_files.each { |json_file| FileUtils.rm(json_file) }
32
+ end
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-api
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-12-04 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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-api.gemspec
68
+ - lib/jekyll/api.rb
69
+ - lib/jekyll/api/version.rb
70
+ - lib/jekyll/api/writer.rb
71
+ - test/fixtures/index.md
72
+ - test/fixtures/people/jill.md
73
+ - test/jekyll/api_test.rb
74
+ homepage: https://github.com/gregoryjscott/jekyll-api
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Create APIs from Jekyll page data.
98
+ test_files:
99
+ - test/fixtures/index.md
100
+ - test/fixtures/people/jill.md
101
+ - test/jekyll/api_test.rb