jekyll-theme-open-project-helpers 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e26790a1c7302ae34771b65d077202f032b21912
4
+ data.tar.gz: 7f5e0cd9bfc7dc2d03a0d4202af8d125952ec301
5
+ SHA512:
6
+ metadata.gz: 598f4d1cebd24a0fe19727b3453993d58ef7634841aad33db6dc87452d1db8205118f0253617f7f9a1ece012e2c67bd6b758e9d1191e4ebe70c5767f9d479eb5
7
+ data.tar.gz: b2bbb6e08b2c8be67fb716fe020ff614d81aeb36e904a06a213efb5f5f6b349aaa2b9437df2c16f0fe83659574ee67d4b26857ef022ebb6a17b3b2ca2b31f829
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ribose
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.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Open Project theme helpers
2
+
3
+ Jekyll plugin for the Open Project gem-based Jekyll theme by Ribose.
4
+
5
+ Currently, its functionality includes filtered tag page generation
6
+ for open software and specification indexes on an open hub site.
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jekyll-theme-open-project-helpers'
5
+ s.version = '0.1.6'
6
+ s.authors = ['Ribose Inc.']
7
+ s.email = ['open.source@ribose.com']
8
+
9
+ s.summary = 'Helpers for the Open Project Jekyll theme'
10
+ s.homepage = 'https://github.com/riboseinc/jekyll-theme-open-project-helpers/'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
14
+
15
+ s.add_runtime_dependency 'jekyll', '~> 3.7'
16
+ s.add_development_dependency 'rake', '~> 12.0'
17
+ s.add_development_dependency 'rubocop', '~> 0.50'
18
+
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,193 @@
1
+ require 'digest/md5'
2
+
3
+ module Jekyll
4
+ # Monkey-patching Site to add a custom property holding combined blog post array
5
+ # and speed up generation.
6
+
7
+ class Site
8
+ attr_accessor :posts_combined
9
+
10
+ def posts_combined
11
+ @posts_combined
12
+ end
13
+ end
14
+ end
15
+
16
+ module OpenProjectHelpers
17
+
18
+ # On an open hub site, Jekyll Open Project theme assumes the existence of two types
19
+ # of item indexes: software and specs, where items are gathered
20
+ # from across open projects in the hub.
21
+ #
22
+ # The need for :item_test arises from our data structure (see Jekyll Open Project theme docs)
23
+ # and the fact that Jekyll doesn’t intuitively handle nested collections.
24
+ INDEXES = {
25
+ "software" => {
26
+ :item_test => lambda { |item| item.url.include? '_software' and not item.url.include? '_docs' },
27
+ },
28
+ "specs" => {
29
+ :item_test => lambda { |item| item.url.include? '_specs' and not item.url.include? '_docs' },
30
+ },
31
+ }
32
+
33
+
34
+ # Each software or spec item can have its tags,
35
+ # and the theme allows to filter each index by a tag.
36
+ # The below generates an additional index page
37
+ # for each tag in an index, like software/Ruby.
38
+ #
39
+ # Note: this expects "_pages/<index page>.html" to be present in site source,
40
+ # so it would fail if theme setup instructions were not followed fully.
41
+
42
+ class FilteredIndexPage < Jekyll::Page
43
+ def initialize(site, base, dir, tag, items, index_page)
44
+ @site = site
45
+ @base = base
46
+ @dir = dir
47
+ @name = 'index.html'
48
+
49
+ self.process(@name)
50
+ self.read_yaml(File.join(base, '_pages'), "#{index_page}.html")
51
+ self.data['tag'] = tag
52
+ self.data['items'] = items
53
+ end
54
+ end
55
+
56
+ class FilteredIndexPageGenerator < Jekyll::Generator
57
+ safe true
58
+
59
+ def generate(site)
60
+
61
+ # If there’s a “projects” collection, we assume it is indeed
62
+ # a Jekyll Open Project hub site.
63
+ if site.collections.key? 'projects'
64
+
65
+ INDEXES.each do |index_name, params|
66
+ items = site.collections['projects'].docs.select { |item| params[:item_test].call(item) }
67
+
68
+ # Creates a data structure like { tag1: [item1, item2], tag2: [item2, item3] }
69
+ tags = {}
70
+ items.each do |item|
71
+ item.data['tags'].each do |tag|
72
+ unless tags.key? tag
73
+ tags[tag] = []
74
+ end
75
+ tags[tag].push(item)
76
+ end
77
+ end
78
+
79
+ # Creates a filtered index page for each tag
80
+ tags.each do |tag, tagged_items|
81
+ site.pages << FilteredIndexPage.new(
82
+ site,
83
+ site.source,
84
+
85
+ # The filtered page will be nested under /<index page>/<tag>.html
86
+ File.join(index_name, tag),
87
+
88
+ tag,
89
+ tagged_items,
90
+ index_name)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+
98
+ # Below passes the `items` variable to normal (unfiltered)
99
+ # index page layout.
100
+
101
+ class IndexPage < Jekyll::Page
102
+ def initialize(site, base, dir, items, index_page)
103
+ @site = site
104
+ @base = base
105
+ @dir = dir
106
+ @name = 'index.html'
107
+
108
+ self.process(@name)
109
+ self.read_yaml(File.join(base, '_pages'), "#{index_page}.html")
110
+ self.data['items'] = items
111
+ end
112
+ end
113
+
114
+ class IndexPageGenerator < Jekyll::Generator
115
+ safe true
116
+
117
+ def generate(site)
118
+
119
+ # If there’s a “projects” collection, we assume it is indeed
120
+ # a Jekyll Open Project hub site.
121
+ if site.collections.key? 'projects'
122
+
123
+ INDEXES.each do |index_name, params|
124
+ items = site.collections['projects'].docs.select { |item| params[:item_test].call(item) }
125
+ page = site.site_payload["site"]["pages"].detect { |p| p.url == "/#{index_name}/" }
126
+ page.data['items'] = items
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+
133
+ # Below passes an array of posts of open hub blog
134
+ # and from each individual project blog, combined and sorted by date,
135
+ # to open hub blog index page.
136
+ #
137
+ # (It also does some processing on the posts.)
138
+
139
+ class BlogIndexGenerator < Jekyll::Generator
140
+ safe true
141
+
142
+ def generate(site)
143
+
144
+ site_posts = site.posts.docs
145
+
146
+ # If there’s a “projects” collection, we assume it is indeed
147
+ # a Jekyll Open Project hub site.
148
+ if site.collections.key? 'projects'
149
+
150
+ # Get documents representing projects
151
+ projects = site.collections['projects'].docs.select do |item|
152
+ pieces = item.url.split('/')
153
+ pieces[3] == 'index.html' && pieces[1] == 'projects'
154
+ end
155
+ # Add project name (matches directory name, may differ from title)
156
+ projects = projects.map do |project|
157
+ project.data['name'] = project.url.split('/')[2]
158
+ project
159
+ end
160
+
161
+ # Get documents representnig posts from each project’s blog
162
+ project_posts = site.collections['projects'].docs.select { |item| item.url.include? '_posts' }
163
+
164
+ # Add parent project’s data hash onto each
165
+ project_posts = project_posts.map do |post|
166
+ project_name = post.url.split('/')[2]
167
+ post.data['parent_project'] = projects.detect { |p| p.data['name'] == project_name }
168
+ post
169
+ end
170
+
171
+ posts_combined = (project_posts + site_posts).sort_by(&:date).reverse
172
+ else
173
+ posts_combined = site_posts
174
+ end
175
+
176
+ # On each post, replace authors’ emails with corresponding md5 hashes
177
+ # suitable for hotlinking authors’ Gravatar profile pictures.
178
+ posts_combined = posts_combined.map do |post|
179
+ if post.data.key? 'author'
180
+ email = post.data['author']['email']
181
+ hash = Digest::MD5.hexdigest(email)
182
+ post.data['author']['email'] = hash
183
+ end
184
+ post
185
+ end
186
+
187
+ blog_index = site.site_payload["site"]["pages"].detect { |page| page.url == '/blog/' }
188
+ blog_index.data['posts_combined'] = posts_combined
189
+
190
+ site.posts_combined = posts_combined
191
+ end
192
+ end
193
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-theme-open-project-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-27 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: '3.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.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: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.50'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.50'
55
+ description:
56
+ email:
57
+ - open.source@ribose.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - jekyll-theme-open-project-helpers.gemspec
65
+ - lib/jekyll-theme-open-project-helpers.rb
66
+ homepage: https://github.com/riboseinc/jekyll-theme-open-project-helpers/
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.6.14.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Helpers for the Open Project Jekyll theme
90
+ test_files: []