File: HTree.html

package info (click to toggle)
htree 0.7-5
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,360 kB
  • ctags: 930
  • sloc: ruby: 5,770; makefile: 69
file content (932 lines) | stat: -rw-r--r-- 27,383 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: HTree</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">HTree</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/htree/modules_rb.html">
                htree/modules.rb
                </a>
        <br />
                <a href="../files/htree/context_rb.html">
                htree/context.rb
                </a>
        <br />
                <a href="../files/htree/display_rb.html">
                htree/display.rb
                </a>
        <br />
                <a href="../files/htree/doc_rb.html">
                htree/doc.rb
                </a>
        <br />
                <a href="../files/htree/elem_rb.html">
                htree/elem.rb
                </a>
        <br />
                <a href="../files/htree/encoder_rb.html">
                htree/encoder.rb
                </a>
        <br />
                <a href="../files/htree/equality_rb.html">
                htree/equality.rb
                </a>
        <br />
                <a href="../files/htree/extract_text_rb.html">
                htree/extract_text.rb
                </a>
        <br />
                <a href="../files/htree/fstr_rb.html">
                htree/fstr.rb
                </a>
        <br />
                <a href="../files/htree/htmlinfo_rb.html">
                htree/htmlinfo.rb
                </a>
        <br />
                <a href="../files/htree/inspect_rb.html">
                htree/inspect.rb
                </a>
        <br />
                <a href="../files/htree/leaf_rb.html">
                htree/leaf.rb
                </a>
        <br />
                <a href="../files/htree/loc_rb.html">
                htree/loc.rb
                </a>
        <br />
                <a href="../files/htree/name_rb.html">
                htree/name.rb
                </a>
        <br />
                <a href="../files/htree/output_rb.html">
                htree/output.rb
                </a>
        <br />
                <a href="../files/htree/parse_rb.html">
                htree/parse.rb
                </a>
        <br />
                <a href="../files/htree/raw_string_rb.html">
                htree/raw_string.rb
                </a>
        <br />
                <a href="../files/htree/rexml_rb.html">
                htree/rexml.rb
                </a>
        <br />
                <a href="../files/htree/scan_rb.html">
                htree/scan.rb
                </a>
        <br />
                <a href="../files/htree/tag_rb.html">
                htree/tag.rb
                </a>
        <br />
                <a href="../files/htree/template_rb.html">
                htree/template.rb
                </a>
        <br />
                <a href="../files/htree/text_rb.html">
                htree/text.rb
                </a>
        <br />
                <a href="../files/htree/traverse_rb.html">
                htree/traverse.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h1>Template Engine</h1>
<p>
The htree template engine converts HTML and some data to HTML or XML.
</p>
<h2>Template Method Summary</h2>
<ul>
<li><a
href="HTree.html#M000008">HTree.expand_template</a>(<em>template_pathname</em>)
-&gt; $stdout

</li>
<li><a
href="HTree.html#M000008">HTree.expand_template</a>(<em>template_pathname</em>,
<em>obj</em>) -&gt; $stdout

</li>
<li><a
href="HTree.html#M000008">HTree.expand_template</a>(<em>template_pathname</em>,
<em>obj</em>, <em>out</em>) -&gt; <em>out</em>

</li>
<li><a
href="HTree.html#M000008">HTree.expand_template</a>(<em>template_pathname</em>,
<em>obj</em>, <em>out</em>, <em>encoding</em>) -&gt; <em>out</em>

</li>
<li><a
href="HTree.html#M000008">HTree.expand_template</a>{<em>template_string</em>}
-&gt; $stdout

</li>
<li><a href="HTree.html#M000008">HTree.expand_template</a>(<em>out</em>)
{<em>template_string</em>} -&gt; <em>out</em>

</li>
<li><a href="HTree.html#M000008">HTree.expand_template</a>(<em>out</em>,
<em>encoding</em>) {<em>template_string</em>} -&gt; <em>out</em>

