jekyll-contentful 0.1.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
+ SHA1:
3
+ metadata.gz: 1dbc8405799ea8061bfbbb46290e94ca5e589143
4
+ data.tar.gz: 1ccb356df17b0d3bc55ecb715808405063fe5bb3
5
+ SHA512:
6
+ metadata.gz: 727ef0245f954390471a1622f048b2b68b75238f0d3bbff1122ec6c9cfd5088952b22b52f225306576a628e1826e52b964eb4f871e4d68475a2f3dae88ffbf3b
7
+ data.tar.gz: 729914866006b502acf3db330155384cb9a6adc96845343b87b30c676c3ff8000865c75118537a586c40799957c2e75656bf20d6fd2aa5c1ec5b8aa43fdc6763
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyllcontentful.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dommmel
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # Jekyll-Contentful
2
+
3
+ Generate Pages for Contentful Entries
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Gemfile:
8
+
9
+ ```ruby
10
+ group :jekyll_plugins do
11
+ gem "jekyll-contentful"
12
+ end
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Alternatively install the gem yourself as:
20
+
21
+ $ gem install jekyll-contentful
22
+
23
+ and put this in your ``_config.yml``
24
+
25
+ ```yaml
26
+ gems: [jekyll-contentful]
27
+ # This will require each of these gems automatically.
28
+ ```
29
+
30
+ ## Configuration
31
+
32
+ Configure in your _config.yml file
33
+
34
+ ```yaml
35
+ contentful:
36
+ access_token: 'YOUR_TOKEN'
37
+ space: 'SPACE'
38
+ content_types:
39
+ - "First Content Type"
40
+ - "Second Content Type"
41
+ localization:
42
+ - locale: en-US
43
+ url_prefix: "en"
44
+ - locale: de-DE
45
+ url_prefix: "de"
46
+ ```
47
+
48
+ #### Content Fields:
49
+ All Entry fields can be used inside the layout templates as {{ page.fieldname }}
50
+
51
+ #### ULRs and Layouts:
52
+
53
+ Let's say you have a content type named "Blog Post" with an entry that has its title field set to "Awesome Title".
54
+ The plugin will generate a page using the "blog-post.html" layout at the url: /en/blog-post/awesome-title/index.html
55
+
56
+ If no layout named "blog-post.html" can be found the plugin will fallback to use the "default.html" layout.
57
+
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll-contentful/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-contentful"
8
+ spec.version = Jekyll::Contentful::VERSION
9
+ spec.authors = ["Dommmel"]
10
+ spec.email = ["dommmel@gmail.com"]
11
+
12
+ spec.summary = %q{jekyll plugin that generates pages from contentful entries}
13
+ spec.description = %q{jekyll plugin that generates pages from contentful entries}
14
+ spec.homepage = "https://github.com/dommmel/jekyll-contentful"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'jekyll'
21
+ spec.add_dependency "contentful"
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,99 @@
1
+ require "jekyll-contentful/version"
2
+ require "jekyll"
3
+ require "contentful"
4
+
5
+ #
6
+ # Configure in your _config.yml file
7
+ #
8
+ # contentful:
9
+ # access_token: 'YOUR_TOKEN'
10
+ # space: 'SPACE'
11
+ # content_types:
12
+ # - "First Content Type"
13
+ # - "Second Content Type"
14
+ # localization:
15
+ # - locale: en-US
16
+ # url_prefix: "en"
17
+ # - locale: de-DE
18
+ # url_prefix: "de"
19
+ #
20
+ #
21
+ # Content Fields:
22
+ #
23
+ # All Entry fields can be used inside the layout templates as {{ page.fieldname }}
24
+ #
25
+ # ULRs and Layouts:
26
+ #
27
+ # Let's say you have a content type named "Blog Post" with an entry that has its title field set to "Awesome Title".
28
+ # The plugin will generate a page using the "blog-post.html" layout at the url: /en/blog-post/awesome-title/index.html
29
+ #
30
+ # If no layout named "blog-post.html" can be found the plugin will fallback to use the "default.html" layout.
31
+ #
32
+
33
+ module Jekyll
34
+ class ContentfulEntryPage < Page
35
+ def initialize(site, fields, content_type_name, prefix)
36
+
37
+ @site = site
38
+ @base = site.source
39
+ @name = 'index.html'
40
+
41
+ content_type_slug = Utils.slugify content_type_name
42
+
43
+ layout_filename = site.layouts.key?(content_type_slug) ? "#{content_type_slug}.html" : "default.html"
44
+ self.read_yaml(File.join(@base, '_layouts'), layout_filename)
45
+
46
+ # stringify hash keys
47
+ fields = fields.inject({}){|x,(k,v)| x[k.to_s] = v; x}
48
+
49
+ # merge data
50
+ self.data.merge!(fields)
51
+
52
+ # If there is a title fields make it the url
53
+ page_title_slug = Utils.slugify(self.data["title"] || "")
54
+ @dir = "#{prefix}/#{content_type_slug}/#{page_title_slug}"
55
+
56
+ self.process(@name)
57
+ end
58
+ end
59
+
60
+ class ContentfulEntryPageGenerator < Generator
61
+ safe true
62
+
63
+ def generate(site)
64
+
65
+ client = ::Contentful::Client.new(
66
+ access_token: site.config['contentful']['access_token'],
67
+ space: site.config['contentful']['space']
68
+ )
69
+
70
+ # Loop over all content types
71
+ site.config['contentful']['content_types'].each do |content_type_name|
72
+ # Get ID for content type name
73
+ content_type = client.content_types(name: content_type_name).first
74
+
75
+ throw "Content_type \'#{content_type_name}\' does not exist." if content_type.nil?
76
+
77
+
78
+ localization = site.config['contentful']['localization'] || [{locale: nil, url_prefix: ""}]
79
+
80
+ # Get all entries of content type
81
+ sync = client.sync(initial: true, type: 'Entry', content_type: content_type.id)
82
+
83
+ sync.each_page do |page|
84
+ puts "Generating #{page.items.count} entries of type \'#{content_type_name}\' (#{content_type.id})"
85
+
86
+ page.items.each do |item|
87
+ localization.each do |loc|
88
+ fields = loc["locale"].nil? ? item.fields : item.fields(loc["locale"])
89
+ site.pages << ContentfulEntryPage.new(site, fields, content_type_name, "/#{loc['url_prefix']}") unless fields.nil?
90
+ end
91
+
92
+ end
93
+ end
94
+
95
+ end
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module Contentful
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-contentful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dommmel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: contentful
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: jekyll plugin that generates pages from contentful entries
70
+ email:
71
+ - dommmel@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - jekyll-contentful.gemspec
82
+ - lib/jekyll-contentful.rb
83
+ - lib/jekyll-contentful/version.rb
84
+ homepage: https://github.com/dommmel/jekyll-contentful
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.4.5
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: jekyll plugin that generates pages from contentful entries
108
+ test_files: []