tenjin 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +163 -0
- data/MIT-LICENSE +16 -17
- data/README.txt +5 -5
- data/benchmark/Makefile +9 -0
- data/benchmark/bench.rb +3 -2
- data/bin/rbtenjin +6 -3
- data/doc/docstyle.css +25 -4
- data/doc/users-guide.html +2088 -1563
- data/lib/tenjin.rb +784 -158
- data/public_html/_layout.rbhtml +33 -0
- data/public_html/css/style.css +77 -0
- data/public_html/env.rbhtml +15 -0
- data/public_html/favicon.ico +0 -0
- data/public_html/hello.rbhtml +14 -0
- data/public_html/index.rbhtml +39 -0
- data/public_html/rbtenjin.cgi +188 -0
- data/tenjin.gemspec +9 -6
- data/test/data/examples/preprocessing/main.rb +1 -1
- data/test/data/examples/preprocessing/select.rbhtml +1 -1
- data/test/data/faq/{ex11-bench.rb → ex10-bench.rb} +3 -3
- data/test/data/faq/ex10-content.rbhtml +8 -11
- data/test/data/faq/{ex11-layout1.rbhtml → ex10-layout1.rbhtml} +0 -0
- data/test/data/faq/{ex11-layout2.rbhtml → ex10-layout2.rbhtml} +0 -0
- data/test/data/faq/{ex11.rb → ex10.rb} +1 -1
- data/test/data/faq/{ex11.rbhtml → ex10.rbhtml} +0 -0
- data/test/data/faq/{ex11.source → ex10.source} +2 -2
- data/test/data/faq/{ex11_arraybuffer.result → ex10_arraybuffer.result} +1 -1
- data/test/data/faq/{ex5.rbhtml → ex2.rbhtml} +0 -0
- data/test/data/faq/{ex5_template_args.source → ex2_template_args.source} +1 -1
- data/test/data/faq/{ex7-expr-pattern.rb → ex4-expr-pattern.rb} +1 -1
- data/test/data/faq/{ex7-expr-pattern.rbhtml → ex4-expr-pattern.rbhtml} +0 -0
- data/test/data/faq/{ex7_expr_pattern.result → ex4_expr_pattern.result} +1 -1
- data/test/data/faq/{ex6-content.rhtml → ex5-content.rhtml} +0 -0
- data/test/data/faq/{ex6-layout.rhtml → ex5-layout.rhtml} +0 -0
- data/test/data/faq/{ex6.rb → ex5.rb} +2 -2
- data/test/data/faq/{ex6_eruby.result → ex5_eruby.result} +1 -1
- data/test/data/faq/{ex2-content.rbhtml → ex6-content.rbhtml} +0 -0
- data/test/data/faq/{ex2-layout.rbhtml → ex6-layout.rbhtml} +0 -0
- data/test/data/faq/{ex2_removenl.result → ex6_removenl.result} +1 -1
- data/test/data/faq/ex7-m18n.rb +48 -0
- data/test/data/faq/{ex8-m18n.rbhtml → ex7-m18n.rbhtml} +0 -0
- data/test/data/faq/{ex8_m18n.result → ex7_m18n.result} +1 -1
- data/test/data/faq/ex8-baselayout.rbhtml +8 -0
- data/test/data/faq/ex8-content.rbhtml +6 -0
- data/test/data/faq/{ex9-mylayout.rbhtml → ex8-mylayout.rbhtml} +0 -0
- data/test/data/faq/{ex9_changelayout.result → ex8_changelayout.result} +1 -1
- data/test/data/faq/ex9-baselayout.rbhtml +24 -5
- data/test/data/faq/ex9-content.rbhtml +12 -6
- data/test/data/faq/{ex10-customlayout.rbhtml → ex9-customlayout.rbhtml} +1 -1
- data/test/data/faq/{ex10_inherit.result → ex9_inherit.result} +1 -1
- data/test/data/faq/helpers1.rb +17 -0
- data/test/data/faq/helpers1.rbhtml +4 -0
- data/test/data/faq/helpers1.result +11 -0
- data/test/data/faq/helpers2.rb +21 -0
- data/test/data/faq/helpers2.rbhtml +4 -0
- data/test/data/faq/helpers2.result +11 -0
- data/test/data/faq/weekday1.rb +6 -0
- data/test/data/faq/weekday1.rbhtml +9 -0
- data/test/data/faq/weekday1.result +23 -0
- data/test/data/faq/weekday2.rb +8 -0
- data/test/data/faq/weekday2.rbhtml +10 -0
- data/test/data/faq/weekday2.result +24 -0
- data/test/data/faq/weekday3.rb +22 -0
- data/test/data/faq/weekday3.rbhtml +3 -0
- data/test/data/faq/weekday3.result +28 -0
- data/test/data/users_guide/test_010/main.rb +14 -0
- data/test/data/users_guide/test_010/result.output +13 -0
- data/test/data/users_guide/test_010/views/page.rbhtml +11 -0
- data/test/data/users_guide/test_011/main.rb +14 -0
- data/test/data/users_guide/test_011/result.output +2 -0
- data/test/data/users_guide/test_011/views/page.rbhtml +11 -0
- data/test/data/users_guide/test_020/main.rb +14 -0
- data/test/data/users_guide/test_020/result.output +13 -0
- data/test/data/users_guide/test_020/views/page.rbhtml +11 -0
- data/test/data/users_guide/test_021/main.rb +12 -0
- data/test/data/users_guide/test_021/result.output +12 -0
- data/test/data/users_guide/test_021/views/page.rbhtml +11 -0
- data/test/data/users_guide/test_030/main.rb +14 -0
- data/test/data/users_guide/test_030/result.output +23 -0
- data/test/data/users_guide/test_030/views/_layout.rbhtml +10 -0
- data/test/data/users_guide/test_030/views/page.rbhtml +11 -0
- data/test/data/users_guide/test_040/main.rb +14 -0
- data/test/data/users_guide/test_040/result.output +23 -0
- data/test/data/users_guide/test_040/views/_layout.rbhtml +10 -0
- data/test/data/users_guide/test_040/views/page.rbhtml +12 -0
- data/test/data/users_guide/test_050/main.rb +14 -0
- data/test/data/users_guide/test_050/result.output +14 -0
- data/test/data/users_guide/test_050/views/_layout.rbhtml +10 -0
- data/test/data/users_guide/test_050/views/page.rbhtml +13 -0
- data/test/data/users_guide/test_051/main.rb +14 -0
- data/test/data/users_guide/test_051/result.output +12 -0
- data/test/data/users_guide/test_051/views/_layout.rbhtml +11 -0
- data/test/data/users_guide/test_051/views/page.rbhtml +13 -0
- data/test/data/users_guide/test_060/main.rb +14 -0
- data/test/data/users_guide/test_060/result.output +29 -0
- data/test/data/users_guide/test_060/views/_footer.rbhtml +3 -0
- data/test/data/users_guide/test_060/views/_header.rbhtml +3 -0
- data/test/data/users_guide/test_060/views/_layout.rbhtml +13 -0
- data/test/data/users_guide/test_060/views/page.rbhtml +13 -0
- data/test/data/users_guide/test_070/main.rb +14 -0
- data/test/data/users_guide/test_070/result.output +29 -0
- data/test/data/users_guide/test_070/views/_footer.rbhtml +3 -0
- data/test/data/users_guide/test_070/views/_header.rbhtml +3 -0
- data/test/data/users_guide/test_070/views/_layout.rbhtml +13 -0
- data/test/data/users_guide/test_070/views/page.rbhtml +13 -0
- data/test/data/users_guide/test_capturing/main.rb +24 -0
- data/test/data/users_guide/test_capturing/result.output +28 -0
- data/test/data/users_guide/test_capturing/views/_layout.rbhtml +21 -0
- data/test/data/users_guide/test_capturing/views/blog-post.rbhtml +13 -0
- data/test/data/users_guide/test_context/context.rb +5 -0
- data/test/data/users_guide/test_context/context.yaml +4 -0
- data/test/data/users_guide/test_context/example.rbhtml +5 -0
- data/test/data/users_guide/test_context/result1.output +6 -0
- data/test/data/users_guide/test_context/result2.output +6 -0
- data/test/data/users_guide/test_context/result3.output +6 -0
- data/test/data/users_guide/test_context/result4.output +6 -0
- data/test/data/users_guide/test_convert/example.rbhtml +5 -0
- data/test/data/users_guide/test_convert/result1.output +7 -0
- data/test/data/users_guide/test_convert/result2.output +6 -0
- data/test/data/users_guide/test_escape/main.rb +4 -0
- data/test/data/users_guide/test_escape/result.output +5 -0
- data/test/data/users_guide/test_escape/views/page.rbhtml +4 -0
- data/test/data/users_guide/test_execute/example.rbhtml +6 -0
- data/test/data/users_guide/test_execute/result.output +6 -0
- data/test/data/users_guide/test_fragmentcache/cache.d/items/1 +5 -0
- data/test/data/users_guide/test_fragmentcache/main.rb +21 -0
- data/test/data/users_guide/test_fragmentcache/result.output +8 -0
- data/test/data/users_guide/test_fragmentcache/result2.output +6 -0
- data/test/data/users_guide/test_fragmentcache/views/items.rbhtml +10 -0
- data/test/data/users_guide/test_logging/ex-logger.rb +11 -0
- data/test/data/users_guide/test_logging/example.rbhtml +0 -0
- data/test/data/users_guide/test_logging/result1.output +3 -0
- data/test/data/users_guide/test_logging/result2.output +2 -0
- data/test/data/users_guide/test_m17n/m17n.rb +44 -0
- data/test/data/users_guide/test_m17n/m17n.rbhtml +5 -0
- data/test/data/users_guide/test_m17n/result.output +9 -0
- data/test/data/users_guide/test_m17n/result_en.output +4 -0
- data/test/data/users_guide/test_m17n/result_fr.output +4 -0
- data/test/data/users_guide/test_nested/main.rb +8 -0
- data/test/data/users_guide/test_nested/result.output +15 -0
- data/test/data/users_guide/test_nested/views/_blog_layout.rbhtml +5 -0
- data/test/data/users_guide/{layout8_html.rbhtml → test_nested/views/_site_layout.rbhtml} +0 -0
- data/test/data/users_guide/test_nested/views/blog_post.rbhtml +4 -0
- data/test/data/users_guide/test_preprocessing/pp-example1.rb +14 -0
- data/test/data/users_guide/test_preprocessing/result1a.output +11 -0
- data/test/data/users_guide/test_preprocessing/result1b.output +5 -0
- data/test/data/users_guide/test_preprocessing/result1c.output +6 -0
- data/test/data/users_guide/test_preprocessing/result2a.output +10 -0
- data/test/data/users_guide/test_preprocessing/result2b.output +10 -0
- data/test/data/users_guide/test_preprocessing/result3a.output +2 -0
- data/test/data/users_guide/test_preprocessing/result3b.output +2 -0
- data/test/data/users_guide/test_preprocessing/views/pp-example1.rbhtml +4 -0
- data/test/data/users_guide/{example12.rbhtml → test_preprocessing/views/pp-example2.rbhtml} +4 -4
- data/test/data/users_guide/test_preprocessing/views/pp-example3.rbhtml +7 -0
- data/test/data/users_guide/test_retrieve/example.rbhtml +10 -0
- data/test/data/users_guide/test_retrieve/result1.output +11 -0
- data/test/data/users_guide/test_retrieve/result2.output +11 -0
- data/test/data/users_guide/test_retrieve/result3.output +11 -0
- data/test/data/users_guide/test_retrieve/result4.output +8 -0
- data/test/data/users_guide/test_retrieve/result5.output +5 -0
- data/test/data/users_guide/test_safe/result.output +6 -0
- data/test/data/users_guide/test_safe/safe-test.rb +21 -0
- data/test/data/users_guide/test_safehelper/main.rb +16 -0
- data/test/data/users_guide/test_safehelper/result.output +8 -0
- data/test/data/users_guide/{example3.rbhtml → test_syntax_check/example.rbhtml} +0 -0
- data/test/data/users_guide/test_syntax_check/result.output +2 -0
- data/test/data/users_guide/test_trace/layout.rbhtml +7 -0
- data/test/data/users_guide/test_trace/main.rbhtml +5 -0
- data/test/data/users_guide/test_trace/result.output +16 -0
- data/test/data/users_guide/test_trace/trace-example.rb +4 -0
- data/test/oktest.rb +755 -0
- data/test/test_all.rb +24 -14
- data/test/test_engine.rb +628 -63
- data/test/test_engine.yaml +40 -3
- data/test/test_examples.rb +14 -12
- data/test/test_faq.rb +17 -12
- data/test/test_htmlhelper.rb +104 -33
- data/test/test_main.rb +32 -21
- data/test/test_main.yaml +2 -2
- data/test/test_safe.rb +206 -0
- data/test/test_store.rb +220 -0
- data/test/test_tcache.rb +94 -0
- data/test/test_template.rb +65 -23
- data/test/test_template.yaml +7 -7
- data/test/test_users_guide.rb +75 -29
- data/test/testcase-helper.rb +20 -18
- data/test/testunit-assertions.rb +71 -0
- metadata +185 -159
- data/doc-api/classes/Tenjin.html +0 -141
- data/doc-api/classes/Tenjin/ArrayBufferTemplate.html +0 -270
- data/doc-api/classes/Tenjin/BaseContext.html +0 -329
- data/doc-api/classes/Tenjin/Context.html +0 -126
- data/doc-api/classes/Tenjin/ContextHelper.html +0 -461
- data/doc-api/classes/Tenjin/Engine.html +0 -616
- data/doc-api/classes/Tenjin/ErubisTemplate.html +0 -166
- data/doc-api/classes/Tenjin/HtmlHelper.html +0 -359
- data/doc-api/classes/Tenjin/Preprocessor.html +0 -242
- data/doc-api/classes/Tenjin/Template.html +0 -916
- data/doc-api/created.rid +0 -1
- data/doc-api/files/README_txt.html +0 -188
- data/doc-api/files/lib/tenjin_rb.html +0 -136
- data/doc-api/fr_class_index.html +0 -36
- data/doc-api/fr_file_index.html +0 -28
- data/doc-api/fr_method_index.html +0 -91
- data/doc-api/index.html +0 -24
- data/doc-api/rdoc-style.css +0 -208
- data/doc/examples.html +0 -312
- data/doc/faq.html +0 -909
- data/examples/preprocessing/select.rbhtml.cache +0 -17
- data/test/Rookbook.yaml +0 -14
- data/test/assert-text-equal.rb +0 -45
- data/test/data/faq/ex10-baselayout.rbhtml +0 -27
- data/test/data/faq/ex11-content.rbhtml +0 -9
- data/test/data/faq/ex8-m18n.rb +0 -77
- data/test/data/users_guide/content6.rbhtml +0 -3
- data/test/data/users_guide/content7.rbhtml +0 -5
- data/test/data/users_guide/content8.rbhtml +0 -2
- data/test/data/users_guide/contextdata.rb +0 -7
- data/test/data/users_guide/datafile.rb +0 -5
- data/test/data/users_guide/datafile.yaml +0 -10
- data/test/data/users_guide/ex.rbhtml +0 -6
- data/test/data/users_guide/ex.result +0 -7
- data/test/data/users_guide/ex.script +0 -5
- data/test/data/users_guide/ex_script.result +0 -7
- data/test/data/users_guide/ex_source.result +0 -8
- data/test/data/users_guide/example1.rbhtml +0 -12
- data/test/data/users_guide/example1.result +0 -17
- data/test/data/users_guide/example10.rbhtml +0 -4
- data/test/data/users_guide/example10_template_args.result +0 -6
- data/test/data/users_guide/example11.rbhtml +0 -5
- data/test/data/users_guide/example11_template_args_result +0 -2
- data/test/data/users_guide/example12_preprocessed.result +0 -10
- data/test/data/users_guide/example12_preprocessed_source.result +0 -10
- data/test/data/users_guide/example13.rbhtml +0 -6
- data/test/data/users_guide/example13_preprocessed.result +0 -2
- data/test/data/users_guide/example13_preprocessed_source.result +0 -2
- data/test/data/users_guide/example14.rb +0 -32
- data/test/data/users_guide/example14.rbhtml +0 -6
- data/test/data/users_guide/example14_tmplclass.result +0 -15
- data/test/data/users_guide/example15.rb +0 -10
- data/test/data/users_guide/example15_escapefunc.result +0 -14
- data/test/data/users_guide/example16.rbhtml +0 -4
- data/test/data/users_guide/example16a.rb +0 -10
- data/test/data/users_guide/example16a.result +0 -4
- data/test/data/users_guide/example16b.rb +0 -13
- data/test/data/users_guide/example16b.result +0 -4
- data/test/data/users_guide/example16c.rb +0 -12
- data/test/data/users_guide/example16c.result +0 -4
- data/test/data/users_guide/example16d.rb +0 -27
- data/test/data/users_guide/example16d.result +0 -4
- data/test/data/users_guide/example1_S.result +0 -14
- data/test/data/users_guide/example1_SXNC.result +0 -10
- data/test/data/users_guide/example1_source.result +0 -14
- data/test/data/users_guide/example2.rbhtml +0 -3
- data/test/data/users_guide/example2_sb.result2 +0 -9
- data/test/data/users_guide/example3_syntaxcheck.result +0 -2
- data/test/data/users_guide/example4.rbhtml +0 -13
- data/test/data/users_guide/example4_datafile_rb.result +0 -13
- data/test/data/users_guide/example4_yaml.result +0 -13
- data/test/data/users_guide/example5.rbhtml +0 -9
- data/test/data/users_guide/example5_datastr_rb.result +0 -9
- data/test/data/users_guide/example5_datastr_yaml.result +0 -9
- data/test/data/users_guide/example6.rbhtml +0 -19
- data/test/data/users_guide/example6_layout.result +0 -29
- data/test/data/users_guide/example6_nested.result +0 -28
- data/test/data/users_guide/example7_layout2.result +0 -13
- data/test/data/users_guide/example8_layout3.result +0 -8
- data/test/data/users_guide/example9.rbhtml +0 -18
- data/test/data/users_guide/example9_capture.result +0 -26
- data/test/data/users_guide/footer.html +0 -5
- data/test/data/users_guide/footer.rbhtml +0 -4
- data/test/data/users_guide/layout6.rbhtml +0 -17
- data/test/data/users_guide/layout7.rbhtml +0 -9
- data/test/data/users_guide/layout8_xhtml.rbhtml +0 -6
- data/test/data/users_guide/layout9.rbhtml +0 -25
- data/test/data/users_guide/sidemenu.rbhtml +0 -5
- data/test/data/users_guide/user_app.cgi +0 -39
- data/test/data/users_guide/user_app.result +0 -30
- data/test/data/users_guide/user_create.rbhtml +0 -6
- data/test/data/users_guide/user_edit.rbhtml +0 -7
- data/test/data/users_guide/user_form.rbhtml +0 -10
- data/test/data/users_guide/user_layout.rbhtml +0 -16
@@ -1,12 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<?rb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<ul>
|
8
|
-
<?rb for item in @items ?>
|
9
|
-
<li>${item}</li>
|
1
|
+
<table>
|
2
|
+
<tbody>
|
3
|
+
<?rb for i in (1..100) ?>
|
4
|
+
<tr id="row#{i}">
|
5
|
+
<td>#{i}</td>
|
6
|
+
</tr>
|
10
7
|
<?rb end ?>
|
11
|
-
</
|
12
|
-
|
8
|
+
</tbody>
|
9
|
+
</table>
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
$ rbtenjin -s --templateclass=Tenjin::ArrayBufferTemplate
|
1
|
+
$ rbtenjin -s --templateclass=Tenjin::ArrayBufferTemplate ex10.rbhtml
|
2
2
|
_buf = []; _buf.push('<table>
|
3
3
|
'); @items.each_with_index do |item, i|
|
4
4
|
_buf.push(' <tr>
|
@@ -8,4 +8,4 @@ _buf = []; _buf.push('<table>
|
|
8
8
|
'); end
|
9
9
|
_buf.push('</table>
|
10
10
|
');
|
11
|
-
_buf.
|
11
|
+
_buf.join
|
File without changes
|
@@ -29,6 +29,6 @@ end
|
|
29
29
|
if __FILE__ == $0
|
30
30
|
context = { :value => 'AAA&BBB' }
|
31
31
|
engine = Tenjin::Engine.new(:templateclass=>MyTemplate)
|
32
|
-
output = engine.render('
|
32
|
+
output = engine.render('ex4-expr-pattern.rbhtml', context)
|
33
33
|
puts output
|
34
34
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -4,7 +4,7 @@ require 'tenjin'
|
|
4
4
|
include Erubis::XmlHelper
|
5
5
|
|
6
6
|
context = { :items => ['<AAA>', 'B&B', '"CCC"'] }
|
7
|
-
engine = Tenjin::Engine.new(:layout=>'
|
7
|
+
engine = Tenjin::Engine.new(:layout=>'ex5-layout.rhtml',
|
8
8
|
:templateclass=>Tenjin::ErubisTemplate)
|
9
|
-
output = engine.render('
|
9
|
+
output = engine.render('ex5-content.rhtml', context)
|
10
10
|
print output
|
File without changes
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'tenjin'
|
2
|
+
|
3
|
+
##
|
4
|
+
## message catalog to translate message
|
5
|
+
##
|
6
|
+
MESSAGE_CATALOG = {
|
7
|
+
'en' => { 'Hello' => 'Hello',
|
8
|
+
'Good bye'=> 'Good bye', },
|
9
|
+
'fr' => { 'Hello' => 'Bonjour',
|
10
|
+
'Good bye'=> 'Au revoir', },
|
11
|
+
}
|
12
|
+
|
13
|
+
##
|
14
|
+
## add translation method to ContextHelper module
|
15
|
+
## (Tenjin::Context class includes this module)
|
16
|
+
##
|
17
|
+
module Tenjin::ContextHelper
|
18
|
+
def _(message_key)
|
19
|
+
message_dict = MESSAGE_CATALOG[@_lang]
|
20
|
+
return message_key unless message_dict
|
21
|
+
return message_dict[message_key] || message_key
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
## test program
|
27
|
+
##
|
28
|
+
if $0 == __FILE__
|
29
|
+
|
30
|
+
template_name = 'ex7-m18n.rbhtml'
|
31
|
+
context = { :username => 'World' }
|
32
|
+
|
33
|
+
## engine for english
|
34
|
+
engine = Tenjin::Engine.new(:preprocess=>true, :lang=>'en')
|
35
|
+
ctx = context.merge({:_lang=>'en'})
|
36
|
+
output = engine.render(template_name, ctx) # same template
|
37
|
+
puts "--- lang: %s ---" % engine.lang
|
38
|
+
puts output
|
39
|
+
puts
|
40
|
+
|
41
|
+
## engine for French
|
42
|
+
engine = Tenjin::Engine.new(:preprocess=>true, :lang=>'fr')
|
43
|
+
ctx = context.merge({:_lang=>'fr'})
|
44
|
+
output = engine.render(template_name, ctx) # same template
|
45
|
+
puts "--- lang: %s ---" % engine.lang
|
46
|
+
puts output
|
47
|
+
|
48
|
+
end
|
File without changes
|
File without changes
|
@@ -1,8 +1,27 @@
|
|
1
1
|
<html>
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
<body>
|
3
|
+
|
4
|
+
<?rb ## if variable '@header_part' is defined then print it, ?>
|
5
|
+
<?rb ## else print default header part. ?>
|
6
|
+
<div id="header">
|
7
|
+
<?rb unless captured_as(:header_part) ?>
|
8
|
+
<img src="img/logo.png" alt="logo" ?>
|
5
9
|
<?rb end ?>
|
6
|
-
|
7
|
-
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<?rb ## main content part ?>
|
13
|
+
<div id="content">
|
14
|
+
<?rb _buf << @content_part ?>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<?rb ## if variable '@footer_part' is defined then print it, ?>
|
18
|
+
<?rb ## else print default footer part. ?>
|
19
|
+
<div id="footer">
|
20
|
+
<?rb unless captured_as(:footer_part) ?>
|
21
|
+
<hr />
|
22
|
+
<em>webmaster@example.com</em>
|
23
|
+
<?rb end ?>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
</body>
|
8
27
|
</html>
|
@@ -1,6 +1,12 @@
|
|
1
|
-
<?rb @
|
2
|
-
<?rb ##
|
3
|
-
<?rb @_layout = 'ex9-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
<?rb ## '@_layout' variable is equivarent to '{% extends "foobar.html" %}' ?>
|
2
|
+
<?rb ## in Django template engine. ?>
|
3
|
+
<?rb @_layout = 'ex9-customlayout.rbhtml' ?>
|
4
|
+
|
5
|
+
<?rb ## main content part ?>
|
6
|
+
<?rb start_capture(:content_part) ?>
|
7
|
+
<ul>
|
8
|
+
<?rb for item in @items ?>
|
9
|
+
<li>${item}</li>
|
10
|
+
<?rb end ?>
|
11
|
+
</ul>
|
12
|
+
<?rb stop_capture() ?>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<?rb ## '@_layout' variable is equivarent to '{% extends "foobar.html" %}' ?>
|
2
2
|
<?rb ## in Django template engine. ?>
|
3
|
-
<?rb @_layout = '
|
3
|
+
<?rb @_layout = 'ex9-baselayout.rbhtml' ?>
|
4
4
|
|
5
5
|
<?rb ## you can override header or footer by capturing. ?>
|
6
6
|
<?rb start_capture(:footer_part) ?>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
## define helper method
|
2
|
+
def link_to(label, opts={})
|
3
|
+
href = opts[:href]
|
4
|
+
action = opts[:action]
|
5
|
+
if !href && action
|
6
|
+
href = "/#{controller_name()}/#{action}"
|
7
|
+
end
|
8
|
+
return "<a href=\"#{href}\">#{label}</a>"
|
9
|
+
end
|
10
|
+
##
|
11
|
+
def controller_name; 'user'; end
|
12
|
+
require 'tenjin'
|
13
|
+
engine = Tenjin::Engine.new(:preprocess=>true)
|
14
|
+
puts '***** preprocessed *****'
|
15
|
+
puts engine.get_template('helpers1.rbhtml').script
|
16
|
+
puts '***** output *****'
|
17
|
+
puts engine.render('helpers1.rbhtml')
|
@@ -0,0 +1,21 @@
|
|
1
|
+
## define helper method
|
2
|
+
def link_to(label, opts={})
|
3
|
+
href = opts[:href]
|
4
|
+
action = opts[:action]
|
5
|
+
id = opts[:id]
|
6
|
+
if !href && action
|
7
|
+
href = id ? "/#{@controller_name}/#{action}/#{id}" \
|
8
|
+
: "/#{@controller_name}/#{action}"
|
9
|
+
end
|
10
|
+
return "<a href=\"#{href}\">#{label}</a>"
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
require 'tenjin'
|
15
|
+
context = { :controller_name => 'user',
|
16
|
+
:user => {'id' => 123, 'name' => 'Tom&Jerry'} }
|
17
|
+
engine = Tenjin::Engine.new(:preprocess=>true)
|
18
|
+
puts '***** preprocessed *****'
|
19
|
+
puts engine.get_template('helpers2.rbhtml', context).script
|
20
|
+
puts '***** output *****'
|
21
|
+
puts engine.render('helpers2.rbhtml', context)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$ ruby helpers2.rb
|
2
|
+
***** preprocessed *****
|
3
|
+
_buf << %Q`<p>
|
4
|
+
#{link_to(escape(@user['name']), :action=>'show', :id=>@user['id'])}
|
5
|
+
<a href="/user/show/#{@user['id']}">#{escape((@user['name']).to_s)}</a>
|
6
|
+
</p>\n`
|
7
|
+
***** output *****
|
8
|
+
<p>
|
9
|
+
<a href="/user/show/123">Tom&Jerry</a>
|
10
|
+
<a href="/user/show/123">Tom&Jerry</a>
|
11
|
+
</p>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$ ruby weekday1.rb
|
2
|
+
***** preprocessed *****
|
3
|
+
_buf << %Q`<select name="weekday">
|
4
|
+
<option>-</option>
|
5
|
+
<option value="1">Sun</option>
|
6
|
+
<option value="2">Mon</option>
|
7
|
+
<option value="3">Tue</option>
|
8
|
+
<option value="4">Wed</option>
|
9
|
+
<option value="5">Thu</option>
|
10
|
+
<option value="6">Fri</option>
|
11
|
+
<option value="7">Sat</option>
|
12
|
+
</select>\n`
|
13
|
+
***** output *****
|
14
|
+
<select name="weekday">
|
15
|
+
<option>-</option>
|
16
|
+
<option value="1">Sun</option>
|
17
|
+
<option value="2">Mon</option>
|
18
|
+
<option value="3">Tue</option>
|
19
|
+
<option value="4">Wed</option>
|
20
|
+
<option value="5">Thu</option>
|
21
|
+
<option value="6">Fri</option>
|
22
|
+
<option value="7">Sat</option>
|
23
|
+
</select>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
## render with preprocessing
|
2
|
+
require 'tenjin'
|
3
|
+
engine = Tenjin::Engine.new(:preprocess=>true)
|
4
|
+
context = { :params => { 'weekday'=>3, 'day'=>19 } }
|
5
|
+
puts '***** preprocessed *****'
|
6
|
+
puts engine.get_template('weekday2.rbhtml').script
|
7
|
+
puts '***** output *****'
|
8
|
+
puts engine.render('weekday2.rbhtml', context)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<?RB weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] ?>
|
2
|
+
<select name="weekday">
|
3
|
+
<?rb selected = { @params['weekday'].to_s => ' selected="selected"' } ?>
|
4
|
+
<option>-</option>
|
5
|
+
<?RB i = 0 ?>
|
6
|
+
<?RB for wday in weekdays ?>
|
7
|
+
<?RB i += 1?>
|
8
|
+
<option value="#{{i}}"#{selected['#{{i}}']}>#{{wday}}</option>
|
9
|
+
<?RB end ?>
|
10
|
+
</select>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$ ruby weekday2.rb
|
2
|
+
***** preprocessed *****
|
3
|
+
_buf << %Q`<select name="weekday">\n`
|
4
|
+
selected = { @params['weekday'].to_s => ' selected="selected"' }
|
5
|
+
_buf << %Q` <option>-</option>
|
6
|
+
<option value="1"#{selected['1']}>Sun</option>
|
7
|
+
<option value="2"#{selected['2']}>Mon</option>
|
8
|
+
<option value="3"#{selected['3']}>Tue</option>
|
9
|
+
<option value="4"#{selected['4']}>Wed</option>
|
10
|
+
<option value="5"#{selected['5']}>Thu</option>
|
11
|
+
<option value="6"#{selected['6']}>Fri</option>
|
12
|
+
<option value="7"#{selected['7']}>Sat</option>
|
13
|
+
</select>\n`
|
14
|
+
***** output *****
|
15
|
+
<select name="weekday">
|
16
|
+
<option>-</option>
|
17
|
+
<option value="1">Sun</option>
|
18
|
+
<option value="2">Mon</option>
|
19
|
+
<option value="3" selected="selected">Tue</option>
|
20
|
+
<option value="4">Wed</option>
|
21
|
+
<option value="5">Thu</option>
|
22
|
+
<option value="6">Fri</option>
|
23
|
+
<option value="7">Sat</option>
|
24
|
+
</select>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
## helper function
|
2
|
+
WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
3
|
+
def pp_select_weekday_tag(expr_str, name='weekday')
|
4
|
+
buf = ""
|
5
|
+
buf << "<?rb _selected = { (#{expr_str}).to_s => ' selected=\"selected\"' } ?>\n"
|
6
|
+
buf << "<select name=\"#{name}\">\n"
|
7
|
+
buf << " <option>-</option>\n"
|
8
|
+
WEEKDAYS.each_with_index do |wday, i|
|
9
|
+
buf << " <option value=\"#{i+1}\"\#{_selected['#{i+1}']}>#{wday}</option>\n"
|
10
|
+
end
|
11
|
+
buf << "</select>"
|
12
|
+
return buf
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
require 'tenjin'
|
17
|
+
engine = Tenjin::Engine.new(:preprocess=>true)
|
18
|
+
context = { :params => { 'weekday'=>3, 'day'=>19 } }
|
19
|
+
puts '***** preprocessed *****'
|
20
|
+
puts engine.get_template('weekday3.rbhtml').script
|
21
|
+
puts '***** output *****'
|
22
|
+
puts engine.render('weekday3.rbhtml', context)
|