</li>
<li><a
href="HTree.html#M000009">HTree.compile_template</a>(<em>template_string</em>)
-&gt; Module

</li>
<li><a href="HTree.html">HTree</a>{<em>template_string</em>} -&gt; <a
href="HTree/Doc.html">HTree::Doc</a>

</li>
</ul>
<p>
Note that the following method, <a href="HTree.html">HTree</a>(), is not a
template method.
</p>
<ul>
<li><a href="HTree.html">HTree</a>(<em>html_string</em>) -&gt; <a
href="HTree/Doc.html">HTree::Doc</a>

</li>
</ul>
<h2>Template Directives.</h2>
<p>
A template directive is described as a special HTML attribute which name
begins with underscore.
</p>
<p>
The template directives are listed as follows.
</p>
<ul>
<li>&lt;elem
_attr_<em>name</em>=&quot;<em>expr</em>&quot;&gt;content&lt;/elem&gt;

</li>
<li>&lt;elem _text=&quot;<em>expr</em>&quot;&gt;dummy-content&lt;/elem&gt;

</li>
<li>&lt;elem _text&gt;<em>expr</em>&lt;/elem&gt;

</li>
<li>&lt;elem _tree=&quot;<em>expr</em>&quot;&gt;dummy-content&lt;/elem&gt;

</li>
<li>&lt;elem _tree&gt;<em>expr</em>&lt;/elem&gt;

</li>
<li>&lt;elem _if=&quot;<em>expr</em>&quot;
_else=&quot;<em>mod.name(args)</em>&quot;&gt;then-content&lt;/elem&gt;

</li>
<li>&lt;elem
_iter=&quot;<em>expr.meth(args)//vars</em>&quot;&gt;content&lt;/elem&gt;

</li>
<li>&lt;elem
_iter_content=&quot;<em>expr.meth(args)//vars</em>&quot;&gt;content&lt;/elem&gt;

</li>
<li>&lt;elem
_call=&quot;<em>mod.name(args)</em>&quot;&gt;dummy-content&lt;/elem&gt;

</li>
<li>&lt;elem _template=&quot;<em>name(vars)</em>&quot;&gt;body&lt;/elem&gt;

</li>
</ul>
<h3>Template Semantics</h3>
<ul>
<li>attribute substitution

<ul>
<li>&lt;elem
_attr_<em>name</em>=&quot;<em>expr</em>&quot;&gt;content&lt;/elem&gt;

</li>
</ul>
<p>
_attr_<em>name</em> is used for a dynamic attribute.
</p>
<pre>
     &lt;elem _attr_xxx=&quot;...&quot;/&gt;
  -&gt; &lt;elem xxx=&quot;...&quot;/&gt;
</pre>
<p>
It is expanded to <em>name</em>=&quot;content&quot;. The content is
generated by evaluating <em>expr</em>. Usually you don&#8216;t need to care
escaping: &amp;, &lt;, &gt; and &quot; are automatically escaped. If you
need to output character references, the value of <em>expr</em> should be
an object which have a <tt>rcdata</tt> method such as an <a
href="HTree/Text.html">HTree::Text</a>. If the value has a <tt>rcdata</tt>
method, it is called and the result is used as the content with escaping
&lt;, &gt; and &quot;.
</p>
<p>
_attr_<em>name</em> can be used multiple times in single element.
</p>
</li>
<li>text substitution

<ul>
<li>&lt;elem _text=&quot;<em>expr</em>&quot;&gt;dummy-content&lt;/elem&gt;

</li>
<li>&lt;elem _text&gt;<em>expr</em>&lt;/elem&gt;

