guides_style_18f 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/guides_style_18f/navigation.rb +79 -18
- data/lib/guides_style_18f/repository.rb +7 -7
- 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: b865432024e19d9efd28bbd172864cbd05617067
|
4
|
+
data.tar.gz: 5c90ae1698a6598a898aa00af9660913d9a14784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 421affe591c3bbc4b6551b4362281aa5abdd1cbc44989c55e909f6dd1a8ac071a5726b00706f45e336fee7a4e270fd08134325505dcaf491ea836baa19a19abb
|
7
|
+
data.tar.gz: 33cf1a0b7ffe68fbcc3a2dabb0da5853024a3e5e596c4dfe52b3f5ff84305a6e141f6dc4d25ea5eb9ce1d0925a6cfa4a9be0d030c1d70602aff05c2a4eba7ab0
|
@@ -1,13 +1,18 @@
|
|
1
1
|
# @author Mike Bland (michael.bland@gsa.gov)
|
2
2
|
|
3
|
+
require 'jekyll'
|
3
4
|
require 'safe_yaml'
|
4
5
|
|
5
6
|
module GuidesStyle18F
|
6
7
|
module FrontMatter
|
7
8
|
def self.load(basedir)
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
# init_file_to_front_matter_map is initializing the map with a nil value
|
10
|
+
# for every file that _should_ contain front matter as far as the
|
11
|
+
# navigation menu is concerned. Any nil values that remain after merging
|
12
|
+
# with the site_file_to_front_matter map will result in a validation
|
13
|
+
# error.
|
14
|
+
init_file_to_front_matter_map(basedir).merge(
|
15
|
+
site_file_to_front_matter(init_site(basedir)))
|
11
16
|
end
|
12
17
|
|
13
18
|
def self.validate_with_message_upon_error(front_matter)
|
@@ -23,17 +28,76 @@ module GuidesStyle18F
|
|
23
28
|
|
24
29
|
def self.validate(front_matter)
|
25
30
|
front_matter.map do |file, data|
|
26
|
-
next [file, ['no front matter defined']]
|
31
|
+
next [file, ['no front matter defined']] if data.nil?
|
27
32
|
errors = missing_property_errors(data) + permalink_errors(data)
|
28
33
|
[file, errors] unless errors.empty?
|
29
34
|
end.compact.to_h
|
30
35
|
end
|
31
36
|
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.init_site(basedir)
|
40
|
+
Dir.chdir(basedir) do
|
41
|
+
config = SafeYAML.load_file('_config.yml', safe: true)
|
42
|
+
adjust_config_paths(basedir, config)
|
43
|
+
site = Jekyll::Site.new(Jekyll.configuration(config))
|
44
|
+
site.reset
|
45
|
+
site.read
|
46
|
+
site
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.adjust_config_paths(basedir, config)
|
51
|
+
source = config['source']
|
52
|
+
config['source'] = source.nil? ? basedir : File.join(basedir, source)
|
53
|
+
destination = config['destination']
|
54
|
+
destination = '_site' if destination.nil?
|
55
|
+
config['destination'] = File.join(basedir, destination)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.site_file_to_front_matter(site)
|
59
|
+
site_pages(site).map do |page|
|
60
|
+
[page.relative_path, page.data]
|
61
|
+
end.to_h
|
62
|
+
end
|
63
|
+
|
64
|
+
# We're supporting two possible configurations:
|
65
|
+
#
|
66
|
+
# - a `pages/` directory in which documents appear as part of the regular
|
67
|
+
# site.pages collection; we have to filter by page.relative_path, and we
|
68
|
+
# do not assign a permalink so that validation (in a later step) will
|
69
|
+
# ensure that each page has a permalink assigned
|
70
|
+
#
|
71
|
+
# - an actual `pages` collection, stored in a `_pages` directory; no
|
72
|
+
# filtering is necessary, and we can reliably set the permalink to
|
73
|
+
# page.url as a default
|
74
|
+
def self.site_pages(site)
|
75
|
+
pages = site.collections['pages']
|
76
|
+
if pages.nil?
|
77
|
+
site.pages.select do |page|
|
78
|
+
page.relative_path.start_with?('/pages') || page.url == '/'
|
79
|
+
end
|
80
|
+
else
|
81
|
+
pages.docs.each { |page| page.data['permalink'] ||= page.url }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.init_file_to_front_matter_map(basedir)
|
86
|
+
file_to_front_matter = {}
|
87
|
+
Dir.chdir(basedir) do
|
88
|
+
pages_dir = Dir.exist?('_pages') ? '_pages' : 'pages'
|
89
|
+
Dir[File.join(pages_dir, '**', '*')].each do |file_name|
|
90
|
+
next unless File.file?(file_name)
|
91
|
+
file_to_front_matter[file_name] = nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
file_to_front_matter
|
95
|
+
end
|
96
|
+
|
32
97
|
def self.missing_property_errors(data)
|
33
98
|
properties = %w(title permalink)
|
34
99
|
properties.map { |p| "no `#{p}:` property" unless data[p] }.compact
|
35
100
|
end
|
36
|
-
private_class_method :missing_property_errors
|
37
101
|
|
38
102
|
def self.permalink_errors(data)
|
39
103
|
pl = data['permalink']
|
@@ -43,7 +107,6 @@ module GuidesStyle18F
|
|
43
107
|
errors << "`permalink:` does not end with '/'" unless pl.end_with? '/'
|
44
108
|
errors
|
45
109
|
end
|
46
|
-
private_class_method :permalink_errors
|
47
110
|
end
|
48
111
|
|
49
112
|
# Automatically updates the `navigation:` field in _config.yml.
|
@@ -60,6 +123,8 @@ module GuidesStyle18F
|
|
60
123
|
write_navigation_data_to_config_file config_path, nav_data
|
61
124
|
end
|
62
125
|
|
126
|
+
private
|
127
|
+
|
63
128
|
def self.update_navigation_data(nav_data, basedir)
|
64
129
|
pages_data = pages_front_matter basedir
|
65
130
|
children = pages_data['children'].map { |child| child['title'].downcase }
|
@@ -67,7 +132,6 @@ module GuidesStyle18F
|
|
67
132
|
update_parent_nav_data nav_data, pages_data['parents']
|
68
133
|
add_children_to_parents nav_data, pages_data['children']
|
69
134
|
end
|
70
|
-
private_class_method :update_navigation_data
|
71
135
|
|
72
136
|
def self.pages_front_matter(basedir)
|
73
137
|
front_matter = FrontMatter.load basedir
|
@@ -79,7 +143,6 @@ module GuidesStyle18F
|
|
79
143
|
%w(parents children).each { |category| pages_data[category] ||= [] }
|
80
144
|
pages_data
|
81
145
|
end
|
82
|
-
private_class_method :pages_front_matter
|
83
146
|
|
84
147
|
def self.update_parent_nav_data(nav_data, parents)
|
85
148
|
nav_by_title = nav_data_by_title nav_data
|
@@ -93,27 +156,29 @@ module GuidesStyle18F
|
|
93
156
|
end
|
94
157
|
end
|
95
158
|
end
|
96
|
-
private_class_method :update_parent_nav_data
|
97
159
|
|
98
160
|
def self.nav_data_by_title(nav_data)
|
99
161
|
nav_data.map { |nav| [nav['text'].downcase, nav] }.to_h
|
100
162
|
end
|
101
|
-
private_class_method :nav_data_by_title
|
102
163
|
|
103
164
|
def self.page_nav(front_matter)
|
104
|
-
|
105
|
-
|
165
|
+
url_components = front_matter['permalink'].split('/')[1..-1]
|
166
|
+
result = {
|
167
|
+
'text' => front_matter['title'],
|
168
|
+
'url' => "#{url_components.nil? ? '' : url_components.last}/",
|
106
169
|
'internal' => true,
|
107
170
|
}
|
171
|
+
# Delete the root URL so we don't have an empty `url:` property laying
|
172
|
+
# around.
|
173
|
+
result.delete 'url' if result['url'] == '/'
|
174
|
+
result
|
108
175
|
end
|
109
|
-
private_class_method :page_nav
|
110
176
|
|
111
177
|
def self.add_children_to_parents(nav_data, children)
|
112
178
|
parents_by_title = nav_data_by_title nav_data
|
113
179
|
children.each { |child| add_child_to_parent child, parents_by_title }
|
114
180
|
nav_data
|
115
181
|
end
|
116
|
-
private_class_method :add_children_to_parents
|
117
182
|
|
118
183
|
def self.add_child_to_parent(child, parents_by_title)
|
119
184
|
child_nav_data = page_nav child
|
@@ -128,7 +193,6 @@ module GuidesStyle18F
|
|
128
193
|
children << child_nav_data
|
129
194
|
end
|
130
195
|
end
|
131
|
-
private_class_method :add_child_to_parent
|
132
196
|
|
133
197
|
def self.parent(child, parents_by_title)
|
134
198
|
parent = parents_by_title[child['parent'].downcase]
|
@@ -136,7 +200,6 @@ module GuidesStyle18F
|
|
136
200
|
fail StandardError, 'Parent page not present in existing ' \
|
137
201
|
"config: \"#{child['parent']}\" needed by: \"#{child['title']}\""
|
138
202
|
end
|
139
|
-
private_class_method :parent
|
140
203
|
|
141
204
|
def self.write_navigation_data_to_config_file(config_path, nav_data)
|
142
205
|
lines = []
|
@@ -146,7 +209,6 @@ module GuidesStyle18F
|
|
146
209
|
end
|
147
210
|
File.write config_path, lines.join
|
148
211
|
end
|
149
|
-
private_class_method :write_navigation_data_to_config_file
|
150
212
|
|
151
213
|
def self.process_line(line, lines, nav_data, in_navigation = false)
|
152
214
|
if !in_navigation && line.start_with?('navigation:')
|
@@ -160,5 +222,4 @@ module GuidesStyle18F
|
|
160
222
|
end
|
161
223
|
in_navigation
|
162
224
|
end
|
163
|
-
private_class_method :process_line
|
164
225
|
end
|
@@ -5,13 +5,13 @@ require 'fileutils'
|
|
5
5
|
|
6
6
|
module GuidesStyle18F
|
7
7
|
TEMPLATE_FILES = %w(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
_pages/add-a-new-page/make-a-child-page.md
|
9
|
+
_pages/add-a-new-page.md
|
10
|
+
_pages/add-images.md
|
11
|
+
_pages/github-setup.md
|
12
|
+
_pages/post-your-guide.md
|
13
|
+
_pages/update-the-config-file/understanding-baseurl.md
|
14
|
+
_pages/update-the-config-file.md
|
15
15
|
images/18f-pages.png
|
16
16
|
images/description.png
|
17
17
|
images/gh-add-guide.png
|
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.11
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|