@@ -153,7 +153,102 @@ def is_a?(klass)
153
153
path : "/1/2/3/index.html" ,
154
154
metadata : { locals : { } } )
155
155
156
- current_page_html = '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>'
156
+ current_page_html = '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>' ;
157
+
158
+ config = {
159
+ http_prefix : "/" ,
160
+ tech_docs : {
161
+ max_toc_heading_level : 3
162
+ }
163
+ }
164
+
165
+ expected_multi_page_table_of_contents = %{
166
+ <ul><li><a href="/index.html">Index</a>
167
+ <ul>
168
+ <li>
169
+ <a href="/a.html#heading-one">Heading one</a>
170
+ <ul>
171
+ <li>
172
+ <a href="/a.html#heading-two">Heading two</a>
173
+ </li>
174
+ </ul>
175
+ </li>
176
+ </ul>
177
+ <ul>
178
+ <li>
179
+ <a href="/b.html#heading-one">Heading one</a>
180
+ <ul>
181
+ <li>
182
+ <a href="/b.html#heading-two">Heading two</a>
183
+ </li>
184
+ </ul>
185
+ </li>
186
+ </ul>
187
+ </li></ul>
188
+ }
189
+
190
+ expect ( subject . multi_page_table_of_contents ( resources , current_page , config , current_page_html ) . strip ) . to eq ( expected_multi_page_table_of_contents . strip )
191
+ end
192
+
193
+ it 'builds a table of contents from several page resources with a custom http prefix configured' do
194
+ resources = [ ]
195
+ resources [ 0 ] = FakeResource . new ( '/prefix/index.html' , '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>' , 10 , 'Index' ) ;
196
+ resources [ 1 ] = FakeResource . new ( '/prefix/a.html' , '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>' , 10 , 'Sub page A' , resources [ 0 ] ) ;
197
+ resources [ 2 ] = FakeResource . new ( '/prefix/b.html' , '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>' , 20 , 'Sub page B' , resources [ 0 ] ) ;
198
+ resources [ 0 ] . add_children [ resources [ 1 ] , resources [ 2 ] ]
199
+
200
+ current_page = double ( "current_page" ,
201
+ data : double ( "page_frontmatter" , description : "The description." , title : "The Title" ) ,
202
+ url : "/prefix/index.html" ,
203
+ metadata : { locals : { } } )
204
+
205
+ current_page_html = '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>' ;
206
+
207
+ config = {
208
+ http_prefix : "/prefix" ,
209
+ tech_docs : {
210
+ max_toc_heading_level : 3
211
+ }
212
+ }
213
+
214
+ expected_multi_page_table_of_contents = %{
215
+ <ul><li><a href="/prefix/index.html">Index</a>
216
+ <ul>
217
+ <li>
218
+ <a href="/prefix/a.html#heading-one">Heading one</a>
219
+ <ul>
220
+ <li>
221
+ <a href="/prefix/a.html#heading-two">Heading two</a>
222
+ </li>
223
+ </ul>
224
+ </li>
225
+ </ul>
226
+ <ul>
227
+ <li>
228
+ <a href="/prefix/b.html#heading-one">Heading one</a>
229
+ <ul>
230
+ <li>
231
+ <a href="/prefix/b.html#heading-two">Heading two</a>
232
+ </li>
233
+ </ul>
234
+ </li>
235
+ </ul>
236
+ </li></ul>
237
+ }
238
+
239
+ expect ( subject . multi_page_table_of_contents ( resources , current_page , config , current_page_html ) . strip ) . to eq ( expected_multi_page_table_of_contents . strip )
240
+ end
241
+
242
+ it 'builds a table of contents from a single page resources' do
243
+ resources = [ ]
244
+ resources . push FakeResource . new ( '/index.html' , '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2><h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2><h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>' ) ;
245
+
246
+ current_page = double ( "current_page" ,
247
+ data : double ( "page_frontmatter" , description : "The description." , title : "The Title" ) ,
248
+ url : "/index.html" ,
249
+ metadata : { locals : { } } )
250
+
251
+ current_page_html = '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2><h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2><h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>' ;
157
252
158
253
config = {
159
254
http_prefix : "/" ,
0 commit comments