</li>
</ul>
<p>
_text substitutes the content of the element by the string evaluated from
<em>expr</em>. <em>expr</em> is described in the attribute value or the
content of the element.
</p>
<p>
If a result of <em>expr</em> have &amp;, &lt; and/or &gt;, they are
automatically escaped. If you need to output character references, the
value of <em>expr</em> should be an object which have a <tt>rcdata</tt>
method such as an <a href="HTree/Text.html">HTree::Text</a>. If the value
has a <tt>rcdata</tt> method, it is called and the result is used as the
content with escaping &lt; and &gt;.
</p>
<p>
If the element is span or div, and there is no other attributes, no tags
are produced.
</p>
<pre>
     &lt;elem _text=&quot;...&quot;&gt;dummy-content&lt;/elem&gt;
  -&gt; &lt;elem&gt;...&lt;/elem&gt;
</pre>
</li>
<li>tree substitution

<ul>
<li>&lt;elem _tree=&quot;<em>expr</em>&quot;&gt;dummy-content&lt;/elem&gt;

</li>
<li>&lt;elem _tree&gt;<em>expr</em>&lt;/elem&gt;

</li>
</ul>
<p>
_tree substitutes the content of the element by the htree object evaluated
from <em>expr</em>. <em>expr</em> is described in the attribute value or
the content of the element.
</p>
<p>
If the element is span or div, and there is no other attributes, no tags
are produced.
</p>
<pre>
     &lt;elem _tree=&quot;...&quot;&gt;dummy-content&lt;/elem&gt;
  -&gt; &lt;elem&gt;...&lt;/elem&gt;
</pre>
</li>
<li>conditional

<ul>
<li>&lt;elem _if=&quot;<em>expr</em>&quot;&gt;then-content&lt;/elem&gt;

</li>
<li>&lt;elem _if=&quot;<em>expr</em>&quot;
_else=&quot;<em>name(args)</em>&quot;&gt;then-content&lt;/elem&gt;

</li>
</ul>
<p>
_if is used for conditional.
</p>
<p>
If <em>expr</em> is evaluated to true, it expands as follows regardless of
existence of _else.
</p>
<pre>
     &lt;elem _if=&quot;&lt;i&gt;expr&lt;/i&gt;&quot;&gt;then-content&lt;/elem&gt;
  -&gt; &lt;elem&gt;then-content&lt;/elem&gt;
</pre>
<p>
If <em>expr</em> is evaluated to false, it expands using _else. If _else is
not given, it expands to empty. If _else is given, it expands as follows.
</p>
<pre>
     &lt;elem _if=&quot;&lt;i&gt;expr&lt;/i&gt;&quot; _else=&quot;&lt;i&gt;name(args)&lt;/i&gt;&quot;&gt;then-content&lt;/elem&gt;
  -&gt; &lt;elem _call=&quot;&lt;i&gt;name(args)&lt;/i&gt;&quot;&gt;then-content&lt;/elem&gt;
  -&gt; see _call for further expansion.
</pre>
<p>
It is expanded to &lt;elem&gt;then-content&lt;/elem&gt; if <em>expr</em> is
evaluated to a true value. Otherwise, it is replaced by other template
specified by _else attribute. If _else attribute is not given, it just
replaced by empty.
</p>
</li>
<li>iteration

<ul>
<li>&lt;elem
_iter=&quot;<em>expr.meth(args)//vars</em>&quot;&gt;content&lt;/elem&gt;

</li>
<li>&lt;elem
_iter_content=&quot;<em>expr.meth(args)//vars</em>&quot;&gt;content&lt;/elem&gt;

</li>
</ul>
<p>
_iter and _iter_content is used for iteration. _iter iterates the element
itself but _iter_content iterates the content.
</p>
<pre>
     &lt;outer _iter=&quot;...&quot;&gt;&lt;inner/&gt;&lt;/outer&gt;
  -&gt; &lt;outer&gt;&lt;inner/&gt;&lt;/outer&gt;&lt;outer&gt;&lt;inner/&gt;&lt;/outer&gt;...

     &lt;outer _iter_content=&quot;...&quot;&gt;&lt;inner/&gt;&lt;/outer&gt;
  -&gt; &lt;outer&gt;&lt;inner/&gt;&lt;inner/&gt;...&lt;/outer&gt;
