guides_style_18f 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/guides_style_18f/navigation.rb +53 -49
- data/lib/guides_style_18f/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ed8884311059c0f0419dea17f6622f5e56b357a
|
4
|
+
data.tar.gz: 8bac760301892a270a60742dc76e28247159c01c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c29860082cc18fdd88eaf8305fb408ed839612a43959dfb13d1189866287955debe83b0186387a5c9b6ca8cfc091181a39f28a9355b8a7c279c03c657eccd6e
|
7
|
+
data.tar.gz: 0f955271cc7d346e506b41d05bccdf9714dd4d50b8929154785f29f4a0b9426fbefcb4ade3621b3f06ebcb3fc3460a48bc540f736650454b0c65e239c12016d5
|
@@ -119,46 +119,33 @@ module GuidesStyle18F
|
|
119
119
|
config_data = SafeYAML.load_file config_path, safe: true
|
120
120
|
return unless config_data
|
121
121
|
nav_data = config_data['navigation'] || []
|
122
|
-
|
123
|
-
write_navigation_data_to_config_file
|
122
|
+
update_navigation_data(nav_data, basedir)
|
123
|
+
write_navigation_data_to_config_file(config_path, nav_data)
|
124
124
|
end
|
125
125
|
|
126
126
|
private
|
127
127
|
|
128
128
|
def self.update_navigation_data(nav_data, basedir)
|
129
|
-
|
130
|
-
|
131
|
-
nav_data
|
132
|
-
|
133
|
-
|
129
|
+
original = map_nav_items_by_url('/', nav_data).to_h
|
130
|
+
updated = updated_nav_data(basedir)
|
131
|
+
remove_stale_nav_entries(nav_data, original, updated)
|
132
|
+
updated.map { |url, nav| apply_nav_update(url, nav, nav_data, original) }
|
133
|
+
check_for_orphaned_items(nav_data)
|
134
134
|
end
|
135
135
|
|
136
|
-
def self.
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
pages_data = front_matter.values.group_by do |fm|
|
141
|
-
fm['parent'].nil? ? 'parents' : 'children'
|
142
|
-
end
|
143
|
-
%w(parents children).each { |category| pages_data[category] ||= [] }
|
144
|
-
pages_data
|
145
|
-
end
|
146
|
-
|
147
|
-
def self.update_parent_nav_data(nav_data, parents)
|
148
|
-
nav_by_title = nav_data_by_title nav_data
|
149
|
-
parents.each do |page|
|
150
|
-
page_nav = page_nav page
|
151
|
-
title = page_nav['text'].downcase
|
152
|
-
if nav_by_title.member? title
|
153
|
-
nav_by_title[title].merge! page_nav
|
154
|
-
else
|
155
|
-
nav_data << page_nav
|
156
|
-
end
|
136
|
+
def self.map_nav_items_by_url(parent_url, nav_data)
|
137
|
+
nav_data.flat_map do |nav|
|
138
|
+
url = File.join('', parent_url, nav['url'] || '')
|
139
|
+
[[url, nav]].concat(map_nav_items_by_url(url, nav['children'] || []))
|
157
140
|
end
|
158
141
|
end
|
159
142
|
|
160
|
-
def self.
|
161
|
-
|
143
|
+
def self.updated_nav_data(basedir)
|
144
|
+
front_matter = FrontMatter.load basedir
|
145
|
+
errors = FrontMatter.validate_with_message_upon_error front_matter
|
146
|
+
abort errors + "\n_config.yml not updated" if errors
|
147
|
+
front_matter.values.sort_by { |fm| fm['permalink'] }
|
148
|
+
.map { |fm| [fm['permalink'], page_nav(fm)] }.to_h
|
162
149
|
end
|
163
150
|
|
164
151
|
def self.page_nav(front_matter)
|
@@ -174,31 +161,42 @@ module GuidesStyle18F
|
|
174
161
|
result
|
175
162
|
end
|
176
163
|
|
177
|
-
def self.
|
178
|
-
|
179
|
-
|
180
|
-
|
164
|
+
def self.remove_stale_nav_entries(nav_data, original, updated)
|
165
|
+
# Remove old entries whose pages have been deleted
|
166
|
+
original.each do |url, nav|
|
167
|
+
nav['delete'] = true if !updated.member?(url) && nav['internal']
|
168
|
+
end
|
169
|
+
original.delete_if { |_url, nav| nav['delete'] }
|
170
|
+
nav_data.delete_if { |nav| nav['delete'] }
|
181
171
|
end
|
182
172
|
|
183
|
-
def self.
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
173
|
+
def self.apply_nav_update(url, nav, nav_data, original)
|
174
|
+
orig = original[url]
|
175
|
+
if orig.nil?
|
176
|
+
apply_new_nav_item(url, nav, nav_data, original)
|
177
|
+
else
|
178
|
+
orig['text'] = nav['text']
|
179
|
+
end
|
180
|
+
end
|
189
181
|
|
190
|
-
|
191
|
-
|
182
|
+
def self.apply_new_nav_item(url, nav, nav_data, original)
|
183
|
+
parent_url = File.dirname(url || '/')
|
184
|
+
parent = original["#{parent_url}/"]
|
185
|
+
if parent_url == '/'
|
186
|
+
nav_data << (original[url] = nav)
|
187
|
+
elsif parent.nil?
|
188
|
+
nav_data << { orphan_url: url }
|
192
189
|
else
|
193
|
-
children <<
|
190
|
+
(parent['children'] ||= []) << nav
|
194
191
|
end
|
195
192
|
end
|
196
193
|
|
197
|
-
def self.
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
194
|
+
def self.check_for_orphaned_items(nav_data)
|
195
|
+
orphans = nav_data.map { |nav| nav[:orphan_url] }.compact
|
196
|
+
unless orphans.empty?
|
197
|
+
fail(StandardError, "Parent pages missing for the following:\n " +
|
198
|
+
orphans.join("\n "))
|
199
|
+
end
|
202
200
|
end
|
203
201
|
|
204
202
|
def self.write_navigation_data_to_config_file(config_path, nav_data)
|
@@ -212,7 +210,7 @@ module GuidesStyle18F
|
|
212
210
|
|
213
211
|
def self.process_line(line, lines, nav_data, in_navigation = false)
|
214
212
|
if !in_navigation && line.start_with?('navigation:')
|
215
|
-
lines << line << nav_data
|
213
|
+
lines << line << format_navigation_section(nav_data)
|
216
214
|
in_navigation = true
|
217
215
|
elsif in_navigation
|
218
216
|
in_navigation = line.start_with?(' ') || line.start_with?('-')
|
@@ -222,4 +220,10 @@ module GuidesStyle18F
|
|
222
220
|
end
|
223
221
|
in_navigation
|
224
222
|
end
|
223
|
+
|
224
|
+
YAML_PREFIX = "---\n"
|
225
|
+
|
226
|
+
def self.format_navigation_section(nav_data)
|
227
|
+
nav_data.empty? ? '' : nav_data.to_yaml[YAML_PREFIX.size..-1]
|
228
|
+
end
|
225
229
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guides_style_18f
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Bland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|