middleman-pagegroups 1.0.2 → 1.0.3
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/.gitignore +8 -1
- data/.yardopts +8 -0
- data/CHANGELOG.md +24 -4
- data/README.md +5 -5
- data/Rakefile +201 -7
- data/documentation_project/Gemfile +2 -2
- data/documentation_project/config.rb +15 -19
- data/documentation_project/source/documentation/100_nested_folder/another_file.html.md.erb +19 -0
- data/documentation_project/source/documentation/100_nested_folder/index.html.md.erb +25 -0
- data/documentation_project/source/documentation/100_nested_folder/one_file.html.md.erb +11 -0
- data/documentation_project/source/documentation/100_nested_folder/stray.txt +6 -0
- data/documentation_project/source/documentation/10_concepts.html.md.erb +1 -1
- data/documentation_project/source/documentation/20_directory_organization.html.md.erb +12 -10
- data/documentation_project/source/documentation/40_resources.html.md.erb +3 -68
- data/documentation_project/source/documentation/50_helpers.html.md.erb +41 -163
- data/documentation_project/source/documentation/60_sample_partials.html.md.erb +23 -22
- data/documentation_project/source/documentation/80_config.html.md.erb +6 -0
- data/documentation_project/source/documentation/90_cli.html.md.erb +47 -0
- data/documentation_project/source/partials/_yard_config.erb +744 -0
- data/documentation_project/source/partials/_yard_helpers.erb +710 -0
- data/documentation_project/source/partials/_yard_helpers_css.erb +523 -0
- data/documentation_project/source/partials/_yard_helpers_extended.erb +56 -0
- data/documentation_project/source/partials/_yard_resources.erb +540 -0
- data/documentation_project/source/stylesheets/_middlemac_minimal.scss +287 -0
- data/features/helpers_and_resources.feature +120 -0
- data/features/support/env.rb +20 -0
- data/fixtures/middleman_pagegroups_app/config.rb +17 -0
- data/fixtures/middleman_pagegroups_app/source/20_sub_folder_02/index.html.md.erb +8 -0
- data/fixtures/middleman_pagegroups_app/source/20_sub_folder_02/not_legitimate.html.md.erb +8 -0
- data/fixtures/middleman_pagegroups_app/source/20_sub_folder_02/sibling_one.html.md.erb +8 -0
- data/fixtures/middleman_pagegroups_app/source/20_sub_folder_02/sibling_two.html.md.erb +8 -0
- data/fixtures/middleman_pagegroups_app/source/_partial.md.erb +111 -0
- data/fixtures/middleman_pagegroups_app/source/index.html.md.erb +23 -0
- data/fixtures/middleman_pagegroups_app/source/layout.erb +6 -0
- data/fixtures/middleman_pagegroups_app/source/sub_folder_01/10_sibling_one.html.md.erb +7 -0
- data/fixtures/middleman_pagegroups_app/source/sub_folder_01/20_sibling_two.html.md.erb +7 -0
- data/fixtures/middleman_pagegroups_app/source/sub_folder_01/30_sibling_three.html.md.erb +7 -0
- data/fixtures/middleman_pagegroups_app/source/sub_folder_01/index.html.md.erb +9 -0
- data/lib/middleman-pagegroups/extension.rb +468 -110
- data/lib/middleman-pagegroups/partials.rb +9 -12
- data/lib/middleman-pagegroups/version.rb +1 -1
- data/middleman-pagegroups.gemspec +10 -2
- data/yard/readme.md +5 -0
- data/yard/template-grouped/default/module/html/method_details_list.erb +11 -0
- data/yard/template-partials/default/method_details/setup.rb +4 -0
- data/yard/template-partials/default/module/html/attribute_details.erb +9 -0
- data/yard/template-partials/default/module/html/method_details_list.erb +10 -0
- data/yard/template-partials/default/module/setup.rb +6 -0
- data/yard/template-partials/default/onefile/html/layout.erb +1 -0
- data/yard/template-partials/default/onefile/html/setup.rb +4 -0
- data/yard/yard_extensions.rb +109 -0
- metadata +105 -7
@@ -0,0 +1,111 @@
|
|
1
|
+
## page_classes helper
|
2
|
+
|
3
|
+
~~~
|
4
|
+
page_classes: <%= page_classes %>
|
5
|
+
~~~
|
6
|
+
|
7
|
+
* * *
|
8
|
+
|
9
|
+
## Resource Extensions
|
10
|
+
|
11
|
+
~~~
|
12
|
+
current_resource.breadcrumbs:<%= current_resource.breadcrumbs || 'nil' %>
|
13
|
+
~~~
|
14
|
+
|
15
|
+
~~~
|
16
|
+
current_resource.brethren:<%= current_resource.brethren || 'nil' %>
|
17
|
+
~~~
|
18
|
+
|
19
|
+
~~~
|
20
|
+
current_resource.brethren_next:<%= current_resource.brethren_next || 'nil' %>
|
21
|
+
~~~
|
22
|
+
|
23
|
+
~~~
|
24
|
+
current_resource.brethren_previous:<%= current_resource.brethren_previous || 'nil' %>
|
25
|
+
~~~
|
26
|
+
|
27
|
+
~~~
|
28
|
+
current_resource.group_count:<%= current_resource.group_count || 'nil' %>
|
29
|
+
~~~
|
30
|
+
|
31
|
+
~~~
|
32
|
+
current_resource.legitimate_children:<%= current_resource.legitimate_children || 'nil' %>
|
33
|
+
~~~
|
34
|
+
|
35
|
+
~~~
|
36
|
+
current_resource.navigator_eligible:<%= current_resource.navigator_eligible? || 'nil' %>
|
37
|
+
~~~
|
38
|
+
|
39
|
+
~~~
|
40
|
+
current_resource.page_group:<%= current_resource.page_group || 'nil' %>
|
41
|
+
~~~
|
42
|
+
|
43
|
+
~~~
|
44
|
+
current_resource.page_name:<%= current_resource.page_name || 'nil' %>
|
45
|
+
~~~
|
46
|
+
|
47
|
+
~~~
|
48
|
+
current_resource.page_sequence:<%= current_resource.page_sequence || 'nil' %>
|
49
|
+
~~~
|
50
|
+
|
51
|
+
~~~
|
52
|
+
current_resource.parent:<%= current_resource.parent || 'nil' %>
|
53
|
+
~~~
|
54
|
+
|
55
|
+
~~~
|
56
|
+
current_resource.sort_order:<%= current_resource.sort_order || 'nil' %>
|
57
|
+
~~~
|
58
|
+
|
59
|
+
* * *
|
60
|
+
|
61
|
+
## Content Helpers
|
62
|
+
|
63
|
+
nav_breadcrumbs:
|
64
|
+
|
65
|
+
~~~
|
66
|
+
<%= nav_breadcrumbs %>
|
67
|
+
~~~
|
68
|
+
|
69
|
+
nav_breadcrumbs_alt:
|
70
|
+
|
71
|
+
~~~
|
72
|
+
<%= nav_breadcrumbs_alt %>
|
73
|
+
~~~
|
74
|
+
|
75
|
+
nav_brethren:
|
76
|
+
|
77
|
+
~~~
|
78
|
+
<%= nav_brethren %>
|
79
|
+
~~~
|
80
|
+
|
81
|
+
nav_brethren_index:
|
82
|
+
|
83
|
+
~~~
|
84
|
+
<%= nav_brethren_index %>
|
85
|
+
~~~
|
86
|
+
|
87
|
+
nav_legitimate_children:
|
88
|
+
|
89
|
+
~~~
|
90
|
+
<%= nav_legitimate_children %>
|
91
|
+
~~~
|
92
|
+
|
93
|
+
nav_prev_next:
|
94
|
+
|
95
|
+
~~~
|
96
|
+
<%= nav_prev_next %>
|
97
|
+
~~~
|
98
|
+
|
99
|
+
nav_toc_index:
|
100
|
+
|
101
|
+
~~~
|
102
|
+
<%= nav_toc_index %>
|
103
|
+
~~~
|
104
|
+
|
105
|
+
nav_toc_index (from top):
|
106
|
+
|
107
|
+
~~~
|
108
|
+
<%= nav_toc_index(:start => current_page.breadcrumbs.first) %>
|
109
|
+
~~~
|
110
|
+
|
111
|
+
* * *
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
title: Main Index Page
|
3
|
+
blurb: This is the main index file.
|
4
|
+
navigate: false
|
5
|
+
---
|
6
|
+
|
7
|
+
#<%= current_page.data.title %>
|
8
|
+
<%= current_page.data.blurb %>
|
9
|
+
|
10
|
+
* * *
|
11
|
+
|
12
|
+
## CSS Helpers
|
13
|
+
|
14
|
+
- nav_breadcrumbs_alt_class: <%= nav_breadcrumbs_alt_class %>
|
15
|
+
- nav_breadcrumbs_alt_label: <%= nav_breadcrumbs_alt_label %>
|
16
|
+
- nav_breadcrumbs_class: <%= nav_breadcrumbs_class %>
|
17
|
+
- nav_brethren_class: <%= nav_brethren_class %>
|
18
|
+
- nav_brethren_index_class: <%= nav_brethren_index_class %>
|
19
|
+
- nav_legitimate_children_class: <%= nav_legitimate_children_class %>
|
20
|
+
- nav_prev_next_class: <%= nav_prev_next_class %>
|
21
|
+
- nav_prev_next_label_next: <%= nav_prev_next_label_next %>
|
22
|
+
- nav_prev_next_label_prev: <%= nav_prev_next_label_prev %>
|
23
|
+
- nav_toc_index_class: <%= nav_toc_index_class %>
|
@@ -1,10 +1,12 @@
|
|
1
|
-
################################################################################
|
2
|
-
# extension.rb
|
3
|
-
# This file constitutes the framework for the bulk of this extension.
|
4
|
-
################################################################################
|
5
1
|
require 'middleman-core'
|
6
2
|
require 'middleman-pagegroups/partials'
|
7
3
|
|
4
|
+
################################################################################
|
5
|
+
# This extension provides advanced navigation tools and helpers for grouping
|
6
|
+
# pages by topic and navigating between them. It includes support for tables
|
7
|
+
# of content, related pages, breadcrumbs, and more.
|
8
|
+
# @author Jim Derry <balthisar@gmail.com>
|
9
|
+
################################################################################
|
8
10
|
class MiddlemanPageGroups < ::Middleman::Extension
|
9
11
|
|
10
12
|
|
@@ -26,20 +28,157 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
26
28
|
option :nav_prev_next_label_next, 'Next', 'Default "next" label text for the nav_prev_next helper/partial.'
|
27
29
|
option :nav_toc_index_class, nil, 'Default css class for the nav_toc_index helper/partial.'
|
28
30
|
|
31
|
+
# @!group Extension Configuration
|
32
|
+
|
33
|
+
# @!attribute [rw] options[:strip_file_prefixes]=
|
34
|
+
# If `true` leading numbers used for sorting files will be removed for
|
35
|
+
# presentation purposes. This makes it possible to neatly organize your
|
36
|
+
# source files in their presentation order on your filesystem but output
|
37
|
+
# nice filenames without ugly prefix numbers.
|
38
|
+
# @param [Boolean] value `true` or `false` to enable or disable this feature.
|
39
|
+
# @return [Boolean] Returns the current value of this option.
|
40
|
+
|
41
|
+
# @!attribute [rw] options[:extend_page_class]=
|
42
|
+
# If true then the default **Middleman** `page_class` helper will be extended
|
43
|
+
# to include simple `group` and `page_name` for each resource.
|
44
|
+
# @param [Boolean] value `true` or `false` to enable or disable this feature.
|
45
|
+
# @return [Boolean] Returns the current value of this option.
|
46
|
+
|
47
|
+
# @!attribute [rw] options[:nav_breadcrumbs_class]=
|
48
|
+
# Default css class for the `nav_breadcrumbs` helper/partial.
|
49
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
50
|
+
# containing element.
|
51
|
+
# @return [String] Returns the current value of this option.
|
52
|
+
|
53
|
+
# @!attribute [rw] options[:nav_breadcrumbs_alt_class]=
|
54
|
+
# Default css class for the `nav_breadcrumbs_alt` helper/partial.
|
55
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
56
|
+
# containing element.
|
57
|
+
# @return [String] Returns the current value of this option.
|
58
|
+
|
59
|
+
# @!attribute [rw] options[:nav_breadcrumbs_alt_label]=
|
60
|
+
# Default "current page" label for the `nav_breadcrumbs_alt` helper/partial.
|
61
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
62
|
+
# containing element.
|
63
|
+
# @return [String] Returns the current value of this option.
|
64
|
+
|
65
|
+
# @!attribute [rw] options[:nav_brethren_class]=
|
66
|
+
# Default css class for the `nav_brethren` helper/partial.
|
67
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
68
|
+
# containing element.
|
69
|
+
# @return [String] Returns the current value of this option.
|
70
|
+
|
71
|
+
# @!attribute [rw] options[:nav_brethren_index_class]=
|
72
|
+
# Default css class for the `nav_brethren_index` helper/partial.
|
73
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
74
|
+
# containing element.
|
75
|
+
# @return [String] Returns the current value of this option.
|
76
|
+
|
77
|
+
# @!attribute [rw] options[:nav_legitimate_children_class]=
|
78
|
+
# Default css class for the `nav_legitimate_children` helper/partial.
|
79
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
80
|
+
# containing element.
|
81
|
+
# @return [String] Returns the current value of this option.
|
82
|
+
|
83
|
+
# @!attribute [rw] options[:nav_prev_next_class]=
|
84
|
+
# Default css class for the `nav_prev_next` helper/partial.
|
85
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
86
|
+
# containing element.
|
87
|
+
# @return [String] Returns the current value of this option.
|
88
|
+
|
89
|
+
# @!attribute [rw] options[:nav_prev_next_label_prev]=
|
90
|
+
# Default "previous" label text for the `nav_prev_next` helper/partial.
|
91
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
92
|
+
# containing element.
|
93
|
+
# @return [String] Returns the current value of this option.
|
94
|
+
|
95
|
+
# @!attribute [rw] options[:nav_prev_next_label_next]=
|
96
|
+
# Default "next" label text for the `nav_prev_next` helper/partial.
|
97
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
98
|
+
# containing element.
|
99
|
+
# @return [String] Returns the current value of this option.
|
100
|
+
|
101
|
+
# @!attribute [rw] options[:nav_toc_index_class]=
|
102
|
+
# Default css class for the `nav_toc_index` helper/partial.
|
103
|
+
# @param [String] value The `class` attribute value to use for this item’s
|
104
|
+
# containing element.
|
105
|
+
# @return [String] Returns the current value of this option.
|
106
|
+
|
107
|
+
# @!endgroup
|
108
|
+
|
29
109
|
|
30
110
|
############################################################
|
31
111
|
# Sitemap manipulators.
|
32
112
|
# Add new methods to each resource.
|
33
113
|
############################################################
|
114
|
+
|
115
|
+
#--------------------------------------------------------
|
116
|
+
# We must ensure that for any directory the index_file
|
117
|
+
# is first. This is so that we can check it for a page
|
118
|
+
# order and rename the containing directory in output.
|
119
|
+
# @!visibility private
|
120
|
+
#--------------------------------------------------------
|
121
|
+
def resource_sort_comparator( x, y )
|
122
|
+
if File.basename(x.path) == app.config[:index_file]
|
123
|
+
-1
|
124
|
+
else
|
125
|
+
if File.dirname(x.path) == File.dirname(y.path)
|
126
|
+
return File.basename(x.path) <=> File.basename(y.path)
|
127
|
+
else
|
128
|
+
return File.dirname(x.path) <=> File.dirname(y.path)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
#--------------------------------------------------------
|
135
|
+
# Add our own resource methods to each resource in the
|
136
|
+
# site map.
|
137
|
+
# @!visibility private
|
138
|
+
#--------------------------------------------------------
|
34
139
|
def manipulate_resource_list(resources)
|
35
140
|
|
36
|
-
resources.
|
141
|
+
resources.sort { |a,b| resource_sort_comparator(a,b) }
|
142
|
+
.each do |resource|
|
143
|
+
|
144
|
+
#--------------------------------------------------------
|
145
|
+
# Return the parent of the resource. This implementation
|
146
|
+
# corrects a bug in **Middleman** as of 4.1.7 wherein
|
147
|
+
# **Middleman** doesn’t return the parent if the the
|
148
|
+
# directory has been renamed for output.
|
149
|
+
# @return [Sitemap::Resource] The resource instance of
|
150
|
+
# the resource’s parent.
|
151
|
+
#--------------------------------------------------------
|
152
|
+
def resource.parent
|
153
|
+
root = path.sub(/^#{::Regexp.escape(traversal_root)}/, '')
|
154
|
+
parts = root.split('/')
|
155
|
+
|
156
|
+
tail = parts.pop
|
157
|
+
is_index = (tail == @app.config[:index_file])
|
158
|
+
|
159
|
+
if parts.empty?
|
160
|
+
return is_index ? nil : @store.find_resource_by_path(@app.config[:index_file])
|
161
|
+
end
|
162
|
+
|
163
|
+
test_expr = parts.join('\\/')
|
164
|
+
# eponymous reverse-lookup
|
165
|
+
found = @store.resources.find do |candidate|
|
166
|
+
candidate.path =~ %r{^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$}
|
167
|
+
end
|
168
|
+
|
169
|
+
if found
|
170
|
+
found
|
171
|
+
else
|
172
|
+
parts.pop if is_index
|
173
|
+
@store.find_resource_by_path("#{parts.join('/')}/#{@app.config[:index_file]}")
|
174
|
+
end
|
175
|
+
end
|
37
176
|
|
38
177
|
#--------------------------------------------------------
|
39
|
-
# page_name
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
178
|
+
# Make `page_name` available for each resource. This is
|
179
|
+
# the file’s base name after any renaming has occurred.
|
180
|
+
# Useful for assigning classes, etc.
|
181
|
+
# @return [String] The `page_name` of the current page.
|
43
182
|
#--------------------------------------------------------
|
44
183
|
def resource.page_name
|
45
184
|
File.basename( self.destination_path, '.*' )
|
@@ -47,22 +186,26 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
47
186
|
|
48
187
|
|
49
188
|
#--------------------------------------------------------
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# conditionals.
|
189
|
+
# Make `page_group` available for each resource.
|
190
|
+
# Useful for for assigning classes, and/or group
|
191
|
+
# conditionals.
|
192
|
+
# @return [String] The `page_group` of the current page.
|
55
193
|
#--------------------------------------------------------
|
56
194
|
def resource.page_group
|
57
|
-
File.basename( File.split( self.
|
195
|
+
result = File.basename( File.split( self.destination_path )[0] )
|
196
|
+
if result == '.'
|
197
|
+
result = @app.config[:source]
|
198
|
+
end
|
199
|
+
result
|
58
200
|
end
|
59
201
|
|
60
202
|
|
61
203
|
#--------------------------------------------------------
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
204
|
+
# Returns the quantity of pages in the current page’s
|
205
|
+
# group, including this current page, i.e., the number
|
206
|
+
# of `brethren + 1`.
|
207
|
+
# @return [Integer] The total number of pages in the
|
208
|
+
# this page’s current group.
|
66
209
|
#--------------------------------------------------------
|
67
210
|
def resource.group_count
|
68
211
|
self.brethren.count + 1
|
@@ -70,10 +213,15 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
70
213
|
|
71
214
|
|
72
215
|
#--------------------------------------------------------
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
216
|
+
# Returns the page sort order or 0 if no page sort order
|
217
|
+
# was applied.
|
218
|
+
#
|
219
|
+
# Pages without a sort order can still be linked to;
|
220
|
+
# they simply aren't brethren or legitimate children,
|
221
|
+
# and so don’t participate in any of the automatic
|
222
|
+
# navigation features.
|
223
|
+
# @return [Integer] The current resource’s sort order
|
224
|
+
# within its group, or 0 if no sort order was applied.
|
77
225
|
#--------------------------------------------------------
|
78
226
|
def resource.sort_order
|
79
227
|
options[:sort_order]
|
@@ -81,10 +229,12 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
81
229
|
|
82
230
|
|
83
231
|
#--------------------------------------------------------
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
232
|
+
# Returns the page sequence amongst all of the brethren,
|
233
|
+
# and can be used as a page number surrogate. The first
|
234
|
+
# page is 1. Pages without a sort order will have a `nil`
|
235
|
+
# `page_sequence`.
|
236
|
+
# @return [Integer, Nil] The current page sequence of
|
237
|
+
# this resource among its brethren.
|
88
238
|
#--------------------------------------------------------
|
89
239
|
def resource.page_sequence
|
90
240
|
if self.sort_order == 0
|
@@ -100,15 +250,17 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
100
250
|
|
101
251
|
|
102
252
|
#--------------------------------------------------------
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
253
|
+
# Returns an array of all of the siblings of this page,
|
254
|
+
# taking into account their eligibility for display.
|
255
|
+
#
|
256
|
+
# * is not already the current page.
|
257
|
+
# * has a `sort_order`.
|
258
|
+
# * is not ignored.
|
259
|
+
#
|
260
|
+
# The returned array will be sorted by each item’s
|
261
|
+
# `sort_order`.
|
262
|
+
# @return [Array<Sitemap::Resource>] An array of
|
263
|
+
# resources.
|
112
264
|
#--------------------------------------------------------
|
113
265
|
def resource.brethren
|
114
266
|
self.siblings
|
@@ -118,8 +270,10 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
118
270
|
|
119
271
|
|
120
272
|
#--------------------------------------------------------
|
121
|
-
#
|
122
|
-
#
|
273
|
+
# Returns the next sibling based on order, or `nil` if
|
274
|
+
# there is no next sibling.
|
275
|
+
# @return [Sitemap::Resource] The resource instance of
|
276
|
+
# the next sibling.
|
123
277
|
#--------------------------------------------------------
|
124
278
|
def resource.brethren_next
|
125
279
|
if self.sort_order == 0
|
@@ -131,8 +285,10 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
131
285
|
|
132
286
|
|
133
287
|
#--------------------------------------------------------
|
134
|
-
#
|
135
|
-
#
|
288
|
+
# Returns the previous sibling based on order, or `nil`
|
289
|
+
# if there is no previous sibling.
|
290
|
+
# @return [Sitemap::Resource] The resource instance of
|
291
|
+
# the previous sibling.
|
136
292
|
#--------------------------------------------------------
|
137
293
|
def resource.brethren_previous
|
138
294
|
if self.sort_order == 0
|
@@ -144,12 +300,17 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
144
300
|
|
145
301
|
|
146
302
|
#--------------------------------------------------------
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
303
|
+
# Determines whether a page is eligible to include a
|
304
|
+
# previous/next page control. This is based on:
|
305
|
+
#
|
306
|
+
# * The group is set to allow navigation via the
|
307
|
+
# `:navigate` front matter key.
|
308
|
+
# * This page is not excluded from navigation via the
|
309
|
+
# use of `:navigator => false` in its front matter.
|
310
|
+
# * This page has a `sort_order`.
|
311
|
+
#
|
312
|
+
# @return (Boolean) Returns `true` if this pages is
|
313
|
+
# eligible for a previous/next page control.
|
153
314
|
#--------------------------------------------------------
|
154
315
|
def resource.navigator_eligible?
|
155
316
|
group_navigates = self.parent && self.parent.data['navigate'] == true
|
@@ -160,14 +321,18 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
160
321
|
|
161
322
|
|
162
323
|
#--------------------------------------------------------
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
324
|
+
# Returns an array of all of the children of this
|
325
|
+
# resource, taking into account their eligibility for
|
326
|
+
# display. Each child is legitimate if it:
|
327
|
+
#
|
328
|
+
# * has a sort_order.
|
329
|
+
# * is not ignored.
|
330
|
+
#
|
331
|
+
# The returned array will be sorted by each item’s
|
332
|
+
# `sort_order`.
|
333
|
+
#
|
334
|
+
# @return [Array<Sitemap::Resource>] An array of
|
335
|
+
# resources.
|
171
336
|
#--------------------------------------------------------
|
172
337
|
def resource.legitimate_children
|
173
338
|
self.children
|
@@ -177,9 +342,9 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
177
342
|
|
178
343
|
|
179
344
|
#--------------------------------------------------------
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
345
|
+
# Returns an array of resources leading to this resource.
|
346
|
+
# @return [Array<Sitemap::Resource>] An array of
|
347
|
+
# resources.
|
183
348
|
#--------------------------------------------------------
|
184
349
|
def resource.breadcrumbs
|
185
350
|
hierarchy = [] << self
|
@@ -201,22 +366,71 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
201
366
|
# If :strip_file_prefixes, then additionally we will
|
202
367
|
# prettify the output page name.
|
203
368
|
#========================================================
|
369
|
+
strip = @app.extensions[:MiddlemanPageGroups].options[:strip_file_prefixes]
|
370
|
+
page_name = File.basename(resource.path, '.*')
|
371
|
+
path_part = File.dirname(resource.destination_path)
|
372
|
+
|
204
373
|
if resource.content_type && resource.content_type.start_with?('text/html', 'application/xhtml')
|
205
|
-
|
374
|
+
|
375
|
+
file_renamed = false
|
376
|
+
# Set the resource's sort order if provided via various means.
|
206
377
|
if resource.data.key?('order')
|
378
|
+
# Priority for ordering goes to the :order front matter key.
|
207
379
|
sort_order = resource.data['order']
|
208
380
|
elsif ( match = /^(\d*?)_/.match(page_name) )
|
381
|
+
# Otherwise if the file has an integer prefix we will use that.
|
382
|
+
sort_order = match[1]
|
383
|
+
elsif ( match = /^(\d*?)_/.match(path_part.split('/').last) ) && File.basename( resource.path ) == app.config[:index_file]
|
384
|
+
# Otherwise if we're an index file then set the sort order based on
|
385
|
+
# its containing group. Because we sorted the resources, we are sure
|
386
|
+
# that this is the first resource to be processed in this directory.
|
209
387
|
sort_order = match[1]
|
210
|
-
if @app.extensions[:MiddlemanPageGroups].options[:strip_file_prefixes]
|
211
|
-
path_part = File.dirname( resource.destination_path )
|
212
|
-
name_part = page_name.sub( "#{sort_order}_", '') + File.extname( resource.path )
|
213
|
-
resource.destination_path = File.join( path_part, name_part )
|
214
|
-
end
|
215
388
|
else
|
216
389
|
sort_order = nil
|
217
390
|
end
|
218
391
|
|
392
|
+
# Remove the sort order indicator from the file or directory name.
|
393
|
+
# This will only change the output path for files that have a sort
|
394
|
+
# order. Other files in a renamed directory that needs to have their
|
395
|
+
# paths changed will be changed below.
|
396
|
+
if strip && sort_order
|
397
|
+
path_parts = path_part.split('/')
|
398
|
+
path_parts.last.sub!(/^(\d*?)_/, '')
|
399
|
+
path_part = path_parts.join('/')
|
400
|
+
name_part = page_name.sub( "#{sort_order}_", '') + File.extname( resource.path )
|
401
|
+
if path_part == '.'
|
402
|
+
resource.destination_path = name_part
|
403
|
+
else
|
404
|
+
resource.destination_path = File.join(path_part, name_part)
|
405
|
+
end
|
406
|
+
file_renamed = true
|
407
|
+
end
|
408
|
+
|
219
409
|
resource.options[:sort_order] = sort_order.to_i
|
410
|
+
|
411
|
+
end
|
412
|
+
|
413
|
+
unless file_renamed
|
414
|
+
|
415
|
+
# For other files, check to see if there's an index file in this source
|
416
|
+
# directory. If so then our rules state it will have a sort order, which
|
417
|
+
# means we can ensure that our output path is without a sorting prefix.
|
418
|
+
# If there is, then make sure OUR immediate destination directory is
|
419
|
+
# the same as the index file’s, in case we've renamed it.
|
420
|
+
index_file = [path_part, app.config[:index_file] ].join('/')
|
421
|
+
index_found = resources.select { |r| r.path == index_file }[0]
|
422
|
+
|
423
|
+
if strip && index_found && index_found.options[:sort_order]
|
424
|
+
path_part = File.dirname(index_found.destination_path)
|
425
|
+
name_part = File.basename(resource.destination_path)
|
426
|
+
if path_part == '.'
|
427
|
+
resource.destination_path = name_part
|
428
|
+
else
|
429
|
+
resource.destination_path = File.join(path_part, name_part)
|
430
|
+
end
|
431
|
+
|
432
|
+
end
|
433
|
+
|
220
434
|
end
|
221
435
|
|
222
436
|
|
@@ -237,9 +451,13 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
237
451
|
|
238
452
|
|
239
453
|
#--------------------------------------------------------
|
240
|
-
# page_classes
|
241
|
-
#
|
242
|
-
#
|
454
|
+
# Extend the built-in page_classes to include the naked
|
455
|
+
# group and page name. The features of this helper are
|
456
|
+
# enabled only if `options[:extend_page_class]` is
|
457
|
+
# `true`.
|
458
|
+
# @return [String] Returns the classes that correspond
|
459
|
+
# to the site hierarchy.
|
460
|
+
# @group Extended Helpers
|
243
461
|
#--------------------------------------------------------
|
244
462
|
def page_classes
|
245
463
|
if extensions[:MiddlemanPageGroups].options[:extend_page_class]
|
@@ -256,11 +474,16 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
256
474
|
# them instead of installing partials.
|
257
475
|
#########################################################
|
258
476
|
|
477
|
+
|
259
478
|
#--------------------------------------------------------
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
263
|
-
#
|
479
|
+
# Generates a breadcrumbs structure as an `<ul>`. The
|
480
|
+
# trailing element is the current page.
|
481
|
+
# @param [Hash] locals A hash of key-value pairs that
|
482
|
+
# are passed to the structure as local variables.
|
483
|
+
# @option locals [String] :klass The `class` attribute
|
484
|
+
# value that should be assigned to the containing
|
485
|
+
# element.
|
486
|
+
# @return [String] An `<ul>` containing the breadcrumbs.
|
264
487
|
#--------------------------------------------------------
|
265
488
|
def nav_breadcrumbs( locals = {} )
|
266
489
|
locals[:klass] = locals.delete(:class) if locals.key?(:class)
|
@@ -269,11 +492,17 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
269
492
|
|
270
493
|
|
271
494
|
#--------------------------------------------------------
|
272
|
-
#
|
273
|
-
#
|
274
|
-
#
|
275
|
-
#
|
276
|
-
#
|
495
|
+
# Generates the breadcrumbs structure, alternate form,
|
496
|
+
# wherein the trailing element consists of a label
|
497
|
+
# indicating “current page,” as an `<ul>`.
|
498
|
+
# @param [Hash] locals A hash of key-value pairs that
|
499
|
+
# are passed to the structure as local variables.
|
500
|
+
# @option locals [String] :klass The `class` attribute
|
501
|
+
# value that should be assigned to the containing
|
502
|
+
# element.
|
503
|
+
# @option locals [String] :label The text for the label
|
504
|
+
# that means “Current page.”
|
505
|
+
# @return [String] An `<ul>` containing the breadcrumbs.
|
277
506
|
#--------------------------------------------------------
|
278
507
|
def nav_breadcrumbs_alt( locals = {} )
|
279
508
|
locals[:klass] = locals.delete(:class) if locals.key?(:class)
|
@@ -281,12 +510,19 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
281
510
|
end
|
282
511
|
|
283
512
|
#--------------------------------------------------------
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
513
|
+
# Generates a fuller list of related topics as a `<dl>`,
|
514
|
+
# with a link to the page as the definition term and the
|
515
|
+
# page’s front matter `:blurb` as the definition
|
516
|
+
# definition.
|
517
|
+
# @param [Hash] locals A hash of key-value pairs that
|
518
|
+
# are passed to the structure as local variables.
|
519
|
+
# @option locals [String] :klass The `class` attribute
|
520
|
+
# value that should be assigned to the containing
|
521
|
+
# element.
|
522
|
+
# @option locals [Sitemap::Resource] :start The resource
|
523
|
+
# from which to start the list. If not specified,
|
524
|
+
# then this resource’s brethren will be listed.
|
525
|
+
# @return [String] A `<dl>` containing the list.
|
290
526
|
#--------------------------------------------------------
|
291
527
|
def nav_brethren( locals = {} )
|
292
528
|
locals[:klass] = locals.delete(:class) if locals.key?(:class)
|
@@ -295,12 +531,17 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
295
531
|
|
296
532
|
|
297
533
|
#--------------------------------------------------------
|
298
|
-
#
|
299
|
-
#
|
300
|
-
#
|
301
|
-
#
|
302
|
-
#
|
303
|
-
#
|
534
|
+
# Generates a condensed list of related topics as an
|
535
|
+
# `<ul>`, omitting the `:blurb` front matter data.
|
536
|
+
# @param [Hash] locals A hash of key-value pairs that
|
537
|
+
# are passed to the structure as local variables.
|
538
|
+
# @option locals [String] :klass The `class` attribute
|
539
|
+
# value that should be assigned to the containing
|
540
|
+
# element.
|
541
|
+
# @option locals [Sitemap::Resource] :start The resource
|
542
|
+
# from which to start the list. If not specified,
|
543
|
+
# then this resource’s brethren will be listed.
|
544
|
+
# @return [String] An `<ul>` containing the list.
|
304
545
|
#--------------------------------------------------------
|
305
546
|
def nav_brethren_index(locals = {})
|
306
547
|
locals[:klass] = locals.delete(:class) if locals.key?(:class)
|
@@ -309,11 +550,19 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
309
550
|
|
310
551
|
|
311
552
|
#--------------------------------------------------------
|
312
|
-
#
|
313
|
-
#
|
314
|
-
#
|
315
|
-
#
|
316
|
-
#
|
553
|
+
# Generates a fuller list of child topics as a `<dl>`,
|
554
|
+
# with a link to the page as the definition term and the
|
555
|
+
# page’s front matter `:blurb` as the definition
|
556
|
+
# definition.
|
557
|
+
# @param [Hash] locals A hash of key-value pairs that
|
558
|
+
# are passed to the structure as local variables.
|
559
|
+
# @option locals [String] :klass The `class` attribute
|
560
|
+
# value that should be assigned to the containing
|
561
|
+
# element.
|
562
|
+
# @option locals [Sitemap::Resource] :start The resource
|
563
|
+
# from which to start the list. If not specified,
|
564
|
+
# then this resource’s children will be listed.
|
565
|
+
# @return [String] A `<dl>` containing the list.
|
317
566
|
#--------------------------------------------------------
|
318
567
|
def nav_legitimate_children(locals = {})
|
319
568
|
locals[:klass] = locals.delete(:class) if locals.key?(:class)
|
@@ -322,12 +571,19 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
322
571
|
|
323
572
|
|
324
573
|
#--------------------------------------------------------
|
325
|
-
#
|
326
|
-
#
|
327
|
-
#
|
328
|
-
#
|
329
|
-
#
|
330
|
-
#
|
574
|
+
# Generates a previous and next item as two anchors
|
575
|
+
# nested within a `<div>`. With appropriate CSS this
|
576
|
+
# can be rendered as a set of navigation buttons.
|
577
|
+
# @param [Hash] locals A hash of key-value pairs that
|
578
|
+
# are passed to the structure as local variables.
|
579
|
+
# @option locals [String] :klass The `class` attribute
|
580
|
+
# value that should be assigned to the containing
|
581
|
+
# element.
|
582
|
+
# @option locals [String] :label_previous The text for
|
583
|
+
# the label that means “Previous page.”
|
584
|
+
# @option locals [String] :label_next The text for the
|
585
|
+
# label that means “Next page.”
|
586
|
+
# @return [String] A `<div>` containing the links.
|
331
587
|
#--------------------------------------------------------
|
332
588
|
def nav_prev_next(locals = {})
|
333
589
|
locals[:klass] = locals.delete(:class) if locals.key?(:class)
|
@@ -336,14 +592,18 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
336
592
|
|
337
593
|
|
338
594
|
#--------------------------------------------------------
|
339
|
-
#
|
340
|
-
#
|
341
|
-
#
|
342
|
-
#
|
343
|
-
#
|
344
|
-
#
|
345
|
-
#
|
346
|
-
#
|
595
|
+
# Generate a nested `<ul>` structure representing the
|
596
|
+
# complete table of contents from any particular
|
597
|
+
# starting point.
|
598
|
+
# @param [Hash] locals A hash of key-value pairs that
|
599
|
+
# are passed to the structure as local variables.
|
600
|
+
# @option locals [String] :klass The `class` attribute
|
601
|
+
# value that should be assigned to the containing
|
602
|
+
# element.
|
603
|
+
# @option locals [Sitemap::Resource] :start The resource
|
604
|
+
# from which to start the list. If not specified,
|
605
|
+
# then this resource will be used as the root.
|
606
|
+
# @return [String] An `<ul>` containing the list.
|
347
607
|
#--------------------------------------------------------
|
348
608
|
def nav_toc_index( locals = {} )
|
349
609
|
recurse = locals.key?(:recurse) && locals[:recurse]
|
@@ -379,47 +639,146 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
379
639
|
|
380
640
|
|
381
641
|
#########################################################
|
382
|
-
#
|
383
|
-
#
|
384
|
-
#
|
642
|
+
# @!macro [new] class_helpers
|
643
|
+
# Both the built-in helpers and the partials (if you
|
644
|
+
# install them) use these helpers in order to access the
|
645
|
+
# configuration values. When writing your own partials
|
646
|
+
# it is generally unnecessary to use these helpers; you
|
647
|
+
# can simply assign your own class name.
|
648
|
+
#
|
649
|
+
# The provided helpers and partials use CSS classes, and
|
650
|
+
# if the class names collide with your own class names
|
651
|
+
# or fail to meet with your naming standards, then they
|
652
|
+
# can be changed using the extension options.
|
385
653
|
#########################################################
|
386
654
|
|
655
|
+
|
656
|
+
#--------------------------------------------------------
|
657
|
+
# Returns the value of the the extension option
|
658
|
+
# `options[:nav_breadcrumbs_class]`.
|
659
|
+
#
|
660
|
+
# @!macro class_helpers
|
661
|
+
#
|
662
|
+
# @return [String] Returns the name of the class.
|
663
|
+
# @group CSS Class Helpers
|
664
|
+
#--------------------------------------------------------
|
387
665
|
def nav_breadcrumbs_class
|
388
666
|
extensions[:MiddlemanPageGroups].options[:nav_breadcrumbs_class]
|
389
667
|
end
|
390
668
|
|
669
|
+
#--------------------------------------------------------
|
670
|
+
# Returns the value of the the extension option
|
671
|
+
# `options[:nav_breadcrumbs_alt_class]`.
|
672
|
+
#
|
673
|
+
# @!macro class_helpers
|
674
|
+
#
|
675
|
+
# @return [String] Returns the name of the class.
|
676
|
+
# @group CSS Class Helpers
|
677
|
+
#--------------------------------------------------------
|
391
678
|
def nav_breadcrumbs_alt_class
|
392
679
|
extensions[:MiddlemanPageGroups].options[:nav_breadcrumbs_alt_class]
|
393
680
|
end
|
394
681
|
|
682
|
+
#--------------------------------------------------------
|
683
|
+
# Returns the value of the the extension option
|
684
|
+
# `options[:nav_breadcrumbs_alt_label]`.
|
685
|
+
#
|
686
|
+
# @!macro class_helpers
|
687
|
+
#
|
688
|
+
# @return [String] Returns the name of the class.
|
689
|
+
# @group CSS Class Helpers
|
690
|
+
#--------------------------------------------------------
|
395
691
|
def nav_breadcrumbs_alt_label
|
396
692
|
extensions[:MiddlemanPageGroups].options[:nav_breadcrumbs_alt_label]
|
397
693
|
end
|
398
694
|
|
695
|
+
#--------------------------------------------------------
|
696
|
+
# Returns the value of the the extension option
|
697
|
+
# `options[:nav_brethren_class]`.
|
698
|
+
#
|
699
|
+
# @!macro class_helpers
|
700
|
+
#
|
701
|
+
# @return [String] Returns the name of the class.
|
702
|
+
# @group CSS Class Helpers
|
703
|
+
#--------------------------------------------------------
|
399
704
|
def nav_brethren_class
|
400
705
|
extensions[:MiddlemanPageGroups].options[:nav_brethren_class]
|
401
706
|
end
|
402
707
|
|
708
|
+
#--------------------------------------------------------
|
709
|
+
# Returns the value of the the extension option
|
710
|
+
# `options[:nav_brethren_index_class]`.
|
711
|
+
#
|
712
|
+
# @!macro class_helpers
|
713
|
+
#
|
714
|
+
# @return [String] Returns the name of the class.
|
715
|
+
# @group CSS Class Helpers
|
716
|
+
#--------------------------------------------------------
|
403
717
|
def nav_brethren_index_class
|
404
718
|
extensions[:MiddlemanPageGroups].options[:nav_brethren_index_class]
|
405
719
|
end
|
406
720
|
|
721
|
+
#--------------------------------------------------------
|
722
|
+
# Returns the value of the the extension option
|
723
|
+
# `options[:nav_legitimate_children_class]`.
|
724
|
+
#
|
725
|
+
# @!macro class_helpers
|
726
|
+
#
|
727
|
+
# @return [String] Returns the name of the class.
|
728
|
+
# @group CSS Class Helpers
|
729
|
+
#--------------------------------------------------------
|
407
730
|
def nav_legitimate_children_class
|
408
731
|
extensions[:MiddlemanPageGroups].options[:nav_legitimate_children_class]
|
409
732
|
end
|
410
733
|
|
734
|
+
#--------------------------------------------------------
|
735
|
+
# Returns the value of the the extension option
|
736
|
+
# `options[:nav_prev_next_class]`.
|
737
|
+
#
|
738
|
+
# @!macro class_helpers
|
739
|
+
#
|
740
|
+
# @return [String] Returns the name of the class.
|
741
|
+
# @group CSS Class Helpers
|
742
|
+
#--------------------------------------------------------
|
411
743
|
def nav_prev_next_class
|
412
744
|
extensions[:MiddlemanPageGroups].options[:nav_prev_next_class]
|
413
745
|
end
|
414
746
|
|
747
|
+
#--------------------------------------------------------
|
748
|
+
# Returns the value of the the extension option
|
749
|
+
# `options[:nav_prev_next_label_prev]`.
|
750
|
+
#
|
751
|
+
# @!macro class_helpers
|
752
|
+
#
|
753
|
+
# @return [String] Returns the name of the class.
|
754
|
+
# @group CSS Class Helpers
|
755
|
+
#--------------------------------------------------------
|
415
756
|
def nav_prev_next_label_prev
|
416
757
|
extensions[:MiddlemanPageGroups].options[:nav_prev_next_label_prev]
|
417
758
|
end
|
418
759
|
|
760
|
+
#--------------------------------------------------------
|
761
|
+
# Returns the value of the the extension option
|
762
|
+
# `options[:nav_prev_next_label_next]`.
|
763
|
+
#
|
764
|
+
# @!macro class_helpers
|
765
|
+
#
|
766
|
+
# @return [String] Returns the name of the class.
|
767
|
+
# @group CSS Class Helpers
|
768
|
+
#--------------------------------------------------------
|
419
769
|
def nav_prev_next_label_next
|
420
770
|
extensions[:MiddlemanPageGroups].options[:nav_prev_next_label_next]
|
421
771
|
end
|
422
772
|
|
773
|
+
#--------------------------------------------------------
|
774
|
+
# Returns the value of the the extension option
|
775
|
+
# `options[:nav_toc_index_class]`.
|
776
|
+
#
|
777
|
+
# @!macro class_helpers
|
778
|
+
#
|
779
|
+
# @return [String] Returns the name of the class.
|
780
|
+
# @group CSS Class Helpers
|
781
|
+
#--------------------------------------------------------
|
423
782
|
def nav_toc_index_class
|
424
783
|
extensions[:MiddlemanPageGroups].options[:nav_breadcrumbs_alt_class]
|
425
784
|
end
|
@@ -427,5 +786,4 @@ class MiddlemanPageGroups < ::Middleman::Extension
|
|
427
786
|
|
428
787
|
end #helpers
|
429
788
|
|
430
|
-
|
431
789
|
end # class MiddlemanPageGroups
|