</pre>
<p>
<em>expr.meth(args)</em> specifies iterator method call. It is actually
called with a block. The block have block parameters <em>vars</em>.
<em>vars</em> must be variables separated by comma.
</p>
</li>
<li>template call

<ul>
<li>&lt;elem
_call=&quot;<em>name(args)</em>&quot;&gt;dummy-content&lt;/elem&gt;

</li>
<li>&lt;elem
_call=&quot;<em>mod.name(args)</em>&quot;&gt;dummy-content&lt;/elem&gt;

</li>
</ul>
<p>
_call is used to expand a template function. The template function is
defined by _template.
</p>
<pre>
     &lt;d _template=&quot;m&quot;&gt;...&lt;/d&gt;
     &lt;c _call=&quot;m&quot;&gt;...&lt;/c&gt;
  -&gt; &lt;d&gt;...&lt;/d&gt;
</pre>
<p>
A local template can be called as follows:
</p>
<pre>
  HTree.expand_template{&lt;&lt;'End'}
  &lt;a _template=ruby_talk(num)
     _attr_href='&quot;http://ruby-talk.org/#{num}&quot;'
     &gt;[ruby-talk:&lt;span _text=num&gt;nnn&lt;/span&gt;]&lt;/a&gt;
  Ruby 1.8.0 is released at &lt;span _call=ruby_talk(77946) /&gt;.
  Ruby 1.8.1 is released at &lt;span _call=ruby_talk(88814) /&gt;.
  End
</pre>
<p>
<em>mod</em> should be the result of <a
href="HTree.html#M000009">HTree.compile_template</a>.
</p>
<pre>
  M = HTree.compile_template(&lt;&lt;'End')
  &lt;a _template=ruby_talk(num)
     _attr_href='&quot;http://ruby-talk.org/#{num}&quot;'
     &gt;[ruby-talk:&lt;span _text=num&gt;nnn&lt;/span&gt;]&lt;/a&gt;
  End
  HTree.expand_template{&lt;&lt;'End'}
  &lt;html&gt;
  Ruby 1.8.0 is released at &lt;span _call=M.ruby_talk(77946) /&gt;.
  Ruby 1.8.1 is released at &lt;span _call=M.ruby_talk(88814) /&gt;.
  &lt;/html&gt;
  End
</pre>
<p>
The module can included. In such case, the template function can be called
without <em>mod.</em> prefix.
</p>
<pre>
  include HTree.compile_template(&lt;&lt;'End')
  &lt;a _template=ruby_talk(num)
     _attr_href='&quot;http://ruby-talk.org/#{num}&quot;'
     &gt;[ruby-talk:&lt;span _text=num&gt;nnn&lt;/span&gt;]&lt;/a&gt;
  End
  HTree.expand_template{&lt;&lt;'End'}
  &lt;html&gt;
  Ruby 1.8.0 is released at &lt;span _call=ruby_talk(77946) /&gt;.
  Ruby 1.8.1 is released at &lt;span _call=ruby_talk(88814) /&gt;.
  &lt;/html&gt;
  End
</pre>
</li>
<li>template definition

<ul>
<li>&lt;elem _template=&quot;<em>name(vars)</em>&quot;&gt;body&lt;/elem&gt;

</li>
</ul>
<p>
_template defines a template function which is usable by _call.
</p>
<p>
When a template is compiled to a module by <a
href="HTree.html#M000009">HTree.compile_template</a>, the module have a
module function for each template function defined by outermost _template
attribute.
</p>
</li>
</ul>
<h3>White Space Handling</h3>
<p>
The htree template engine strips whitespace text nodes in a template except
under HTML pre element.
</p>
<p>
For example the white space text node between two spans in following
template is stripped.
</p>
<pre>
  &lt;span _text=&quot;'a'&quot;/&gt; &lt;span _text=&quot;'b'&quot;/&gt; -&gt; &quot;ab&quot;
