nanoc-toolbox 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,999 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>Module: Nanoc::Toolbox::Helpers::Navigation</title>
7
+ <link rel="stylesheet" href="../../../css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="../../../css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '../../..';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <script type="text/javascript" charset="utf-8">
20
+ if (window.top.frames.main) document.body.className = 'frames';
21
+ </script>
22
+
23
+ <div id="header">
24
+ <div id="menu">
25
+
26
+ <a href="../../../_index.html">Index (N)</a> &raquo;
27
+ <span class='title'><span class='object_link'><a href="../../../Nanoc.html" title="Nanoc (module)">Nanoc</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../../Toolbox.html" title="Nanoc::Toolbox (module)">Toolbox</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Helpers.html" title="Nanoc::Toolbox::Helpers (module)">Helpers</a></span></span>
28
+ &raquo;
29
+ <span class="title">Navigation</span>
30
+
31
+
32
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
33
+ </div>
34
+
35
+ <div id="search">
36
+ <a id="class_list_link" href="#">Class List</a>
37
+ <a id="method_list_link" href="#">Method List</a>
38
+ <a id ="file_list_link" href="#">File List</a>
39
+ </div>
40
+
41
+ <div class="clear"></div>
42
+ </div>
43
+
44
+ <iframe id="search_frame"></iframe>
45
+
46
+ <div id="content"><h1>Module: Nanoc::Toolbox::Helpers::Navigation
47
+
48
+
49
+
50
+ </h1>
51
+
52
+ <dl class="box">
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+ <dt class="r1 last">Defined in:</dt>
62
+ <dd class="r1 last">lib/nanoc/toolbox/helpers/navigation.rb</dd>
63
+
64
+ </dl>
65
+ <div class="clear"></div>
66
+
67
+ <h2>Overview</h2><div class="docstring">
68
+ <div class="discussion">
69
+ <p>
70
+ NANOC Helper for the Navigation related stuff. This module contains
71
+ functions for generating navigation menus for your pages, like navigation
72
+ menu, breadcrumbs or a table of content for a given Item
73
+ </p>
74
+
75
+
76
+ </div>
77
+ </div>
78
+ <div class="tags">
79
+ <h3>Author:</h3>
80
+ <ul class="author">
81
+
82
+ <li>
83
+
84
+
85
+
86
+
87
+
88
+ <div class='inline'><p>
89
+ Anouar ADLANI <anouar@adlani.com>
90
+ </p>
91
+ </div>
92
+
93
+ </li>
94
+
95
+ </ul>
96
+
97
+ </div>
98
+
99
+
100
+
101
+ <h2>
102
+ Instance Method Summary
103
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
104
+ </h2>
105
+
106
+ <ul class="summary">
107
+
108
+ <li class="public ">
109
+ <span class="summary_signature">
110
+
111
+ <a href="#breadcrumb_for-instance_method" title="#breadcrumb_for (instance method)">- (String) <strong>breadcrumb_for</strong>(identifier, params = {}) </a>
112
+
113
+
114
+
115
+ </span>
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+ <span class="summary_desc"><div class='inline'><p>
125
+ Generate a Breadcrumb for a given item.
126
+ </p>
127
+ </div></span>
128
+
129
+ </li>
130
+
131
+
132
+ <li class="public ">
133
+ <span class="summary_signature">
134
+
135
+ <a href="#navigation_for-instance_method" title="#navigation_for (instance method)">- (String) <strong>navigation_for</strong>(identifier, params = {}) </a>
136
+
137
+
138
+
139
+ </span>
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+ <span class="summary_desc"><div class='inline'><p>
149
+ Generate a navigation menu for a given item.
150
+ </p>
151
+ </div></span>
152
+
153
+ </li>
154
+
155
+
156
+ <li class="public ">
157
+ <span class="summary_signature">
158
+
159
+ <a href="#render_menu-instance_method" title="#render_menu (instance method)">- (String) <strong>render_menu</strong>(items, params = {}) </a>
160
+
161
+
162
+
163
+ </span>
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+ <span class="summary_desc"><div class='inline'><p>
173
+ Render a Hash to a HTML List by default.
174
+ </p>
175
+ </div></span>
176
+
177
+ </li>
178
+
179
+
180
+ <li class="public ">
181
+ <span class="summary_signature">
182
+
183
+ <a href="#toc_for-instance_method" title="#toc_for (instance method)">- (String) <strong>toc_for</strong>(item_rep, params = {}) </a>
184
+
185
+
186
+
187
+ </span>
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+ <span class="summary_desc"><div class='inline'><p>
197
+ Generate a Table of Content for a given item.
198
+ </p>
199
+ </div></span>
200
+
201
+ </li>
202
+
203
+
204
+ </ul>
205
+
206
+
207
+
208
+
209
+ <div id="instance_method_details" class="method_details_list">
210
+ <h2>Instance Method Details</h2>
211
+
212
+
213
+ <div class="method_details first">
214
+ <p class="signature first" id="breadcrumb_for-instance_method">
215
+
216
+ - (<tt>String</tt>) <strong>breadcrumb_for</strong>(identifier, params = {})
217
+
218
+
219
+
220
+ </p><div class="docstring">
221
+ <div class="discussion">
222
+ <p>
223
+ Generate a Breadcrumb for a given item. The breadcrumbs, is starting with
224
+ the root item and ending with the item itself.
225
+ </p>
226
+ <p>
227
+ Requires the Helper: Nanoc3::Helpers::Breadcrumbs
228
+ </p>
229
+
230
+
231
+ </div>
232
+ </div>
233
+ <div class="tags">
234
+ <h3>Parameters:</h3>
235
+ <ul class="param">
236
+
237
+ <li>
238
+
239
+ <span class='type'>(<tt>String</tt>)</span>
240
+
241
+
242
+ <span class='name'>identifier</span>
243
+
244
+
245
+
246
+ &mdash;
247
+ <div class='inline'><ul>
248
+ <li><p>
249
+ the identifier string of element
250
+ </p>
251
+ </li>
252
+ </ul>
253
+ </div>
254
+
255
+ </li>
256
+
257
+ <li>
258
+
259
+ <span class='type'>(<tt>Hash</tt>)</span>
260
+
261
+
262
+ <span class='name'>params</span>
263
+
264
+
265
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
266
+
267
+
268
+ &mdash;
269
+ <div class='inline'><ul>
270
+ <li><p>
271
+ The Optional parameters
272
+ </p>
273
+ </li>
274
+ </ul>
275
+ </div>
276
+
277
+ </li>
278
+
279
+ </ul>
280
+
281
+
282
+
283
+
284
+
285
+
286
+ <h3>Options Hash (<tt>params</tt>):</h3>
287
+ <ul class="option">
288
+
289
+ <li>
290
+ <span class="type">(<tt>String</tt>)</span>
291
+ <span class="name">:collection_tag</span>
292
+ <span class="default">
293
+
294
+ &mdash; default:
295
+ <tt>'ol'</tt>
296
+
297
+ </span>
298
+ &mdash; <div class='inline'><p>
299
+ collection englobing tag name
300
+ </p>
301
+ </div>
302
+ </tr>
303
+
304
+ <li>
305
+ <span class="type">(<tt>String</tt>)</span>
306
+ <span class="name">:item_tag</span>
307
+ <span class="default">
308
+
309
+ &mdash; default:
310
+ <tt>'li'</tt>
311
+
312
+ </span>
313
+ &mdash; <div class='inline'><p>
314
+ item englobing tag name
315
+ </p>
316
+ </div>
317
+ </tr>
318
+
319
+ </ul>
320
+
321
+ <h3>Returns:</h3>
322
+ <ul class="return">
323
+
324
+ <li>
325
+
326
+ <span class='type'>(<tt>String</tt>)</span>
327
+
328
+
329
+
330
+
331
+ &mdash;
332
+ <div class='inline'><p>
333
+ The output ready to be displayed by the caller
334
+ </p>
335
+ </div>
336
+
337
+ </li>
338
+
339
+ </ul>
340
+
341
+ <h3>See Also:</h3>
342
+ <ul class="see">
343
+
344
+ <li>Nanoc3::Helpers::Breadcrumbs#breadcrumbs_for_identifier</li>
345
+
346
+ </ul>
347
+
348
+ </div><table class="source_code">
349
+ <tr>
350
+ <td>
351
+ <pre class="lines">
352
+
353
+
354
+ 88
355
+ 89
356
+ 90
357
+ 91
358
+ 92
359
+ 93
360
+ 94
361
+ 95
362
+ 96
363
+ 97</pre>
364
+ </td>
365
+ <td>
366
+ <pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 88</span>
367
+
368
+ <span class='kw'>def</span> <span class='id breadcrumb_for'>breadcrumb_for</span><span class='lparen'>(</span><span class='id identifier'>identifier</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
369
+
370
+ <span class='comment'># Parse params or set to default values
371
+ </span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ul</span><span class='tstring_end'>'</span></span>
372
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
373
+
374
+ <span class='comment'># Retreive the breadcrumbs trail and format them
375
+ </span> <span class='id sections'>sections</span> <span class='op'>=</span> <span class='id find_breadcrumbs_trail'>find_breadcrumbs_trail</span><span class='lparen'>(</span><span class='id identifier'>identifier</span><span class='rparen'>)</span>
376
+ <span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id sections'>sections</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
377
+ <span class='kw'>end</span></pre>
378
+ </td>
379
+ </tr>
380
+ </table>
381
+ </div>
382
+
383
+ <div class="method_details ">
384
+ <p class="signature " id="navigation_for-instance_method">
385
+
386
+ - (<tt>String</tt>) <strong>navigation_for</strong>(identifier, params = {})
387
+
388
+
389
+
390
+ </p><div class="docstring">
391
+ <div class="discussion">
392
+ <p>
393
+ Generate a navigation menu for a given item. The menu will be generated
394
+ form the identifier of the desired root element. The root itself will not
395
+ be rendered. It generate the menu by parsing all the descendent of the
396
+ passed item.
397
+ </p>
398
+
399
+
400
+ </div>
401
+ </div>
402
+ <div class="tags">
403
+ <h3>Parameters:</h3>
404
+ <ul class="param">
405
+
406
+ <li>
407
+
408
+ <span class='type'>(<tt>String</tt>)</span>
409
+
410
+
411
+ <span class='name'>identifier</span>
412
+
413
+
414
+
415
+ &mdash;
416
+ <div class='inline'><ul>
417
+ <li><p>
418
+ the identifier string of the root element
419
+ </p>
420
+ </li>
421
+ </ul>
422
+ </div>
423
+
424
+ </li>
425
+
426
+ <li>
427
+
428
+ <span class='type'>(<tt>Hash</tt>)</span>
429
+
430
+
431
+ <span class='name'>params</span>
432
+
433
+
434
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
435
+
436
+
437
+ &mdash;
438
+ <div class='inline'><ul>
439
+ <li><p>
440
+ The Optional parameters
441
+ </p>
442
+ </li>
443
+ </ul>
444
+ </div>
445
+
446
+ </li>
447
+
448
+ </ul>
449
+
450
+
451
+
452
+
453
+
454
+
455
+ <h3>Options Hash (<tt>params</tt>):</h3>
456
+ <ul class="option">
457
+
458
+ <li>
459
+ <span class="type">(<tt>Interger</tt>)</span>
460
+ <span class="name">:depth</span>
461
+ <span class="default">
462
+
463
+ &mdash; default:
464
+ <tt>3</tt>
465
+
466
+ </span>
467
+ &mdash; <div class='inline'><p>
468
+ maximum depth of the rendered menu
469
+ </p>
470
+ </div>
471
+ </tr>
472
+
473
+ <li>
474
+ <span class="type">(<tt>String</tt>)</span>
475
+ <span class="name">:collection_tag</span>
476
+ <span class="default">
477
+
478
+ &mdash; default:
479
+ <tt>'ol'</tt>
480
+
481
+ </span>
482
+ &mdash; <div class='inline'><p>
483
+ collection englobing tag name
484
+ </p>
485
+ </div>
486
+ </tr>
487
+
488
+ <li>
489
+ <span class="type">(<tt>String</tt>)</span>
490
+ <span class="name">:item_tag</span>
491
+ <span class="default">
492
+
493
+ &mdash; default:
494
+ <tt>'li'</tt>
495
+
496
+ </span>
497
+ &mdash; <div class='inline'><p>
498
+ item englobing tag name
499
+ </p>
500
+ </div>
501
+ </tr>
502
+
503
+ </ul>
504
+
505
+ <h3>Returns:</h3>
506
+ <ul class="return">
507
+
508
+ <li>
509
+
510
+ <span class='type'>(<tt>String</tt>)</span>
511
+
512
+
513
+
514
+
515
+ &mdash;
516
+ <div class='inline'><p>
517
+ The output ready to be displayed by the caller
518
+ </p>
519
+ </div>
520
+
521
+ </li>
522
+
523
+ </ul>
524
+
525
+ </div><table class="source_code">
526
+ <tr>
527
+ <td>
528
+ <pre class="lines">
529
+
530
+
531
+ 22
532
+ 23
533
+ 24
534
+ 25
535
+ 26
536
+ 27
537
+ 28
538
+ 29
539
+ 30
540
+ 31
541
+ 32
542
+ 33
543
+ 34
544
+ 35
545
+ 36
546
+ 37
547
+ 38
548
+ 39
549
+ 40</pre>
550
+ </td>
551
+ <td>
552
+ <pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 22</span>
553
+
554
+ <span class='kw'>def</span> <span class='id navigation_for'>navigation_for</span><span class='lparen'>(</span><span class='id identifier'>identifier</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
555
+ <span class='comment'># Parse params or set to default values
556
+ </span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='int'>3</span>
557
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ol</span><span class='tstring_end'>'</span></span>
558
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
559
+
560
+ <span class='comment'># Decrease the depth level
561
+ </span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>-=</span> <span class='int'>1</span>
562
+
563
+ <span class='comment'># Get root item for which we need to draw the navigation
564
+ </span> <span class='id root'>root</span> <span class='op'>=</span> <span class='ivar'>@items</span><span class='period'>.</span><span class='id find'>find</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id i'>i</span><span class='op'>|</span> <span class='id i'>i</span><span class='period'>.</span><span class='id identifier'>identifier</span> <span class='op'>==</span> <span class='id identifier'>identifier</span> <span class='rbrace'>}</span>
565
+
566
+ <span class='comment'># Do not render if there is no child
567
+ </span> <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id root'>root</span><span class='period'>.</span><span class='id children'>children</span>
568
+
569
+ <span class='comment'># Find all sections, and render them
570
+ </span> <span class='id sections'>sections</span> <span class='op'>=</span> <span class='id find_item_tree'>find_item_tree</span><span class='lparen'>(</span><span class='id root'>root</span><span class='rparen'>)</span>
571
+ <span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id sections'>sections</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
572
+ <span class='kw'>end</span></pre>
573
+ </td>
574
+ </tr>
575
+ </table>
576
+ </div>
577
+
578
+ <div class="method_details ">
579
+ <p class="signature " id="render_menu-instance_method">
580
+
581
+ - (<tt>String</tt>) <strong>render_menu</strong>(items, params = {})
582
+
583
+
584
+
585
+ </p><div class="docstring">
586
+ <div class="discussion">
587
+ <p>
588
+ Render a Hash to a HTML List by default
589
+ </p>
590
+ <p>
591
+ Hash structure should be construct like this:
592
+ </p>
593
+ <pre class="code">
594
+ Link: is an hash with the following key
595
+ * :title =&gt; The content of the link
596
+ * :link =&gt; The link
597
+ * :subsections =&gt; nil or an Array of Links
598
+
599
+ [{:title =&gt; 'Title', :link =&gt; 'http://example.com', :subsections =&gt; [{}, {}, ...]},{...}]
600
+ </pre>
601
+ <p>
602
+ Results to an output like the following (by default):
603
+ </p>
604
+ <pre class="code">
605
+ &lt;ul&gt;
606
+ &lt;li&gt;
607
+ &lt;a href=&quot;http://example.com&quot;&gt;Title&lt;/a&gt;
608
+ &lt;ul&gt;
609
+ &lt;li&gt;&lt;a href=&quot;&quot;&gt;Title&lt;/a&gt;&lt;/li&gt;
610
+ &lt;/ul&gt;
611
+ &lt;/li&gt;
612
+ &lt;li&gt;&lt;a href=&quot;http://example.com&quot;&gt;Title&lt;/a&gt;&lt;/li&gt;
613
+ &lt;li&gt;&lt;a href=&quot;http://example.com&quot;&gt;Title&lt;/a&gt;&lt;/li&gt;
614
+ &lt;/ul&gt;</pre>
615
+
616
+
617
+ </div>
618
+ </div>
619
+ <div class="tags">
620
+ <h3>Parameters:</h3>
621
+ <ul class="param">
622
+
623
+ <li>
624
+
625
+ <span class='type'>(<tt>Array</tt>)</span>
626
+
627
+
628
+ <span class='name'>items</span>
629
+
630
+
631
+
632
+ &mdash;
633
+ <div class='inline'><ul>
634
+ <li><p>
635
+ The array of links that need to be rendered
636
+ </p>
637
+ </li>
638
+ </ul>
639
+ </div>
640
+
641
+ </li>
642
+
643
+ <li>
644
+
645
+ <span class='type'>(<tt>Hash</tt>)</span>
646
+
647
+
648
+ <span class='name'>params</span>
649
+
650
+
651
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
652
+
653
+
654
+ &mdash;
655
+ <div class='inline'><ul>
656
+ <li><p>
657
+ The Optional parameters
658
+ </p>
659
+ </li>
660
+ </ul>
661
+ </div>
662
+
663
+ </li>
664
+
665
+ </ul>
666
+
667
+
668
+
669
+
670
+
671
+
672
+ <h3>Options Hash (<tt>params</tt>):</h3>
673
+ <ul class="option">
674
+
675
+ <li>
676
+ <span class="type">(<tt>String</tt>)</span>
677
+ <span class="name">:collection_tag</span>
678
+ <span class="default">
679
+
680
+ &mdash; default:
681
+ <tt>'ol'</tt>
682
+
683
+ </span>
684
+ &mdash; <div class='inline'><p>
685
+ collection englobing tag name
686
+ </p>
687
+ </div>
688
+ </tr>
689
+
690
+ <li>
691
+ <span class="type">(<tt>String</tt>)</span>
692
+ <span class="name">:item_tag</span>
693
+ <span class="default">
694
+
695
+ &mdash; default:
696
+ <tt>'li'</tt>
697
+
698
+ </span>
699
+ &mdash; <div class='inline'><p>
700
+ item englobing tag name
701
+ </p>
702
+ </div>
703
+ </tr>
704
+
705
+ </ul>
706
+
707
+ <h3>Returns:</h3>
708
+ <ul class="return">
709
+
710
+ <li>
711
+
712
+ <span class='type'>(<tt>String</tt>)</span>
713
+
714
+
715
+
716
+
717
+ &mdash;
718
+ <div class='inline'><p>
719
+ The output ready to be displayed by the caller
720
+ </p>
721
+ </div>
722
+
723
+ </li>
724
+
725
+ </ul>
726
+
727
+ </div><table class="source_code">
728
+ <tr>
729
+ <td>
730
+ <pre class="lines">
731
+
732
+
733
+ 128
734
+ 129
735
+ 130
736
+ 131
737
+ 132
738
+ 133
739
+ 134
740
+ 135
741
+ 136
742
+ 137
743
+ 138
744
+ 139
745
+ 140
746
+ 141
747
+ 142
748
+ 143
749
+ 144
750
+ 145
751
+ 146
752
+ 147
753
+ 148
754
+ 149
755
+ 150
756
+ 151</pre>
757
+ </td>
758
+ <td>
759
+ <pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 128</span>
760
+
761
+ <span class='kw'>def</span> <span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id items'>items</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
762
+
763
+ <span class='comment'># Parse params or set to default values
764
+ </span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='int'>3</span>
765
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ol</span><span class='tstring_end'>'</span></span>
766
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
767
+
768
+ <span class='comment'># Decrease the depth level
769
+ </span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>-=</span> <span class='int'>1</span>
770
+
771
+ <span class='id rendered_menu'>rendered_menu</span> <span class='op'>=</span> <span class='id items'>items</span><span class='period'>.</span><span class='id map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id item'>item</span><span class='op'>|</span>
772
+
773
+ <span class='comment'># Render only if there is depth left
774
+ </span> <span class='kw'>if</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id to_i'>to_i</span> <span class='op'>&gt;=</span> <span class='int'>0</span> <span class='op'>&amp;&amp;</span> <span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:subsections</span><span class='rbracket'>]</span>
775
+ <span class='id output'>output</span> <span class='op'>=</span> <span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:subsections</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
776
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='comment'># Increase the depth level after the call of navigation_for
777
+ </span> <span class='kw'>end</span>
778
+ <span class='id output'>output</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span>
779
+ <span class='id content_tag'>content_tag</span><span class='lparen'>(</span><span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id link_to'>link_to</span><span class='lparen'>(</span><span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:title</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:link</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>+</span> <span class='id output'>output</span><span class='rparen'>)</span>
780
+
781
+ <span class='kw'>end</span><span class='period'>.</span><span class='id join'>join</span><span class='lparen'>(</span><span class='rparen'>)</span>
782
+
783
+ <span class='id content_tag'>content_tag</span><span class='lparen'>(</span><span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id rendered_menu'>rendered_menu</span><span class='rparen'>)</span>
784
+ <span class='kw'>end</span></pre>
785
+ </td>
786
+ </tr>
787
+ </table>
788
+ </div>
789
+
790
+ <div class="method_details ">
791
+ <p class="signature " id="toc_for-instance_method">
792
+
793
+ - (<tt>String</tt>) <strong>toc_for</strong>(item_rep, params = {})
794
+
795
+
796
+
797
+ </p><div class="docstring">
798
+ <div class="discussion">
799
+ <p>
800
+ Generate a Table of Content for a given item. The toc will be generated
801
+ form the item content. The parsing is done with Nokogiri through XPath.
802
+ </p>
803
+
804
+
805
+ </div>
806
+ </div>
807
+ <div class="tags">
808
+ <h3>Parameters:</h3>
809
+ <ul class="param">
810
+
811
+ <li>
812
+
813
+ <span class='type'>(<tt>String</tt>)</span>
814
+
815
+
816
+ <span class='name'>item_rep</span>
817
+
818
+
819
+
820
+ &mdash;
821
+ <div class='inline'><ul>
822
+ <li><p>
823
+ the representation of desired item
824
+ </p>
825
+ </li>
826
+ </ul>
827
+ </div>
828
+
829
+ </li>
830
+
831
+ <li>
832
+
833
+ <span class='type'>(<tt>Hash</tt>)</span>
834
+
835
+
836
+ <span class='name'>params</span>
837
+
838
+
839
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
840
+
841
+
842
+ &mdash;
843
+ <div class='inline'><ul>
844
+ <li><p>
845
+ The Optional parameters
846
+ </p>
847
+ </li>
848
+ </ul>
849
+ </div>
850
+
851
+ </li>
852
+
853
+ </ul>
854
+
855
+
856
+
857
+
858
+
859
+
860
+ <h3>Options Hash (<tt>params</tt>):</h3>
861
+ <ul class="option">
862
+
863
+ <li>
864
+ <span class="type">(<tt>Interger</tt>)</span>
865
+ <span class="name">:depth</span>
866
+ <span class="default">
867
+
868
+ &mdash; default:
869
+ <tt>3</tt>
870
+
871
+ </span>
872
+ &mdash; <div class='inline'><p>
873
+ maximum depth of the rendered menu
874
+ </p>
875
+ </div>
876
+ </tr>
877
+
878
+ <li>
879
+ <span class="type">(<tt>String</tt>)</span>
880
+ <span class="name">:collection_tag</span>
881
+ <span class="default">
882
+
883
+ &mdash; default:
884
+ <tt>'ol'</tt>
885
+
886
+ </span>
887
+ &mdash; <div class='inline'><p>
888
+ collection englobing tag name
889
+ </p>
890
+ </div>
891
+ </tr>
892
+
893
+ <li>
894
+ <span class="type">(<tt>String</tt>)</span>
895
+ <span class="name">:item_tag</span>
896
+ <span class="default">
897
+
898
+ &mdash; default:
899
+ <tt>'li'</tt>
900
+
901
+ </span>
902
+ &mdash; <div class='inline'><p>
903
+ item englobing tag name
904
+ </p>
905
+ </div>
906
+ </tr>
907
+
908
+ </ul>
909
+
910
+ <h3>Returns:</h3>
911
+ <ul class="return">
912
+
913
+ <li>
914
+
915
+ <span class='type'>(<tt>String</tt>)</span>
916
+
917
+
918
+
919
+
920
+ &mdash;
921
+ <div class='inline'><p>
922
+ The output ready to be displayed by the caller
923
+ </p>
924
+ </div>
925
+
926
+ </li>
927
+
928
+ </ul>
929
+
930
+ <h3>See Also:</h3>
931
+ <ul class="see">
932
+
933
+ <li><a href="http://nokogiri.org/" target="_parent" title="http://nokogiri.org/">http://nokogiri.org/</a></li>
934
+
935
+ </ul>
936
+
937
+ </div><table class="source_code">
938
+ <tr>
939
+ <td>
940
+ <pre class="lines">
941
+
942
+
943
+ 55
944
+ 56
945
+ 57
946
+ 58
947
+ 59
948
+ 60
949
+ 61
950
+ 62
951
+ 63
952
+ 64
953
+ 65
954
+ 66
955
+ 67
956
+ 68
957
+ 69
958
+ 70
959
+ 71
960
+ 72</pre>
961
+ </td>
962
+ <td>
963
+ <pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 55</span>
964
+
965
+ <span class='kw'>def</span> <span class='id toc_for'>toc_for</span><span class='lparen'>(</span><span class='id item_rep'>item_rep</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
966
+ <span class='id require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nokogiri</span><span class='tstring_end'>'</span></span>
967
+
968
+ <span class='comment'># Parse params or set to default values
969
+ </span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='int'>3</span>
970
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ol</span><span class='tstring_end'>'</span></span>
971
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
972
+ <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:path</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>div[@class=&quot;section&quot;]</span><span class='tstring_end'>'</span></span>
973
+
974
+ <span class='comment'># Retreive the parsed content and init nokogiri
975
+ </span> <span class='id compiled_content'>compiled_content</span> <span class='op'>=</span> <span class='id item_rep'>item_rep</span><span class='period'>.</span><span class='id instance_eval'>instance_eval</span> <span class='lbrace'>{</span> <span class='ivar'>@content</span><span class='lbracket'>[</span><span class='symbol'>:pre</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
976
+ <span class='id doc'>doc</span> <span class='op'>=</span> <span class='const'>Nokogiri</span><span class='op'>::</span><span class='const'>HTML</span><span class='lparen'>(</span><span class='id compiled_content'>compiled_content</span><span class='rparen'>)</span>
977
+ <span class='id doc_root'>doc_root</span> <span class='op'>=</span> <span class='id doc'>doc</span><span class='period'>.</span><span class='id xpath'>xpath</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/html/body</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id first'>first</span>
978
+
979
+ <span class='comment'># Find all sections, and render them
980
+ </span> <span class='id sections'>sections</span> <span class='op'>=</span> <span class='id find_toc_sections'>find_toc_sections</span><span class='lparen'>(</span><span class='id doc_root'>doc_root</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:path</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span>
981
+ <span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id sections'>sections</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
982
+ <span class='kw'>end</span></pre>
983
+ </td>
984
+ </tr>
985
+ </table>
986
+ </div>
987
+
988
+ </div>
989
+
990
+ </div>
991
+
992
+ <div id="footer">
993
+ Generated on Thu Jan 6 16:04:02 2011 by
994
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
995
+ 0.6.4 (ruby-1.9.2).
996
+ </div>
997
+
998
+ </body>
999
+ </html>