guides_style_18f 0.1.13 → 0.1.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e8e90ac6e098d4a7f00a3bba6b02feef2ca7b31
4
- data.tar.gz: 55f98a82961b0653128999fc82606640d9f97fd5
3
+ metadata.gz: dce17bb3ce830151e80b02ba3d972d29d2d52eaf
4
+ data.tar.gz: 56b84fb06608302738694a29f9a74cb7dade21c2
5
5
  SHA512:
6
- metadata.gz: 033076c750131294a897ca24db5d4badf8b46b8711976024d92f02fd09c52e468199a0e1c10de4581cb388f73562a9f5b58b88924acd990eb6189f7db6dc394b
7
- data.tar.gz: 60a3142ec6eb987c7bb37f507bc7e515f10b324560ce0c7490778ce93f1bb5076dd5e8d3e20c9a512fb3db34032c0d4321a61971bd632281fdacf9b044549432
6
+ metadata.gz: eb9110487567bca200583b368fc657b7677d70074efa224d08fa475ec9ebf6416a851f185906b1e43e5ab66969dd5f309b8a24e7ac56789c3379b0fb381dbed4
7
+ data.tar.gz: eb7dcebc6877231d7e8d2b1244b00c709f47fc27e53d0f1b77a895241830018a91a36ed8f78744c7dd2fe5dfc31d027d5e9424412cc9bae7212ab90060a3bbae
data/README.md CHANGED
@@ -58,6 +58,10 @@ back_link:
58
58
 
59
59
  # If you use Analytics, add your code here:
60
60
  google_analytics_ua: UA-????????-??