</pre>
<p>
Character entity references are not stripped.
</p>
<pre>
  &lt;span _text=&quot;'a'&quot;/&gt;&amp;#32;&lt;span _text=&quot;'b'&quot;/&gt; -&gt; &quot;a&amp;#32;b&quot;
</pre>
<p>
<a href="HTree/Text.html">Text</a> nodes generated by _text is not
stripped.
</p>
<pre>
  &lt;span _text=&quot;'a'&quot;/&gt;&lt;span _text=&quot;' '&quot;&gt; &lt;/span&gt;&lt;span _text=&quot;'b'&quot;/&gt; -&gt; &quot;a b&quot;
</pre>
<h2>HTML and XML</h2>
<p>
The htree template engine outputs HTML or XML.
</p>
<p>
If a template has no XML declaration and the top element is HTML, the
result is HTML. Otherwise the result is XML.
</p>
<p>
They differs as follows.
</p>
<ul>
<li>XML declaration is (re-)generated for XML.

</li>
<li>empty elements ends with a slash for XML.

</li>
<li>script and style element is escaped for XML.

</li>
</ul>
<h2>Design Decision on Design/Logic Separation</h2>
<p>
<a href="HTree.html">HTree</a> template engine doesn&#8216;t force you to
separate design and logic. Any logic (Ruby code) can be embedded in design
(HTML).
</p>
<p>
However the template engine cares the separation by logic refactorings. The
logic is easy to move between a template and an application. For example,
following tangled template
</p>
<pre>
  tmpl.html:
    &lt;html&gt;
      &lt;head&gt;
        &lt;title _text=&quot;very-complex-ruby-code&quot;&gt;dummy&lt;/title&gt;
      &lt;/head&gt;
      ...
    &lt;/html&gt;

  app.rb:
    HTree.expand_template('tmpl.html', obj)
</pre>
<p>
can be refactored as follows.
</p>
<pre>
  tmpl.html:
    &lt;html&gt;
      &lt;head&gt;
        &lt;title _text=&quot;title&quot;&gt;dummy&lt;/title&gt;
      &lt;/head&gt;
      ...
    &lt;/html&gt;

  app.rb:
    def obj.title
      very-complex-ruby-code
    end
    HTree.expand_template('tmpl.html', obj)
</pre>
<p>
In general, any expression in a template can be refactored to an
application by extracting it as a method. In JSP, this is difficult
especially for a code fragment of an iteration.
</p>
<p>
Also <a href="HTree.html">HTree</a> encourages to separate business logic
(Ruby code in an application) and presentation logic (Ruby code in a
template). For example, presentation logic to color table rows stripe can
be embedded in a template. It doesn&#8216;t need to tangle an application.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000003">==</a>&nbsp;&nbsp;
      <a href="#M000009">compile_template</a>&nbsp;&nbsp;
      <a href="#M000004">eql?</a>&nbsp;&nbsp;
      <a href="#M000008">expand_template</a>&nbsp;&nbsp;
      <a href="#M000005">hash</a>&nbsp;&nbsp;
      <a href="#M000006">parse</a>&nbsp;&nbsp;
      <a href="#M000007">parse_xml</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="HTree/Container.html" class="link">HTree::Container</a><br />
