jekyll-theme-open-project-helpers 1.3.4 → 2.0

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
- SHA256:
3
- metadata.gz: 6d264f603e6b3e7be09d4301371edf74befd053ac0073cb9b40d32729ca4303f
4
- data.tar.gz: 58abf7b1e6bf370ecaa75c1460a449555e580c1f09d771bd9517accfee408024
2
+ SHA1:
3
+ metadata.gz: dd46772b2f87910b758b95f9da217c5ef5ec0a2d
4
+ data.tar.gz: a8b482f8a82760531b55d29356312e9cfe09ab63
5
5
  SHA512:
6
- metadata.gz: cb8b898cc45d9a2a23b0513de0d9f03a0120c97f892e4d3556f388d3ebcc240f553e85e4d7c491866a18d73033aa8bf63fb38b6bb8c4ff32c992ee4f7427b106
7
- data.tar.gz: ca8716c7525b36ae20ef3390e5c91effc17da54e00a80c43e909ee696a55ebd43a4c896d45fd4fca305b66b1f4b6bc286f50227d330c20f11bd28fde7cfa6b6c
6
+ metadata.gz: 041efef7ad38ec390897e3bd8e9b868354b017784d79f8b5ad0ea72ddc9299442f5cf7a05ba6a8d6b3d6dc29eb976725c4f37cd93a82612c81df88097dcdcd77
7
+ data.tar.gz: 752e84028c7ab71d71fb4088a1db9b5532842f3d5780f3dadb6b0e1e2867ab32f23c7b16f1ecd102a47025013da117d8ee448775fc4e86b90a50d399f831fa4d
@@ -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 = '1.3.4'
5
+ s.version = '2.0'
6
6
  s.authors = ['Ribose Inc.']
7
7
  s.email = ['open.source@ribose.com']
8
8
 
@@ -1,27 +1,48 @@
1
1
  require 'nokogiri'
2
2
  require 'uri'
3
3
 
4
- def process_content(site_hostname, content)
4
+ # Given hostname and content, updates <a> elements as follows:
5
+ #
6
+ # - Adds `rel` attribute
7
+ # - Appends inner markup for FontAwesome external link icon
8
+ #
9
+ # Only processes external links where `href` starts with "http"
10
+ # and target host does not include given site hostname.
11
+ def process_content(site_hostname, content, exclude_selectors=[])
5
12
  content = Nokogiri::HTML(content)
6
13
  content.css('body.site--project main a, body.site--hub.layout--post main a').each do |a|
7
14
  next unless a.get_attribute('href') =~ /\Ahttp/i
8
15
  next if a.get_attribute('href').include? site_hostname
16
+ next if matches_one_of(a, exclude_selectors)
9
17
  a.set_attribute('rel', 'external')
10
18
  a.inner_html = "#{a.inner_html}<span class='ico-ext'><i class='fas fa-external-link-square'></i></span>"
11
19
  end
12
20
  return content.to_s
13
21
  end
14
22
 
23
+ # Returns true if Nokogiri’s Node matches one of selectors,
24
+ # otherwise return false
25
+ def matches_one_of(node, selectors)
26
+ for selector in selectors
27
+ if node.matches? selector
28
+ return true
29
+ end
30
+ end
31
+ return false
32
+ end
33
+
15
34
  Jekyll::Hooks.register :documents, :post_render do |doc|
16
35
  site_hostname = URI(doc.site.config['url']).host
36
+ unmarked_link_selectors = doc.site.config['unmarked_external_link_selectors']
17
37
  unless doc.asset_file?
18
- doc.output = process_content(site_hostname, doc.output)
38
+ doc.output = process_content(site_hostname, doc.output, unmarked_link_selectors)
19
39
  end
20
40
  end
21
41
 
22
42
  Jekyll::Hooks.register :pages, :post_render do |page|
23
43
  site_hostname = URI(page.site.config['url']).host
44
+ unmarked_link_selectors = page.site.config['unmarked_external_link_selectors']
24
45
  unless page.asset_file?
25
- page.output = process_content(site_hostname, page.output)
46
+ page.output = process_content(site_hostname, page.output, unmarked_link_selectors)
26
47
  end
27
48
  end
@@ -105,6 +105,10 @@ module Jekyll
105
105
 
106
106
  items = get_all_items(site, collection_name, params[:item_test])
107
107
 
108
+ if items.length == 1
109
+ site.config["one_#{index_name}"] = items[0]
110
+ end
111
+
108
112
  site.config["all_#{index_name}"] = items
109
113
  site.config["num_all_#{index_name}"] = items.size
110
114
 
@@ -1,5 +1,23 @@
1
1
  require 'fastimage'
2
2
 
3
+ # Recursively go through given list of nav_items, including any nested items,
4
+ # and return a flat array containing navigation items with path specified.
5
+ def get_nav_items_with_path(nav_items)
6
+ items_with_path = []
7
+
8
+ for item in nav_items do
9
+ if item['path']
10
+ items_with_path.push(item)
11
+ end
12
+
13
+ if item['items']
14
+ items_with_path.concat(get_nav_items_with_path(item['items']))
15
+ end
16
+ end
17
+
18
+ return items_with_path
19
+ end
20
+
3
21
  module Builder
4
22
 
5
23
  class PngDiagramPage < Jekyll::Page
@@ -34,13 +52,15 @@ module Builder
34
52
  stub_path = "#{File.dirname(__FILE__)}/png_diagram.html"
35
53
  pages = []
36
54
 
55
+ diagram_nav_items = get_nav_items_with_path(spec_info.data['navigation']['items'])
56
+
37
57
  Dir.glob("#{images_path}/*.png") do |pngfile|
38
58
  png_name = File.basename(pngfile)
39
59
  png_name_noext = File.basename(png_name, File.extname(png_name))
40
60
 
41
- nav_item = spec_info.data['navigation']['items'].map { |top_level_item|
42
- top_level_item['items']
43
- } .flatten.select { |item| item['path'].start_with?(png_name_noext) } [0].clone
61
+ nav_item = diagram_nav_items.select { |item|
62
+ item['path'].start_with?(png_name_noext)
63
+ } [0].clone
44
64
 
45
65
  png_dimensions = FastImage.size(pngfile)
46
66
  data = spec_info.data.clone
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: 1.3.4
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-15 00:00:00.000000000 Z
11
+ date: 2019-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.7.6
123
+ rubygems_version: 2.5.2.3
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Helpers for the Open Project Jekyll theme