jekyll-theme-open-project-helpers 0.1.6 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e26790a1c7302ae34771b65d077202f032b21912
4
- data.tar.gz: 7f5e0cd9bfc7dc2d03a0d4202af8d125952ec301
3
+ metadata.gz: 9651edae0b25bd5fa6a36a40e57bb39983f69559
4
+ data.tar.gz: 5d3c6ac31536983b40e6c65f148fc2c898b2449b
5
5
  SHA512:
6
- metadata.gz: 598f4d1cebd24a0fe19727b3453993d58ef7634841aad33db6dc87452d1db8205118f0253617f7f9a1ece012e2c67bd6b758e9d1191e4ebe70c5767f9d479eb5
7
- data.tar.gz: b2bbb6e08b2c8be67fb716fe020ff614d81aeb36e904a06a213efb5f5f6b349aaa2b9437df2c16f0fe83659574ee67d4b26857ef022ebb6a17b3b2ca2b31f829
6
+ metadata.gz: 51cd731eef63bb7ae0741e42787a7af2bdbb3938374abf6aaec1d19e4b9d893b39c448900b24138351caf16466819a5607e0e966c44d9d2b407382c43620f537
7
+ data.tar.gz: 49e31e2a27dfeb3ef12b9e1853d303dd82be03d1325796d489c224c3ff09bab545a922709fe0627c86d952423755d184a85208661e1fc9b025eb4f68290f83d5
data/develop/release ADDED
@@ -0,0 +1,41 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ # Make sure we're in the project root.
7
+
8
+ cd $(dirname "$0")/..
9
+
10
+ # Make sure the darn thing works? Meh.
11
+ # bundle update
12
+
13
+ # Build a new gem archive.
14
+
15
+ rm -rf jekyll-theme-open-project-helpers-*.gem
16
+ gem build -q jekyll-theme-open-project-helpers.gemspec
17
+
18
+ # Make sure we're on the master branch.
19
+
20
+ (git branch | grep -q 'master') || {
21
+ echo "Only release from the master branch."
22
+ exit 1
23
+ }
24
+
25
+ # Figure out what version we're releasing.
26
+
27
+ tag=v`ls jekyll-theme-open-project-helpers-*.gem | sed 's/^jekyll-theme-open-project-helpers-\(.*\)\.gem$/\1/'`
28
+
29
+ # Make sure we haven't released this version before.
30
+
31
+ git fetch -t origin
32
+
33
+ (git tag -l | grep -q "$tag") && {
34
+ echo "Whoops, there's already a '${tag}' tag."
35
+ exit 1
36
+ }
37
+
38
+ # Tag it and bag it.
39
+
40
+ gem push jekyll-theme-open-project-helpers-*.gem && git tag "$tag" &&
41
+ git push origin master && git push origin "$tag"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jekyll-theme-open-project-helpers'
5
- s.version = '0.1.6'
5
+ s.version = '1.0.0.pre'
6
6
  s.authors = ['Ribose Inc.']
7
7
  s.email = ['open.source@ribose.com']
8
8
 
@@ -12,7 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
14
14
 
15
- s.add_runtime_dependency 'jekyll', '~> 3.7'
15
+ s.add_runtime_dependency 'jekyll', '~> 3.8.3'
16
+ s.add_runtime_dependency 'git'
16
17
  s.add_development_dependency 'rake', '~> 12.0'
17
18
  s.add_development_dependency 'rubocop', '~> 0.50'
18
19
 
@@ -1,18 +1,188 @@
1
1
  require 'digest/md5'
2
+ require 'jekyll-data/reader'
3
+ require 'git'
2
4
 
3
- module Jekyll
4
- # Monkey-patching Site to add a custom property holding combined blog post array
5
- # and speed up generation.
6
5
 
7
- class Site
8
- attr_accessor :posts_combined
6
+ def is_hub(site)
7
+ # If there’re projects defined, we assume it is indeed
8
+ # a Jekyll Open Project hub site.
9
+ if site.collections.key? 'projects'
10
+ if site.collections['projects'] != nil
11
+ if site.collections['projects'].docs.length > 0
12
+ return true
13
+ end
14
+ end
15
+ end
16
+
17
+ return false
18
+ end
19
+
20
+ class CollectionDocReader < Jekyll::DataReader
21
+
22
+ def read(dir, collection)
23
+ read_project_subdir(dir, collection)
24
+ end
25
+
26
+ def read_project_subdir(dir, collection, nested=false)
27
+ return unless File.directory?(dir) && !@entry_filter.symlink?(dir)
28
+
29
+ entries = Dir.chdir(dir) do
30
+ Dir["*.{md,markdown,html}"] + Dir["*"].select { |fn| File.directory?(fn) }
31
+ end
32
+
33
+ entries.each do |entry|
34
+ path = File.join(dir, entry)
9
35
 