Module <a href="HTree/Leaf.html" class="link">HTree::Leaf</a><br />
Module <a href="HTree/Node.html" class="link">HTree::Node</a><br />
Module <a href="HTree/Traverse.html" class="link">HTree::Traverse</a><br />
Class <a href="HTree/BogusETag.html" class="link">HTree::BogusETag</a><br />
Class <a href="HTree/Comment.html" class="link">HTree::Comment</a><br />
Class <a href="HTree/Context.html" class="link">HTree::Context</a><br />
Class <a href="HTree/Doc.html" class="link">HTree::Doc</a><br />
Class <a href="HTree/DocType.html" class="link">HTree::DocType</a><br />
Class <a href="HTree/Elem.html" class="link">HTree::Elem</a><br />
Class <a href="HTree/Encoder.html" class="link">HTree::Encoder</a><br />
Class <a href="HTree/Error.html" class="link">HTree::Error</a><br />
Class <a href="HTree/Location.html" class="link">HTree::Location</a><br />
Class <a href="HTree/Name.html" class="link">HTree::Name</a><br />
Class <a href="HTree/ProcIns.html" class="link">HTree::ProcIns</a><br />
Class <a href="HTree/Text.html" class="link">HTree::Text</a><br />
Class <a href="HTree/XMLDecl.html" class="link">HTree::XMLDecl</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="HTree.src/M000009.html" target="Code" class="method-signature"
            onclick="popupCode('HTree.src/M000009.html');return false;">
          <span class="method-name">HTree.compile_template(template_string) &rarr; module<br />
</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<tt><a
href="HTree.html#M000009">HTree.compile_template</a>(<em>template_string</em>)</tt>
compiles <em>template_string</em> as a template.
</p>
<p>
<a href="HTree.html#M000009">HTree.compile_template</a> returns a module.
The module has module functions for each templates defined in
<em>template_string</em>. The returned module can be used for
<tt>include</tt>.
</p>
<pre>
 M = HTree.compile_template(&lt;&lt;'End')
 &lt;p _template=birthday(subj,t)&gt;
   &lt;span _text=subj /&gt;'s birthday is &lt;span _text=&quot;t.strftime('%B %dth %Y')&quot;/&gt;.
 &lt;/p&gt;
 End
 M.birthday('Ruby', Time.utc(1993, 2, 24)).display_xml
 # &lt;p&gt;Ruby's birthday is February 24th 1993.&lt;/p&gt;
</pre>
<p>
The module function takes arguments specifies by a <tt>_template</tt>
attribute and returns a tree represented as <a
href="HTree/Node.html">HTree::Node</a>.
</p>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="HTree.src/M000008.html" target="Code" class="method-signature"
            onclick="popupCode('HTree.src/M000008.html');return false;">
          <span class="method-name">HTree.expand_template(template_pathname, obj=Object.new, out=$stdout, encoding=internal_encoding) &rarr; out<br />
HTree.expand_template(out=$stdout, encoding=internal_encoding) { template_string } &rarr; out<br />
</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<tt><a href="HTree.html#M000008">HTree.expand_template</a></tt> expands a
template.
</p>
<p>
The arguments should be specified as follows. All argument except
<em>pathname</em> are optional.
</p>
<ul>
<li><a href="HTree.html#M000008">HTree.expand_template</a>(<em>pathname</em>,
<em>obj</em>, <em>out</em>, <em>encoding</em>) -&gt; <em>out</em>

</li>
<li><a href="HTree.html#M000008">HTree.expand_template</a>(<em>out</em>,
<em>encoding</em>) {<em>template_string</em>} -&gt; <em>out</em>

</li>
</ul>
<p>
The template is specified by a file or a string. If a block is not given,
the first argument represent a template pathname. Otherwise, the block is
yielded and its value is interpreted as a template string. So it can be
called as follows in simplest case.
</p>
<ul>
<li><a
href="HTree.html#M000008">HTree.expand_template</a>(<em>template_pathname</em>)

</li>
<li><a
href="HTree.html#M000008">HTree.expand_template</a>{<em>template_string</em>}

</li>
</ul>
<p>
Ruby expressions in the template file specified by
<em>template_pathname</em> are evaluated in the context of the optional
second argument <em>obj</em> as follows. I.e. the pseudo variable self in
the expressions is bound to <em>obj</em>.
</p>
<pre>
  HTree.expand_template(template_pathname, obj)