61
+
62
+ # If you want all of the navigation bar entries expanded by default, add this
63
+ # property and it to true:
64
+ expand_nav: true
61
65
  ```
62
66
 
63
67
  ### Additional scripts and styles
@@ -66,6 +70,18 @@ If you'd like to add additional scripts or styles to every page on the site,
66
70
  you can add `styles:` and `scripts:` lists to `_config.yml`. To add them to a
67
71
  particular page, add these lists to the page's front matter.
68
72
 
73
+ ### Alternate navigation bar titles
74
+
75
+ If you want a page to have a different title in the navigation bar than that
76
+ of the page itself, add a `navtitle:` property to the page's front matter:
77
+
78
+ ```md
79
+ ---
80
+ title: Since brevity is the soul of wit, I'll be brief.
81
+ navtitle: Polonius's advice
82
+ ---
83
+ ```
84
+
69
85
  ### Development
70
86
 
71
87
  First, choose a Jekyll site you'd like to use to view the impact of your
@@ -7,9 +7,9 @@
7
7
  aria-hidden="{% if expand_nav == 'true' %}false{% else %}true{% endif %}">
8
8
  {% for child in parent.children %}
9
9
  {% capture child_url %}{{ parent_url }}{{ child.url }}{% endcapture %}
10
- <li class="{% if page.title == child.text %}sidebar-nav-active{% endif %}">
10
+ <li class="{% if page.url == child_url %}sidebar-nav-active{% endif %}">
11
11
  <a href="{% if child.internal == true %}{{ site.baseurl }}{{ child_url }}{% else %}{{ child.url }}{% endif %}"
12
- title="{% if page.title == child.text %}Current Page{% else %}{{ child.text }}{% endif %}">{{ child.text }}</a>
12
+ title="{% if page.url == child_url %}Current Page{% else %}{{ child.text }}{% endif %}">{{ child.text }}</a>
13
13
  {% assign parent = child %}{% assign parent_url = child_url %}
14
14
  {% guides_style_18f_include sidebar-children.html %}
15
15
  {% capture parent_url %}{% guides_style_18f_pop_last_url_component parent_url %}{% endcapture %}
@@ -1,13 +1,12 @@
1
1
  <aside>
2
2
  <p class="intro">{{ site.subtitle }}</p>
3
3
  <nav class="sidebar-nav" role="navigation">
4
- <ul>{% for link in site.navigation %}
5
- <li class="group {% if page.title == link.text %}sidebar-nav-active{% endif %}">
4
+ <ul>{% for link in site.navigation %}{% capture parent_url %}/{{ link.url }}{% endcapture %}
5
+ <li class="group {% if page.url == parent_url %}sidebar-nav-active{% endif %}">
6
6
  <a href="{% if link.internal == true %}{{ site.baseurl }}/{% endif %}{{ link.url }}"
7
- title="{% if page.title == link.text %}Current Page
7
+ title="{% if page.url == parent_url %}Current Page
8
8
  {% else %}{{ link.text }}{% endif %}">{{ link.text }}</a>
9
9
  {% assign parent = link %}
10
- {% capture parent_url %}/{{ link.url }}{% endcapture %}
11
10
  {% guides_style_18f_include sidebar-children.html %}
12
11
  </li>{% endfor %}
13
12
  </ul>
@@ -5,6 +5,8 @@ require 'safe_yaml'
5
5
 
6
6
  module GuidesStyle18F
7
7
  module FrontMatter
8
+ EXTNAMES = %w(.md .html)
9
+
8
10
  def self.load(basedir)
9
11
  # init_file_to_front_matter_map is initializing the map with a nil value
10
12
  # for every file that _should_ contain front matter as far as the
@@ -87,7 +89,8 @@ module GuidesStyle18F
87
89
  Dir.chdir(basedir) do
88
90
  pages_dir = Dir.exist?('_pages') ? '_pages' : 'pages'
89
91
  Dir[File.join(pages_dir, '**', '*')].each do |file_name|
90
- next unless File.file?(file_name)
92
+ extname = File.extname(file_name)
93
+ next unless File.file?(file_name) && EXTNAMES.include?(extname)
91
94
  file_to_front_matter[file_name] = nil
92
95
  end
93
96
  end
@@ -119,111 +122,121 @@ module GuidesStyle18F
119
122
  config_data = SafeYAML.load_file config_path, safe: true
120
123
  return unless config_data
121
124
  nav_data = config_data['navigation'] || []
122
- update_navigation_data(nav_data, basedir)
123
- write_navigation_data_to_config_file(config_path, nav_data)
125
+ NavigationMenu.update_navigation_data(nav_data, basedir)
126
+ NavigationMenu.write_navigation_data_to_config_file(config_path, nav_data)
124
127
  end
125
128
 
126
129
  private
127
130
 
128
- def self.update_navigation_data(nav_data, basedir)
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
- end
131
+ module NavigationMenu
132
+ def self.update_navigation_data(nav_data, basedir)
133
+ original = map_nav_items_by_url('/', nav_data).to_h
134
+ updated = updated_nav_data(basedir)
135
+ remove_stale_nav_entries(nav_data, original, updated)
136
+ updated.map { |url, nav| apply_nav_update(url, nav, nav_data, original) }
137
+ check_for_orphaned_items(nav_data)
138
+ end
135
139
 
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'] || []))
140
+ def self.map_nav_items_by_url(parent_url, nav_data)
141
+ nav_data.flat_map do |nav|
142
+ url = File.join('', parent_url, nav['url'] || '')
143
+ [[url, nav]].concat(map_nav_items_by_url(url, nav['children'] || []))
144
+ end
140
145
  end
141
- end
142
146
 
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
149
- end
147
+ def self.updated_nav_data(basedir)
148
+ front_matter = FrontMatter.load basedir
149
+ errors = FrontMatter.validate_with_message_upon_error front_matter
150
+ abort errors + "\n_config.yml not updated" if errors
151
+ front_matter.values.sort_by { |fm| fm['permalink'] }
152
+ .map { |fm| [fm['permalink'], page_nav(fm)] }.to_h
153
+ end
150
154
 
151
- def self.page_nav(front_matter)
152
- url_components = front_matter['permalink'].split('/')[1..-1]
153
- result = {
154
- 'text' => front_matter['title'],
155
- 'url' => "#{url_components.nil? ? '' : url_components.last}/",
156
- 'internal' => true,
157
- }
158
- # Delete the root URL so we don't have an empty `url:` property laying
159
- # around.
160
- result.delete 'url' if result['url'] == '/'
161
- result
162
- end
155
+ def self.page_nav(front_matter)
156
+ url_components = front_matter['permalink'].split('/')[1..-1]
157
+ result = {
158
+ 'text' => front_matter['navtitle'] || front_matter['title'],
159
+ 'url' => "#{url_components.nil? ? '' : url_components.last}/",
160
+ 'internal' => true,
161
+ }
162
+ # Delete the root URL so we don't have an empty `url:` property laying
163
+ # around.
164
+ result.delete 'url' if result['url'] == '/'
165
+ result
166
+ end
163
167
 
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
+ def self.remove_stale_nav_entries(nav_data, original, updated)
169
+ # Remove old entries whose pages have been deleted
170
+ original.each do |url, nav|
171
+ nav['delete'] = true if !updated.member?(url) && nav['internal']
172
+ end
173
+ original.delete_if { |_url, nav| nav['delete'] }
174
+ nav_data.delete_if { |nav| nav['delete'] }
175
+ nav_data.each { |nav| remove_stale_children(nav) }
168
176
  end
169
- original.delete_if { |_url, nav| nav['delete'] }
170
- nav_data.delete_if { |nav| nav['delete'] }
171
- end
172
177
 
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']
178
+ def self.remove_stale_children(parent)
179
+ children = (parent['children'] || [])
180
+ children.delete_if { |nav| nav['delete'] }
181
+ parent.delete 'children' if children.empty?
182
+ children.each { |child| remove_stale_children(child) }
183
+ end
184
+
185
+ def self.apply_nav_update(url, nav, nav_data, original)
186
+ orig = original[url]
187
+ if orig.nil?
188
+ apply_new_nav_item(url, nav, nav_data, original)
189
+ else
190
+ orig['text'] = nav['text']
191
+ end
179
192
  end
180
- end
181
193
 
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 }
189
- else
190
- (parent['children'] ||= []) << nav
194
+ def self.apply_new_nav_item(url, nav, nav_data, original)
195
+ parent_url = File.dirname(url || '/')
196
+ parent = original["#{parent_url}/"]
197
+ if parent_url == '/'
198
+ nav_data << (original[url] = nav)
199
+ elsif parent.nil?
200
+ nav_data << { orphan_url: url }
201
+ else
202
+ (parent['children'] ||= []) << nav
203
+ end
191
204
  end
192
- end
193
205
 
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 "))
206
+ def self.check_for_orphaned_items(nav_data)
207
+ orphans = nav_data.map { |nav| nav[:orphan_url] }.compact
208
+ unless orphans.empty?
209
+ fail(StandardError, "Parent pages missing for the following:\n " +
210
+ orphans.join("\n "))
211
+ end
199
212
  end
200
- end
201
213
 
202
- def self.write_navigation_data_to_config_file(config_path, nav_data)
203
- lines = []
204
- in_navigation = false
205
- open(config_path).each_line do |line|
206
- in_navigation = process_line line, lines, nav_data, in_navigation
214
+ def self.write_navigation_data_to_config_file(config_path, nav_data)
215
+ lines = []
216
+ in_navigation = false
217
+ open(config_path).each_line do |line|
218
+ in_navigation = process_line line, lines, nav_data, in_navigation
219
+ end
220
+ File.write config_path, lines.join
207
221
  end
208
- File.write config_path, lines.join
209
- end
210
222
 
211
- def self.process_line(line, lines, nav_data, in_navigation = false)
212
- if !in_navigation && line.start_with?('navigation:')
213
- lines << line << format_navigation_section(nav_data)
214
- in_navigation = true
215
- elsif in_navigation
216
- in_navigation = line.start_with?(' ') || line.start_with?('-')
217
- lines << line unless in_navigation
218
- else
219
- lines << line
220
- end
221
- in_navigation
222
- end
223
+ def self.process_line(line, lines, nav_data, in_navigation = false)
224
+ if !in_navigation && line.start_with?('navigation:')
225
+ lines << line << format_navigation_section(nav_data)
226
+ in_navigation = true
227
+ elsif in_navigation
228
+ in_navigation = line.start_with?(' ') || line.start_with?('-')
229
+ lines << line unless in_navigation
230
+ else
231
+ lines << line
232
+ end
233
+ in_navigation
234
+ end
223
235
 
224
- YAML_PREFIX = "---\n"
236
+ YAML_PREFIX = "---\n"
225
237
 
226
- def self.format_navigation_section(nav_data)
227
- nav_data.empty? ? '' : nav_data.to_yaml[YAML_PREFIX.size..-1]
238
+ def self.format_navigation_section(nav_data)
239
+ nav_data.empty? ? '' : nav_data.to_yaml[YAML_PREFIX.size..-1]
240
+ end
228
241
  end
229
242
  end
@@ -9,6 +9,7 @@ module GuidesStyle18F
9
9
  _pages/add-a-new-page.md
10
10
  _pages/add-images.md
11
11
  _pages/github-setup.md
12
+ _pages/images.png
12
13
  _pages/post-your-guide.md
13
14
  _pages/update-the-config-file/understanding-baseurl.md
14
15
  _pages/update-the-config-file.md
@@ -19,7 +20,6 @@ module GuidesStyle18F
19
20
  images/gh-default-branch.png
20
21
  images/gh-settings-button.png
21
22
  images/gh-webhook.png
22
- images/images.png
23
23
  )
24
24
 
25
25
  def self.clear_template_files_and_create_new_repository(
@@ -13,6 +13,7 @@ module GuidesStyle18F
13
13
  end
14
14
 
15
15
  def render(context)
16
+ return true if context['site']['expand_nav']
16
17
  scope = context.scopes.detect { |s| s.member?(reference) }
17
18
  parent_url = scope[reference]
18
19
  page_url = context['page']['url']
@@ -1,5 +1,5 @@
1
1
  # @author Mike Bland (michael.bland@gsa.gov)
2
2
 
3
3
  module GuidesStyle18F
4
- VERSION = '0.1.13'
4
+ VERSION = '0.1.14'
5
5
  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.13
4
+ version: 0.1.14
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-13 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll