swedbank-pay-design-guide-jekyll-theme 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gem_version.rb +1 -1
- data/lib/sidebar.rb +7 -6
- data/lib/sidebar_html_builder.rb +6 -3
- data/lib/sidebar_page.rb +26 -9
- data/lib/sidebar_page_collection.rb +0 -1
- data/lib/sidebar_page_title.rb +29 -5
- data/lib/sidebar_parser.rb +41 -28
- data/lib/sidebar_renderer.rb +15 -18
- data/lib/sidebar_text_builder.rb +2 -2
- data/lib/sidebar_tree_builder.rb +17 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d576204f0905f4ad97a12cbbf4a5bef4b2efed40fd24728f315ef29aa1bdee2
|
4
|
+
data.tar.gz: 76f4c8c9d616c993a50db2b83ef1d186d422222199f5063ec6273c0e247531ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1b3b671e7effeb8b76fc0d501a9bed6b4ddf9a918c88fe2f50e23ddb539f901d7905bef61784d86141b8f4e2bc434391a480dd7274ebc1256188618f1b28ba
|
7
|
+
data.tar.gz: '09e20f7c41ac0c68eca729641ede6287ec05e9c1f101dd62d3ba33e4f2e523b9eda1f2527170c1f590b297a96ab4d057af44e0f8b3d44cd5fe35339a20e1670d'
|
data/lib/gem_version.rb
CHANGED
data/lib/sidebar.rb
CHANGED
@@ -15,15 +15,16 @@ module SwedbankPay
|
|
15
15
|
attr_reader :pages
|
16
16
|
|
17
17
|
def pre_render(site)
|
18
|
-
|
19
|
-
|
20
|
-
@pages = SidebarTreeBuilder.new(pages)
|
18
|
+
Jekyll.logger.debug(' Sidebar: pre_render')
|
19
|
+
@parser = SidebarParser.new(site)
|
20
|
+
@pages = SidebarTreeBuilder.new(@parser.pages)
|
21
21
|
Jekyll.logger.debug(" Sidebar: #{@pages.inspect}")
|
22
|
-
@sidebar_renderer = SidebarRenderer.new(@pages)
|
23
|
-
@sidebar_renderer.enrich_jekyll
|
24
22
|
end
|
25
23
|
|
26
24
|
def post_write
|
25
|
+
@sidebar_renderer = SidebarRenderer.new(@pages)
|
26
|
+
@parser.parse(@pages)
|
27
|
+
Jekyll.logger.debug(' Sidebar: post_write')
|
27
28
|
@sidebar_renderer.render
|
28
29
|
end
|
29
30
|
end
|
@@ -34,6 +35,6 @@ Jekyll::Hooks.register :site, :pre_render do |site, _|
|
|
34
35
|
SwedbankPay::Sidebar.pre_render site
|
35
36
|
end
|
36
37
|
|
37
|
-
Jekyll::Hooks.register :site, :post_write do
|
38
|
+
Jekyll::Hooks.register :site, :post_write do
|
38
39
|
SwedbankPay::Sidebar.post_write
|
39
40
|
end
|
data/lib/sidebar_html_builder.rb
CHANGED
@@ -24,10 +24,13 @@ module SwedbankPay
|
|
24
24
|
markup = ''
|
25
25
|
|
26
26
|
pages.each do |page|
|
27
|
+
current_page_name = current_page.respond_to?(:name) ? current_page.name : current_page.to_s
|
28
|
+
|
27
29
|
if page.hidden_for?(current_page)
|
28
|
-
|
29
|
-
Jekyll.logger.debug(" Sidebar: #{page.name} is hidden for #{name}")
|
30
|
+
Jekyll.logger.debug(" Sidebar: #{page.name} is hidden for #{current_page_name}")
|
30
31
|
next
|
32
|
+
elsif page.hidden?
|
33
|
+
Jekyll.logger.debug(" Sidebar: Hidden page #{page.name} is not hidden for #{current_page_name}")
|
31
34
|
end
|
32
35
|
|
33
36
|
sub_items_markup = sub_items_markup(page, current_page)
|
@@ -96,7 +99,7 @@ module SwedbankPay
|
|
96
99
|
return leaf_markup(page.path, main_title, page.level) unless page.headers?
|
97
100
|
|
98
101
|
# If there's no children, only return the headers as leaf node items.
|
99
|
-
return page.headers.map { |h| header_markup(page, h) }.join('')
|
102
|
+
return page.headers.map { |h| header_markup(page, h) }.join('') unless page.children?
|
100
103
|
|
101
104
|
headers_markup = page.headers.map { |h| header_markup(page, h) }.join('')
|
102
105
|
headers_markup = "<ul class=\"nav-ul\">#{headers_markup}</ul>"
|
data/lib/sidebar_page.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
3
|
require 'jekyll'
|
4
|
+
require 'nokogiri'
|
4
5
|
require_relative 'sidebar_path'
|
5
6
|
require_relative 'sidebar_page_title'
|
6
7
|
require_relative 'sidebar_page_collection'
|
@@ -11,13 +12,14 @@ module SwedbankPay
|
|
11
12
|
class SidebarPage
|
12
13
|
FIXNUM_MAX = (2**(0.size * 8 - 2) - 1)
|
13
14
|
|
14
|
-
attr_reader :path, :title, :level, :order, :children, :name
|
15
|
-
attr_accessor :headers, :
|
15
|
+
attr_reader :path, :title, :level, :order, :children, :name, :filename, :doc
|
16
|
+
attr_accessor :headers, :sidebar_container, :number, :parent
|
16
17
|
|
17
18
|
def initialize(jekyll_page)
|
18
19
|
raise ArgumentError, 'jekyll_page cannot be nil' if jekyll_page.nil?
|
19
20
|
raise ArgumentError, 'jekyll_page must be a Jekyll::Page' unless jekyll_page.is_a? Jekyll::Page
|
20
21
|
|
22
|
+
@filename = jekyll_page.destination('')
|
21
23
|
@jekyll_page = jekyll_page
|
22
24
|
sidebar_path = SidebarPath.new(jekyll_page['url'])
|
23
25
|
@path = sidebar_path.to_s
|
@@ -56,10 +58,6 @@ module SwedbankPay
|
|
56
58
|
def hidden_for?(other_page)
|
57
59
|
# The current page should be hidden for the other page unless the
|
58
60
|
# other page is also hidden.
|
59
|
-
#
|
60
|
-
# TODO: Make it so that hiddden pages within a section are visible
|
61
|
-
# for each other, but not for other sections, regardless if
|
62
|
-
# they are hidden or not.
|
63
61
|
hidden = hidden?
|
64
62
|
|
65
63
|
if other_page.nil? || !other_page.is_a?(SidebarPage)
|
@@ -67,7 +65,9 @@ module SwedbankPay
|
|
67
65
|
return hidden
|
68
66
|
end
|
69
67
|
|
70
|
-
|
68
|
+
# If the other page is hidden, the current page should not be hidden
|
69
|
+
# from it.
|
70
|
+
return false if other_page.hidden? && in_same_section_as?(other_page)
|
71
71
|
|
72
72
|
hidden
|
73
73
|
end
|
@@ -104,8 +104,7 @@ module SwedbankPay
|
|
104
104
|
return
|
105
105
|
end
|
106
106
|
|
107
|
-
Jekyll.logger.debug(" Sidebar:
|
108
|
-
Jekyll.logger.debug(" Sidebar: #{@name}.main_title '#{@title.main}'")
|
107
|
+
Jekyll.logger.debug(" Sidebar: <#{@path}>.lead_title('#{@title.lead}').main_title('#{@title.main}')")
|
109
108
|
|
110
109
|
@jekyll_page.data['lead_title'] = @title.lead
|
111
110
|
@jekyll_page.data['main_title'] = @title.main
|
@@ -120,16 +119,26 @@ module SwedbankPay
|
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
122
|
+
def children?
|
123
|
+
!children.nil? && children.any?
|
124
|
+
end
|
125
|
+
|
123
126
|
def headers?
|
124
127
|
!headers.nil? && headers.any?
|
125
128
|
end
|
126
129
|
|
127
130
|
def coordinate
|
128
131
|
return @number.to_s if @parent.nil?
|
132
|
+
return @number.to_s unless @parent.respond_to? :coordinate
|
129
133
|
|
130
134
|
"#{@parent.coordinate}.#{@number}"
|
131
135
|
end
|
132
136
|
|
137
|
+
def load
|
138
|
+
@doc = File.open(@filename) { |f| Nokogiri::HTML(f) }
|
139
|
+
@doc
|
140
|
+
end
|
141
|
+
|
133
142
|
private
|
134
143
|
|
135
144
|
def menu_order(jekyll_page)
|
@@ -160,5 +169,13 @@ module SwedbankPay
|
|
160
169
|
|
161
170
|
''
|
162
171
|
end
|
172
|
+
|
173
|
+
def in_same_section_as?(other_page)
|
174
|
+
# If this or the other page is the root index page, just ignore the
|
175
|
+
# hidden state completely
|
176
|
+
return false if other_page.path == '/' || @path == '/'
|
177
|
+
|
178
|
+
other_page.path.start_with?(@path) || @path.start_with?(other_page.path)
|
179
|
+
end
|
163
180
|
end
|
164
181
|
end
|
data/lib/sidebar_page_title.rb
CHANGED
@@ -16,7 +16,8 @@ module SwedbankPay
|
|
16
16
|
|
17
17
|
title = jekyll_page['title']
|
18
18
|
section = jekyll_page['section']
|
19
|
-
|
19
|
+
|
20
|
+
return nil if title.nil? && section.nil?
|
20
21
|
|
21
22
|
SidebarPageTitle.new(title, section, sidebar_page)
|
22
23
|
end
|
@@ -45,11 +46,18 @@ module SwedbankPay
|
|
45
46
|
private
|
46
47
|
|
47
48
|
def initialize(title, section, page)
|
48
|
-
raise ArgumentError, 'title cannot be nil' if title.nil?
|
49
|
-
raise ArgumentError, 'title must be a String' unless title.is_a? String
|
49
|
+
raise ArgumentError, 'Both title and section cannot be nil' if title.nil? && section.nil?
|
50
50
|
raise ArgumentError, 'page cannot be nil' if page.nil?
|
51
51
|
raise ArgumentError, 'page must be a SidebarPage' unless page.is_a? SidebarPage
|
52
52
|
|
53
|
+
if title.nil?
|
54
|
+
raise ArgumentError, 'section must be a String' unless section.is_a? String
|
55
|
+
|
56
|
+
title = section
|
57
|
+
elsif section.nil?
|
58
|
+
raise ArgumentError, 'title must be a String' unless title.is_a? String
|
59
|
+
end
|
60
|
+
|
53
61
|
@page = page
|
54
62
|
@title = title
|
55
63
|
parts = title.split('–')
|
@@ -59,13 +67,29 @@ module SwedbankPay
|
|
59
67
|
end
|
60
68
|
|
61
69
|
def find_section(page)
|
70
|
+
raise ArgumentError, 'page cannot be nil' if page.nil?
|
71
|
+
raise ArgumentError, 'page must be a SidebarPage' unless page.is_a? SidebarPage
|
72
|
+
|
62
73
|
# Return the 'section' front matter if it can be found on the current page.
|
63
|
-
|
74
|
+
section = section_from_front_matter(page)
|
75
|
+
return section unless section.nil?
|
64
76
|
|
65
77
|
# Recurse upwards to the root (until there is no parent).
|
66
|
-
return find_section(page.parent) unless page.nil? || page.parent.nil?
|
78
|
+
return find_section(page.parent) unless page.nil? || page.parent.nil? || !page.parent.is_a?(SidebarPage)
|
67
79
|
|
68
80
|
nil
|
69
81
|
end
|
82
|
+
|
83
|
+
def section_from_front_matter(page)
|
84
|
+
return nil if page.nil? || page.title.nil? || page.title.section.nil? || page.title.section.empty?
|
85
|
+
|
86
|
+
page.title.section
|
87
|
+
end
|
88
|
+
|
89
|
+
def section_from_parent(page)
|
90
|
+
return nil if page.nil? || page.parent.nil?
|
91
|
+
|
92
|
+
find_section(page.parent, level) unless page.nil? || page.parent.nil?
|
93
|
+
end
|
70
94
|
end
|
71
95
|
end
|
data/lib/sidebar_parser.rb
CHANGED
@@ -1,59 +1,65 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'jekyll'
|
4
|
+
require 'jekyll-redirect-from'
|
4
5
|
require_relative 'sidebar_path'
|
5
6
|
|
6
7
|
module SwedbankPay
|
7
8
|
# The Sidebar renderer
|
8
9
|
class SidebarParser
|
10
|
+
attr_reader :pages
|
11
|
+
|
9
12
|
def initialize(site)
|
10
13
|
raise ArgumentError, 'Site cannot be nil' if site.nil?
|
11
14
|
raise ArgumentError, 'Site must be a Jekyll::Site' unless site.is_a? Jekyll::Site
|
12
15
|
|
13
|
-
@
|
16
|
+
@pages = convert(site.pages)
|
14
17
|
end
|
15
18
|
|
16
|
-
def parse
|
17
|
-
|
19
|
+
def parse(tree)
|
20
|
+
raise ArgumentError, 'tree cannot be nil' if tree.nil?
|
21
|
+
raise ArgumentError, 'tree must be a SidebarTreeBuilder' unless tree.is_a? SidebarTreeBuilder
|
18
22
|
|
19
|
-
|
23
|
+
parse_html(tree)
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
def convert(pages)
|
29
|
+
pages_hash = {}
|
25
30
|
|
26
|
-
|
27
|
-
|
31
|
+
pages.each do |jekyll_page|
|
32
|
+
if skippable? jekyll_page
|
33
|
+
Jekyll.logger.debug(" Sidebar: Skipping <#{jekyll_page['url']}>")
|
28
34
|
next
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
page.headers = find_headers(doc)
|
34
|
-
page.sidebar_container = find_sidebar_container(filename, doc)
|
37
|
+
sidebar_page = SidebarPage.new(jekyll_page)
|
38
|
+
pages_hash[sidebar_page.path] = sidebar_page
|
35
39
|
end
|
36
40
|
|
37
|
-
|
41
|
+
pages_hash
|
38
42
|
end
|
39
43
|
|
40
|
-
|
44
|
+
def parse_html(pages)
|
45
|
+
return if pages.nil? || pages.empty?
|
41
46
|
|
42
|
-
|
43
|
-
|
47
|
+
pages.each do |page|
|
48
|
+
page.load
|
49
|
+
page.headers = find_headers(page)
|
50
|
+
page.sidebar_container = find_sidebar_container(page)
|
51
|
+
page.freeze
|
44
52
|
|
45
|
-
|
46
|
-
sidebar_page = SidebarPage.new(jekyll_page)
|
47
|
-
pages_hash[sidebar_page.path] = sidebar_page
|
53
|
+
parse_html(page.children)
|
48
54
|
end
|
49
55
|
|
50
|
-
|
56
|
+
pages
|
51
57
|
end
|
52
58
|
|
53
|
-
def find_headers(
|
59
|
+
def find_headers(page)
|
54
60
|
headers = []
|
55
61
|
|
56
|
-
doc.xpath('//h2').each do |header|
|
62
|
+
page.doc.xpath('//h2').each do |header|
|
57
63
|
next unless header['id']
|
58
64
|
|
59
65
|
child_markup = header.last_element_child
|
@@ -68,15 +74,22 @@ module SwedbankPay
|
|
68
74
|
headers
|
69
75
|
end
|
70
76
|
|
71
|
-
def find_sidebar_container(
|
72
|
-
sidebar_containers = doc.xpath('//*[@id="dx-sidebar-main-nav-ul"]')
|
77
|
+
def find_sidebar_container(page)
|
78
|
+
sidebar_containers = page.doc.xpath('//*[@id="dx-sidebar-main-nav-ul"]')
|
73
79
|
|
74
|
-
|
75
|
-
Jekyll.logger.
|
80
|
+
if sidebar_containers.empty?
|
81
|
+
Jekyll.logger.error(" Sidebar: No sidebar container found in <#{page.filename}>!")
|
76
82
|
return nil
|
77
83
|
end
|
78
84
|
|
79
85
|
sidebar_containers.first
|
80
86
|
end
|
87
|
+
|
88
|
+
def skippable?(jekyll_page)
|
89
|
+
return true if jekyll_page.is_a? JekyllRedirectFrom::RedirectPage
|
90
|
+
return true if jekyll_page.is_a? JekyllRedirectFrom::PageWithoutAFile
|
91
|
+
|
92
|
+
false
|
93
|
+
end
|
81
94
|
end
|
82
95
|
end
|
data/lib/sidebar_renderer.rb
CHANGED
@@ -10,6 +10,7 @@ module SwedbankPay
|
|
10
10
|
raise ArgumentError, 'pages must be an SidebarTreeBuilder' unless tree.is_a? SidebarTreeBuilder
|
11
11
|
|
12
12
|
@tree = tree
|
13
|
+
@html_builder = SidebarHTMLBuilder.new(@tree)
|
13
14
|
end
|
14
15
|
|
15
16
|
def enrich_jekyll
|
@@ -22,24 +23,22 @@ module SwedbankPay
|
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
def enrich_jekyll_pages(pages)
|
26
|
-
return if pages.empty?
|
27
|
-
|
28
|
-
pages.each do |page|
|
29
|
-
page.enrich_jekyll
|
30
|
-
|
31
|
-
enrich_jekyll_pages(page.children)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
26
|
def render_pages(pages)
|
36
27
|
return if pages.empty?
|
37
28
|
|
38
29
|
pages.each do |page|
|
39
|
-
sidebar_html =
|
30
|
+
sidebar_html = render_sidebar(page)
|
31
|
+
name = page.filename || page.name || page.to_s
|
32
|
+
|
33
|
+
if sidebar_html.nil?
|
34
|
+
Jekyll.logger.warn(" Sidebar: No HTML rendered for #{name}.")
|
35
|
+
next
|
36
|
+
end
|
40
37
|
|
41
|
-
|
42
|
-
|
38
|
+
if page.sidebar_container.nil?
|
39
|
+
Jekyll.logger.warn(" Sidebar: No sidebar container found in '#{name}'. #{page.filename}")
|
40
|
+
next
|
41
|
+
end
|
43
42
|
|
44
43
|
page.sidebar_container.inner_html = sidebar_html
|
45
44
|
|
@@ -49,19 +48,17 @@ module SwedbankPay
|
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
def
|
51
|
+
def render_sidebar(page)
|
53
52
|
sidebar_html = nil
|
54
53
|
|
55
54
|
begin
|
56
|
-
|
57
|
-
sidebar_html = builder.build(page)
|
55
|
+
sidebar_html = @html_builder.build(page)
|
58
56
|
|
59
57
|
File.open('_site/sidebar.html', 'w') { |f| f.write(sidebar_html) }
|
60
58
|
rescue StandardError => e
|
61
|
-
name = page.filename || page.name
|
59
|
+
name = page.filename || page.name || page.to_s
|
62
60
|
Jekyll.logger.error(" Sidebar: Unable to render sidebar for '#{name}'.")
|
63
61
|
Jekyll.logger.debug(" Sidebar: #{e.message}. #{e.backtrace.inspect}")
|
64
|
-
return nil
|
65
62
|
end
|
66
63
|
|
67
64
|
sidebar_html
|
data/lib/sidebar_text_builder.rb
CHANGED
@@ -14,9 +14,9 @@ module SwedbankPay
|
|
14
14
|
def to_s
|
15
15
|
name = @page.name == '/' ? '/' : "/#{@page.name}"
|
16
16
|
title = @page.title.nil? ? '?' : @page.title.main
|
17
|
-
s = "#{indent} #{
|
17
|
+
s = "#{indent} #{@page.coordinate}. #{name}: #{title}\n"
|
18
18
|
|
19
|
-
|
19
|
+
if @page.children?
|
20
20
|
@page.children.each do |child|
|
21
21
|
s << child.to_s
|
22
22
|
end
|
data/lib/sidebar_tree_builder.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
+
require 'jekyll'
|
3
4
|
require 'forwardable'
|
4
5
|
require_relative 'sidebar_page_collection'
|
5
6
|
|
@@ -8,12 +9,14 @@ module SwedbankPay
|
|
8
9
|
class SidebarTreeBuilder
|
9
10
|
include Enumerable
|
10
11
|
extend Forwardable
|
11
|
-
def_delegators :@
|
12
|
+
def_delegators :@tree, :each, :length, :empty?, :<<, :[], :count
|
12
13
|
|
13
14
|
def initialize(pages)
|
14
|
-
raise ArgumentError, '
|
15
|
+
raise ArgumentError, 'pages cannot be nil' if pages.nil?
|
16
|
+
raise ArgumentError, 'pages must be a Hash' unless pages.is_a? Hash
|
15
17
|
|
16
|
-
@
|
18
|
+
@tree = tree(pages)
|
19
|
+
enrich_jekyll_pages(@tree)
|
17
20
|
end
|
18
21
|
|
19
22
|
def to_s
|
@@ -31,7 +34,7 @@ module SwedbankPay
|
|
31
34
|
|
32
35
|
if inspection
|
33
36
|
output << ":\n"
|
34
|
-
@
|
37
|
+
@tree.each do |page|
|
35
38
|
output << "#{page}\n"
|
36
39
|
end
|
37
40
|
end
|
@@ -69,5 +72,15 @@ module SwedbankPay
|
|
69
72
|
def sort_by_path_reversed(pages)
|
70
73
|
pages.sort_by { |path, _| path }.reverse
|
71
74
|
end
|
75
|
+
|
76
|
+
def enrich_jekyll_pages(pages)
|
77
|
+
return if pages.empty?
|
78
|
+
|
79
|
+
pages.each do |page|
|
80
|
+
page.enrich_jekyll
|
81
|
+
|
82
|
+
enrich_jekyll_pages(page.children)
|
83
|
+
end
|
84
|
+
end
|
72
85
|
end
|
73
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swedbank-pay-design-guide-jekyll-theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Swedbank Pay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|