10
- def posts_combined
11
- @posts_combined
36
+ if File.directory?(path)
37
+ read_project_subdir(path, collection, nested=true)
38
+ elsif nested or (File.basename(entry, '.*') != 'index')
39
+ doc = Jekyll::Document.new(path, :site => @site, :collection => collection)
40
+ doc.read
41
+ collection.docs << doc
42
+ end
12
43
  end
13
44
  end
14
45
  end
15
46
 
47
+
48
+ #
49
+ # Below deals with fetching each open project’s data from its site’s repo
50
+ # (such as posts, template includes, software and specs)
51
+ # and reading it into 'projects' collection docs.
52
+ #
53
+
54
+ class OpenProjectReader < JekyllData::Reader
55
+
56
+ def read
57
+ super
58
+ if is_hub(@site)
59
+ fetch_and_read_projects
60
+ else
61
+ fetch_and_read_docs
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def fetch_and_read_projects
68
+ project_indexes = @site.collections['projects'].docs.select do |doc|
69
+ pieces = doc.id.split('/')
70
+ pieces.length == 4 and pieces[1] == 'projects' and pieces[3] == 'index'
71
+ end
72
+ project_indexes.each do |project|
73
+ project_path = project.path.split('/')[0..-2].join('/')
74
+
75
+ did_check_out = git_sparse_checkout(
76
+ project_path,
77
+ project['site']['git_repo_url'],
78
+ ['_includes/', '_posts/', '_software/', '_specs/'])
79
+
80
+ if did_check_out
81
+ CollectionDocReader.new(site).read(
82
+ project_path,
83
+ @site.collections['projects'])
84
+ end
85
+ end
86
+ end
87
+
88
+ def fetch_and_read_docs
89
+
90
+ # Software
91
+ software_entry_points = @site.collections['software'].docs.select do |doc|
92
+ pieces = doc.id.split('/')
93
+ product_name = pieces[2]
94
+ last_piece = pieces[-1]
95
+
96
+ doc.data.key?('docs') and
97
+ doc.data['docs']['git_repo_url'] and
98
+ pieces[1] == 'software' and
99
+ last_piece == product_name
100
+ end
101
+ software_entry_points.each do |index_doc|
102
+ item_name = index_doc.id.split('/')[-1]
103
+ docs_path = "#{index_doc.path.split('/')[0..-2].join('/')}/#{item_name}"
104
+
105
+ did_check_out = git_sparse_checkout(
106
+ docs_path,
107
+ index_doc['docs']['git_repo_url'],
108
+ [index_doc['docs']['git_repo_subtree']])
109
+
110
+ if did_check_out
111
+ CollectionDocReader.new(site).read(
112
+ docs_path,
113
+ @site.collections['software'])
114
+ end
115
+ end
116
+
117
+ # Specs
118
+ spec_entry_points = @site.collections['specs'].docs.select do |doc|
119
+ pieces = doc.id.split('/')
120
+ product_name = pieces[2]
121
+ last_piece = pieces[-1]
122
+
123
+ doc.data.key?('docs') and
124
+ doc.data['docs']['git_repo_url'] and
125
+ pieces[1] == 'specs' and
126
+ last_piece == product_name
127
+ end
128
+ spec_entry_points.each do |index_doc|
129
+ item_name = index_doc.id.split('/')[-1]
130
+ docs_path = "#{index_doc.path.split('/')[0..-2].join('/')}/#{item_name}"
131
+
132
+ did_check_out = git_sparse_checkout(
133
+ docs_path,
134
+ index_doc['docs']['git_repo_url'],
135
+ [index_doc['docs']['git_repo_subtree']])
136
+
137
+ if did_check_out
138
+ CollectionDocReader.new(site).read(
139
+ docs_path,
140
+ @site.collections['software'])
141
+ end
142
+ end
143
+ end
144
+
145
+ def git_sparse_checkout(repo_path, remote_url, subtrees)
146
+ # Returns boolean indicating whether the checkout happened
147
+
148
+ git_dir = File.join(repo_path, '.git')
149
+ unless File.exists? git_dir
150
+ repo = Git.init(repo_path)
151
+
152
+ repo.add_remote('origin', remote_url)
153
+
154
+ repo.config('core.sparseCheckout', true)
155
+ open(File.join(git_dir, 'info', 'sparse-checkout'), 'a') { |f|
156
+ subtrees.each { |path|
157
+ f << "#{path}\n"
158
+ }
159
+ }
160
+
161
+ repo.fetch
162
+ repo.reset_hard
163
+ repo.checkout('origin/master', { :f => true })
164
+
165
+ return true
166
+
167
+ else
168
+ return false
169
+
170
+ end
171
+ end
172
+ end
173
+
174
+
175
+ Jekyll::Hooks.register :site, :after_init do |site|
176
+ if site.theme # TODO: Check theme name
177
+ site.reader = OpenProjectReader::new(site)
178
+ end
179
+ end
180
+
181
+
182
+ #
183
+ # Below deals with blog and other indexes
184
+ #
185
+
16
186
  module OpenProjectHelpers
