jekyll-theme-open-project-helpers 2.1.4 → 2.1.8

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
  SHA256:
3
- metadata.gz: 3b66bfdb58fa9bd277603af3c29b2736c8af021a144eaa150c59285fa41804ad
4
- data.tar.gz: f6c21cb54b396ef4ee17869e5539ca961c9485f669d1370e4071bc5e05034369
3
+ metadata.gz: 5340ebd6b73a77f544854b7425860b5a2fa78ae1508182b0fa53f2aaa6002906
4
+ data.tar.gz: 2f9025c1a872c6176924c2f936c9bc1fdb7f14c5ce272da54a96ded564528122
5
5
  SHA512:
6
- metadata.gz: 521ab65d046b3605ad8efbdb113f9a387986331c23421db0f14afe8429a9a28d4e4bce191275936b59471396541811f1aa7f0b1bd1d964ae08cee7fc227d635a
7
- data.tar.gz: fbcbc3022c5930db262ea81afd94ac54544b4c32c817ad2e40f28b893cecc143bb473e66dedeec81a89c9a1585e2ba7cb1f61609a578a5528a1c8bcf11acc5a1
6
+ metadata.gz: 992ce56cd7eafea9d7167384a227eaff95d3dc20bd368e277f386238b13725db49662185aef4f0f415f28784fe392036bf01196af7d715fb3b1790f4ec66848e
7
+ data.tar.gz: 9e6d476f0a89b3aee43f1c3e5d0becc5ca2b3ee3d297eb371143587ae19d7182248fd3c6c1c14fe69bfda241e1522a062fcd363dedab3273ee05a5fc323fbb1e
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /Gemfile.lock
2
+ /.rubocop-https*
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ inherit_from:
4
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
5
+
6
+ # local repo-specific modifications
7
+ # ...
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 2.5
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ Encoding.default_external = Encoding::UTF_8
2
+ Encoding.default_internal = Encoding::UTF_8
3
+
4
+ source "https://rubygems.org"
5
+
6
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -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 = '2.1.4'
5
+ s.version = '2.1.8'
6
6
  s.authors = ['Ribose Inc.']
7
7
  s.email = ['open.source@ribose.com']
8
8
 
@@ -6,7 +6,9 @@ module Jekyll
6
6
  DEFAULT_DOCS_SUBTREE = 'docs'
7
7
 
8
8
  DEFAULT_REPO_REMOTE_NAME = 'origin'
9
- DEFAULT_REPO_BRANCH = 'master'
9
+ DEFAULT_REPO_BRANCH = 'main'
10
+ # Can be overridden by default_repo_branch in site config.
11
+ # Used by shallow_git_checkout.
10
12
 
11
13
  class NonLiquidDocument < Jekyll::Document
12
14
  def render_with_liquid?
@@ -42,12 +44,14 @@ module Jekyll
42
44
  doc.read
43
45
 
44
46
  # Add document to Jekyll document database if it refers to software or spec
45
- # (as opposed to be some nested document like README)
46
- if (doc.url.split('/').size == 4) or (doc.url.split('/').size == 5 and collection.label === 'projects')
47
+ # (as opposed to be some random nested document within repository source, like a README)
48
+ doc_url_parts = doc.url.split('/')
49
+ Jekyll.logger.debug("OPF:", "Reading document in collection #{collection.label} with URL #{doc.url} (#{doc_url_parts.size} parts)")
50
+ if collection.label != 'projects' or doc_url_parts.size == 5
47
51
  Jekyll.logger.debug("OPF:", "Adding document with URL: #{doc.url}")
48
52
  collection.docs << doc
49
53
  else
50
- Jekyll.logger.debug("OPF:", "Did NOT add document with URL (nesting level doesn’t match): #{doc.url}")
54
+ Jekyll.logger.debug("OPF:", "Did NOT add document with URL (possibly nesting level doesn’t match): #{doc.url}")
51
55
  end
52
56
  else
53
57
  Jekyll.logger.debug("OPF:", "Adding static file: #{path}")
@@ -93,7 +97,8 @@ module Jekyll
93
97
  git_shallow_checkout(
94
98
  File.join(@site.source, 'parent-hub'),
95
99
  @site.config['parent_hub']['git_repo_url'],
96
- ['assets', 'title.html'])
100
+ ['assets', 'title.html'],
101
+ @site.config['parent_hub']['git_repo_branch'])
97
102
  end
98
103
  end
99
104
 
@@ -108,7 +113,8 @@ module Jekyll
108
113
  git_shallow_checkout(
109
114
  project_path,
110
115
  project['site']['git_repo_url'],
111
- ['assets', '_posts', '_software', '_specs'])
116
+ ['assets', '_posts', '_software', '_specs'],
117
+ project['site']['git_repo_branch'])
112
118
 
113
119
 