</pre>
<p>
Ruby expressions in the template_string are evaluated in the context of the
caller of <a href="HTree.html#M000008">HTree.expand_template</a>. (binding
information is specified by the block.) I.e. they can access local
variables etc. We recommend to specify template_string as a literal string
without interpolation because dynamically generated string may break
lexical scope.
</p>
<p>
<a href="HTree.html#M000008">HTree.expand_template</a> has two more
optional arguments: <em>out</em>, <em>encoding</em>.
</p>
<p>
<em>out</em> specifies output target. It should have <tt>&lt;&lt;</tt>
method: IO and String for example. If it is not specified, $stdout is used.
If it has a method <tt>charset=</tt>, it is called to set the minimal
charset of the result before <tt>&lt;&lt;</tt> is called.
</p>
<p>
<em>encoding</em> specifies output character encoding. If it is not
specified, internal encoding is used.
</p>
<p>
<a href="HTree.html#M000008">HTree.expand_template</a> returns <em>out</em>
or $stdout if <em>out</em> is not specified.
</p>
        </div>
      </div>

      <div id="method-M000006" class="method-detail">
        <a name="M000006"></a>

        <div class="method-heading">
          <a href="HTree.src/M000006.html" target="Code" class="method-signature"
            onclick="popupCode('HTree.src/M000006.html');return false;">
          <span class="method-name">parse</span><span class="method-args">(input)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="HTree.html#M000006">HTree.parse</a> parses <em>input</em> and
return a document tree. represented by <a
href="HTree/Doc.html">HTree::Doc</a>.
</p>
<p>
<em>input</em> should be a String or an object which respond to read or
open method. For example, IO, StringIO, Pathname, URI::HTTP and URI::FTP
are acceptable. Note that the URIs need open-uri.
</p>
<p>
<a href="HTree.html#M000006">HTree.parse</a> guesses <em>input</em> is HTML
or not and XML or not.
</p>
<p>
If it is guessed as HTML, the default namespace in the result is set to <a
href="http://www.w3.org/1999/xhtml">www.w3.org/1999/xhtml</a> regardless of
<em>input</em> has XML namespace declaration or not nor even it is pre-XML
HTML.
</p>
<p>
If it is guessed as HTML and not XML, all element and attribute names are
downcaseed.
</p>
<p>
If opened file or read content has charset method, <a
href="HTree.html#M000006">HTree.parse</a> decode it according to $KCODE
before parsing. Otherwise <a href="HTree.html#M000006">HTree.parse</a>
assumes the character encoding of the content is compatible to $KCODE. Note
that the charset method is provided by URI::HTTP with open-uri.
</p>
        </div>
      </div>

      <div id="method-M000007" class="method-detail">
        <a name="M000007"></a>

        <div class="method-heading">
          <a href="HTree.src/M000007.html" target="Code" class="method-signature"
            onclick="popupCode('HTree.src/M000007.html');return false;">
          <span class="method-name">parse_xml</span><span class="method-args">(input)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="HTree.html#M000007">HTree.parse_xml</a> parses <em>input</em> as
XML and return a document tree represented by <a
href="HTree/Doc.html">HTree::Doc</a>.
</p>
<p>
It behaves almost same as <a href="HTree.html#M000006">HTree.parse</a> but
it assumes <em>input</em> is XML even if no XML declaration. The assumption
causes following differences.
</p>
<ul>
<li>doesn&#8216;t downcase element name.

</li>
<li>The content of &lt;script&gt; and &lt;style&gt; element is PCDATA, not
CDATA.

</li>
</ul>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="HTree.src/M000003.html" target="Code" class="method-signature"
            onclick="popupCode('HTree.src/M000003.html');return false;">
          <span class="method-name">==</span><span class="method-args">(other)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
compare tree structures.
</p>
        </div>
      </div>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <span class="method-name">eql?</span><span class="method-args">(other)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for #==
</p>
        </div>
      </div>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="HTree.src/M000005.html" target="Code" class="method-signature"
            onclick="popupCode('HTree.src/M000005.html');return false;">
          <span class="method-name">hash</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="HTree.html#M000005">hash</a> value for the tree structure.
</p>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>