17
187
 
18
188
  # On an open hub site, Jekyll Open Project theme assumes the existence of two types
@@ -23,10 +193,10 @@ module OpenProjectHelpers
23
193
  # and the fact that Jekyll doesn’t intuitively handle nested collections.
24
194
  INDEXES = {
25
195
  "software" => {
26
- :item_test => lambda { |item| item.url.include? '_software' and not item.url.include? '_docs' },
196
+ :item_test => lambda { |item| item.path.include? '/_software' and not item.path.include? '/docs' },
27
197
  },
28
198
  "specs" => {
29
- :item_test => lambda { |item| item.url.include? '_specs' and not item.url.include? '_docs' },
199
+ :item_test => lambda { |item| item.path.include? '/_specs' and not item.path.include? '/docs' },
30
200
  },
31
201
  }
32
202
 
@@ -57,11 +227,7 @@ module OpenProjectHelpers
57
227
  safe true
58
228
 
59
229
  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
-
230
+ if is_hub(site)
65
231
  INDEXES.each do |index_name, params|
66
232
  items = site.collections['projects'].docs.select { |item| params[:item_test].call(item) }
67
233
 
@@ -90,6 +256,7 @@ module OpenProjectHelpers
90
256
  index_name)
91
257
  end
92
258
  end
259
+
93
260
  end
94
261
  end
95
262
  end
@@ -98,34 +265,22 @@ module OpenProjectHelpers
98
265
  # Below passes the `items` variable to normal (unfiltered)
99
266
  # index page layout.
100
267
 
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
268
  class IndexPageGenerator < Jekyll::Generator
115
269
  safe true
116
270
 
117
271
  def generate(site)
118
272
 
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|
273
+ INDEXES.each do |index_name, params|
274
+ if is_hub(site)
124
275
  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
276
+ else
277
+ items = site.collections[index_name].docs.select { |item| params[:item_test].call(item) }
127
278
  end
279
+
280
+ page = site.site_payload["site"]["pages"].detect { |p| p.url == "/#{index_name}/" }
281
+ page.data['items'] = items
128
282
  end
283
+
129
284
  end
130
285
  end
131
286
 
@@ -140,17 +295,13 @@ module OpenProjectHelpers
140
295
  safe true
141
296
 
142
297
  def generate(site)
143
-
144
298
  site_posts = site.posts.docs
145
299
 
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
-
300
+ if is_hub(site)
150
301
  # Get documents representing projects
151
302
  projects = site.collections['projects'].docs.select do |item|
152
303
  pieces = item.url.split('/')
153
- pieces[3] == 'index.html' && pieces[1] == 'projects'
304
+ pieces.length == 4 && pieces[-1] == 'index' && pieces[1] == 'projects'
154
305
  end
155
306
  # Add project name (matches directory name, may differ from title)
156
307
  projects = projects.map do |project|
@@ -169,8 +320,10 @@ module OpenProjectHelpers
169
320
  end
170
321
 
171
322
  posts_combined = (project_posts + site_posts).sort_by(&:date).reverse
323
+
172
324
  else
173
325
  posts_combined = site_posts
326
+
174
327
  end
175
328
 
176
329
  # On each post, replace authors’ emails with corresponding md5 hashes
@@ -186,8 +339,6 @@ module OpenProjectHelpers
186
339
 
187
340
  blog_index = site.site_payload["site"]["pages"].detect { |page| page.url == '/blog/' }
188
341
  blog_index.data['posts_combined'] = posts_combined
189
-
190
- site.posts_combined = posts_combined
191
342
  end
192
343
  end
193
344
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-theme-open-project-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-27 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.7'
19
+ version: 3.8.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.7'
26
+ version: 3.8.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +75,7 @@ extra_rdoc_files: []
61
75
  files:
62
76
  - LICENSE.txt
63
77
  - README.md
78
+ - develop/release
64
79
  - jekyll-theme-open-project-helpers.gemspec
65
80
  - lib/jekyll-theme-open-project-helpers.rb
66
81
  homepage: https://github.com/riboseinc/jekyll-theme-open-project-helpers/
@@ -78,9 +93,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
93
  version: '0'
79
94
  required_rubygems_version: !ruby/object:Gem::Requirement
80
95
  requirements:
81
- - - ">="
96
+ - - ">"
82
97
  - !ruby/object:Gem::Version
83
- version: '0'
98
+ version: 1.3.1
84
99
  requirements: []
85
100
  rubyforge_project:
86
101
  rubygems_version: 2.6.14.1