114
120
  Jekyll.logger.debug("OPF:", "Reading files in project #{project_path}")
@@ -129,6 +135,7 @@ module Jekyll
129
135
  src = index_doc.data['spec_source']
130
136
  repo_url = src['git_repo_url']
131
137
  repo_subtree = src['git_repo_subtree']
138
+ repo_branch = src['git_repo_branch']
132
139
  build = src['build']
133
140
  engine = build['engine']
134
141
  engine_opts = build['options'] || {}
@@ -140,13 +147,9 @@ module Jekyll
140
147
  spec_checkout_path
141
148
  end
142
149
 
143
- repo_checkout = nil
144
- begin
145
- repo_checkout = git_shallow_checkout(spec_checkout_path, repo_url, [repo_subtree])
146
- rescue
147
- end
150
+ repo_checkout = git_shallow_checkout(spec_checkout_path, repo_url, [repo_subtree], repo_branch)
148
151
 
149
- if repo_checkout
152
+ if repo_checkout[:success]
150
153
  if build_pages
151
154
  builder = Jekyll::OpenProjectHelpers::SpecBuilder::new(
152
155
  @site,
@@ -217,19 +220,17 @@ module Jekyll
217
220
 
218
221
  docs = index_doc.data['docs']
219
222
  main_repo = index_doc.data['repo_url']
223
+ main_repo_branch = index_doc.data['repo_branch']
220
224
 
221
225
  sw_docs_repo = (if docs then docs['git_repo_url'] end) || main_repo
222
226
  sw_docs_subtree = (if docs then docs['git_repo_subtree'] end) || DEFAULT_DOCS_SUBTREE
227
+ sw_docs_branch = (if docs then docs['git_repo_branch'] end) || main_repo_branch
223
228
 
224
229
  docs_path = "#{index_doc.path.split('/')[0..-2].join('/')}/#{item_name}"
225
230
 
226
- sw_docs_checkout = nil
227
- begin
228
- sw_docs_checkout = git_shallow_checkout(docs_path, sw_docs_repo, [sw_docs_subtree])
229
- rescue
230
- end
231
+ sw_docs_checkout = git_shallow_checkout(docs_path, sw_docs_repo, [sw_docs_subtree], sw_docs_branch)
231
232
 
232
- if sw_docs_checkout
233
+ if sw_docs_checkout[:success]
233
234
  CollectionDocReader.new(site).read(
234
235
  docs_path,
235
236
  @site.collections[collection_name])
@@ -238,9 +239,9 @@ module Jekyll
238
239
  # Get last repository modification timestamp.
239
240
  # Fetch the repository for that purpose,
240
241
  # unless it’s the same as the repo where docs are.
241
- if sw_docs_checkout == nil or sw_docs_repo != main_repo
242
+ if !sw_docs_checkout[:success] or sw_docs_repo != main_repo
242
243
  repo_path = "#{index_doc.path.split('/')[0..-2].join('/')}/_#{item_name}_repo"
243
- repo_checkout = git_shallow_checkout(repo_path, main_repo)
244
+ repo_checkout = git_shallow_checkout(repo_path, main_repo, [], main_repo_branch)
244
245
  index_doc.merge_data!({ 'last_update' => repo_checkout[:modified_at] })
245
246
  else
246
247
  index_doc.merge_data!({ 'last_update' => sw_docs_checkout[:modified_at] })
@@ -248,7 +249,7 @@ module Jekyll
248
249
  end
249
250
  end
250
251
 
251
- def git_shallow_checkout(repo_path, remote_url, sparse_subtrees=[])
252
+ def git_shallow_checkout(repo_path, remote_url, sparse_subtrees, branch_name)
252
253
  # Returns hash with timestamp of latest repo commit
253
254
  # and boolean signifying whether new repo has been initialized
254
255
  # in the process of pulling the data.
@@ -285,6 +286,7 @@ module Jekyll
285
286
  end
286
287
 
287
288
  refresh_condition = @@siteconfig['refresh_remote_data'] || 'last-resort'
289
+ repo_branch = branch_name || @@siteconfig['default_repo_branch'] || DEFAULT_REPO_BRANCH
288
290
 
289
291
  unless ['always', 'last-resort', 'skip'].include?(refresh_condition)
290
292
  raise RuntimeError.new('Invalid refresh_remote_data value in site’s _config.yml!')
@@ -293,23 +295,42 @@ module Jekyll
293
295
  if refresh_condition == 'always'
294
296
  repo.fetch(DEFAULT_REPO_REMOTE_NAME, { :depth => 1 })
295
297
  repo.reset_hard
296
- repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{DEFAULT_REPO_BRANCH}", { :f => true })
298
+ repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{repo_branch}", { :f => true })
297
299
 
298
300
  elsif refresh_condition == 'last-resort'
301
+ # This is the default case.
302
+
299
303
  begin
300
- repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{DEFAULT_REPO_BRANCH}", { :f => true })
304
+ # Let’s try in case this repo has been fetched before (this would never be the case on CI though)
305
+ repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{repo_branch}", { :f => true })
301
306
  rescue Exception => e
302
- if e.message.include? "Sparse checkout leaves no entry on working directory"
303
- # Supposedly, software docs are missing! No big deal.
307
+ if is_sparse_checkout_error(e, sparse_subtrees)
308
+ # Silence errors caused by nonexistent sparse checkout directories
304
309
  return {
305
310
  :success => false,
306
311
  :newly_initialized => nil,
307
312
  :modified_at => nil,
308
313
  }
309
314
  else
315
+ # In case of any other error, presume repo has not been fetched and do that now.
310
316
  Jekyll.logger.debug("OPF:", "Fetching & checking out #{remote_url} for #{repo_path}")
311
317
  repo.fetch(DEFAULT_REPO_REMOTE_NAME, { :depth => 1 })
312
- repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{DEFAULT_REPO_BRANCH}", { :f => true })
318
+ begin
319
+ # Try checkout again
320
+ repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{repo_branch}", { :f => true })
321
+ rescue Exception => e
322
+ if is_sparse_checkout_error(e, sparse_subtrees)
323
+ # Again, silence an error caused by nonexistent sparse checkout directories…
324
+ return {
325
+ :success => false,
326
+ :newly_initialized => nil,
327
+ :modified_at => nil,
328
+ }
329
+ else
330
+ # but this time throw any other error.
331
+ raise e
332
+ end
333
+ end
313
334
  end
314
335
  end
315
336
  end
@@ -327,6 +348,15 @@ module Jekyll
327
348
  end
328
349
  end
329
350
 
351
+ def is_sparse_checkout_error(err, subtrees)
352
+ if err.message.include? "Sparse checkout leaves no entry on working directory"
353
+ Jekyll.logger.debug("OPF: It looks like sparse checkout of these directories failed:", subtrees.to_s)
354
+ true
355
+ else
356
+ false
357
+ end
358
+ end
359
+
330
360
  Jekyll::Hooks.register :site, :after_init do |site|
331
361
  if site.theme # TODO: Check theme name
332
362
  site.reader = Jekyll::OpenProjectHelpers::OpenProjectReader::new(site)
@@ -1,92 +1,119 @@
1
- require 'fastimage'
1
+ require "fastimage"
2
2
 
3
3
  # Recursively go through given list of nav_items, including any nested items,
4
4
  # and return a flat array containing navigation items with path specified.
5
5
  def get_nav_items_with_path(nav_items)
6
6
  items_with_path = []
7
7
 
8
- for item in nav_items do
9
- if item['path']
8
+ nav_items.each do |item|
9
+ if item["path"]
10
10
  items_with_path.push(item)
11
11
  end
12
12
 
13
- if item['items']
14
- items_with_path.concat(get_nav_items_with_path(item['items']))
13
+ if item["items"]
14
+ items_with_path.concat(get_nav_items_with_path(item["items"]))
15
15
  end
16
16
  end
17
17
 
18
- return items_with_path
18
+ items_with_path
19
19
  end
20
20
 
21
21
  module Builder
22
-
23
22
  class PngDiagramPage < Jekyll::Page
24
- def initialize(site, base, dir, data)
23
+ EXTRA_STYLESHEETS = [{
24
+ "href" => "https://unpkg.com/leaflet@1.3.4/dist/leaflet.css",
25
+ "integrity" => "sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==", # rubocop:disable Layout/LineLength
26
+ "crossorigin" => "",
27
+ }].freeze
28
+
29
+ EXTRA_SCRIPTS = [{
30
+ "src" => "https://unpkg.com/leaflet@1.3.4/dist/leaflet.js",
31
+ "integrity" => "sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==", # rubocop:disable Layout/LineLength
32
+ "crossorigin" => "",
33
+ }].freeze
34
+
35
+ def initialize(site, base, dir, data) # rubocop:disable Lint/MissingSuper
25
36
  @site = site
26
37
  @base = base
27
38
  @dir = dir
28
- @name = 'index.html'
39
+ @name = "index.html"
29
40
 
30
- self.process(@name)
41
+ process(@name)
31
42
  self.data ||= data
32
43
 
33
- self.data['extra_stylesheets'] = [{
34
- "href" => "https://unpkg.com/leaflet@1.3.4/dist/leaflet.css",
35
- "integrity" => "sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==",
36
- "crossorigin" => "",
37
- }]
38
-
39
- self.data['extra_scripts'] = [{
40
- "src" => "https://unpkg.com/leaflet@1.3.4/dist/leaflet.js",
41
- "integrity" => "sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==",
42
- "crossorigin" => "",
43
- }]
44
-
45
- self.data['layout'] = 'spec'
44
+ self.data["extra_stylesheets"] = EXTRA_STYLESHEETS
45
+ self.data["extra_scripts"] = EXTRA_SCRIPTS
46
+ self.data["layout"] = "spec"
46
47
  end
47
48
  end
48
49
 
49
50
  def build_spec_pages(site, spec_info, source, destination, opts)
50
51
  images_path = source
51
52
  spec_root = destination
52
- stub_path = "#{File.dirname(__FILE__)}/png_diagram.html"
53
53
  pages = []
54
54
 
55
- diagram_nav_items = get_nav_items_with_path(spec_info.data['navigation']['items'])
55
+ diagram_nav_items = get_nav_items_with_path(
56
+ spec_info.data["navigation"]["items"],
57
+ )
58
+ not_found_items = diagram_nav_items.dup
56
59
 
57
60
  Dir.glob("#{images_path}/*.png") do |pngfile|
58
61
  png_name = File.basename(pngfile)
59
62
  png_name_noext = File.basename(png_name, File.extname(png_name))
60
63
 
61
- nav_item = diagram_nav_items.select { |item|
62
- item['path'].start_with?(png_name_noext)
63
- } [0].clone
64
-
65
- png_dimensions = FastImage.size(pngfile)
66
- data = spec_info.data.clone
67
- data['image_path'] = "/#{spec_root}/images/#{png_name}"
68
- data['image_width'] = png_dimensions[0]
69
- data['image_height'] = png_dimensions[1]
64
+ nav_item = diagram_nav_items.select do |item|
65
+ item["path"].start_with?(png_name_noext)
66
+ end [0].clone
70
67
 
71
68
  if nav_item == nil
72
- raise "Navigation item matching #{png_name} (#{spec_root}) was not found"
69
+ warn "UNUSED PNG: #{png_name} detected at source without " \
70
+ "a corresponding navigation item at (#{spec_root})."
71
+ next
73
72
  end
74
73
 
75
- data = data.merge(nav_item)
74
+ not_found_items.delete_if { |item| item["title"] == nav_item["title"] }
75
+
76
+ data = build_spec_page_data(pngfile, spec_root, png_name, nav_item,
77
+ spec_info)
76
78
 
77
- data['title'] = "#{spec_info['title']}: #{nav_item['title']}"
78
- data['article_header_title'] = "#{nav_item['title']}"
79
+ pages << build_spec_page(site, spec_root, png_name_noext, data)
80
+ end
79
81
 
80
- page = PngDiagramPage.new(
81
- site,
82
- site.source,
83
- File.join(spec_root, png_name_noext),
84
- data)
85
- page.content = File.read(stub_path)
86
- pages << page
82
+ not_found_items.each do |item|
83
+ title = item["title"]
84
+ warn "SPECIFIED PNG NOT FOUND: #{title}.png not found at source " \
85
+ "as specified at (#{spec_root})."
87
86
  end
88
87
 
89
- return pages
88
+ pages
89
+ end
90
+
91
+ def build_spec_page(site, spec_root, png_name_noext, data)
92
+ page = PngDiagramPage.new(
93
+ site,
94
+ site.source,
95
+ File.join(spec_root, png_name_noext),
96
+ data,
97
+ )
98
+
99
+ stub_path = "#{File.dirname(__FILE__)}/png_diagram.html"
100
+ page.content = File.read(stub_path)
101
+
102
+ page
90
103
  end
91
104
 
105
+ def build_spec_page_data(pngfile, spec_root, png_name, nav_item, spec_info)
106
+ png_dimensions = FastImage.size(pngfile)
107
+ data = spec_info.data.clone
108
+ data["image_path"] = "/#{spec_root}/images/#{png_name}"
109
+ data["image_width"] = png_dimensions[0]
110
+ data["image_height"] = png_dimensions[1]
111
+
112
+ data = data.merge(nav_item)
113
+
114
+ data["title"] = "#{spec_info['title']}: #{nav_item['title']}"
115
+ data["article_header_title"] = nav_item["title"].to_s
116
+
117
+ data
118
+ end
92
119
  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: 2.1.4
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-05 00:00:00.000000000 Z
11
+ date: 2021-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -87,8 +87,12 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - Gemfile
90
93
  - LICENSE.txt
91
94
  - README.md
95
+ - Rakefile
92
96
  - develop/release
93
97
  - jekyll-theme-open-project-helpers.gemspec
94
98
  - lib/jekyll-theme-open-project-helpers.rb
@@ -119,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
123
  - !ruby/object:Gem::Version
120
124
  version: '0'
121
125
  requirements: []
122
- rubygems_version: 3.0.6
126
+ rubygems_version: 3.0.3
123
127
  signing_key:
124
128
  specification_version: 4
125
129
  summary: Helpers for the Open Project Jekyll theme