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
@@ -0,0 +1,33 @@
|
|
1
|
+
<?rb # -*- coding: utf-8 -*- ?>
|
2
|
+
<!DOCTYPE>
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
6
|
+
<meta http-equiv="Content-Style-Type" content="text/css">
|
7
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript">
|
8
|
+
<title>${@page_title}</title>
|
9
|
+
<link rel="stylesheet" type="text/css" href="${@base_path}/css/style.css" media="screen" />
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<div id="page-content">
|
14
|
+
|
15
|
+
<header id="header">
|
16
|
+
<h1 id="logo"><a href="${@base_path}/">Tenjin Example</a></h1>
|
17
|
+
</header>
|
18
|
+
|
19
|
+
<div id="main-content">
|
20
|
+
<h1>${@page_title}</h1>
|
21
|
+
|
22
|
+
<?rb echo(@_content) ?>
|
23
|
+
|
24
|
+
</div><!-- /main-content -->
|
25
|
+
|
26
|
+
<footer id="footer">
|
27
|
+
<addr>copyright © 2011 Your Name all rights reserved.</addr>
|
28
|
+
</footer>
|
29
|
+
|
30
|
+
</div><!-- /page-content -->
|
31
|
+
|
32
|
+
</body>
|
33
|
+
</html>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
/*** body ***/
|
2
|
+
body {
|
3
|
+
font: 14px "Lucida Grande", "Lucida Sans Unicode", "Helvetica", "Arial", "Verdana", "sans-serif";
|
4
|
+
background-color: #FFF;
|
5
|
+
color: #333;
|
6
|
+
}
|
7
|
+
|
8
|
+
#page-content {
|
9
|
+
margin: 0 auto;
|
10
|
+
width: 960px;
|
11
|
+
}
|
12
|
+
|
13
|
+
#main-content {
|
14
|
+
min-height: 300px;
|
15
|
+
padding: 0 20px 0 20px;
|
16
|
+
}
|
17
|
+
|
18
|
+
/*** header ***/
|
19
|
+
#header {
|
20
|
+
background: #099;
|
21
|
+
color: #FFF;
|
22
|
+
font-weight: bold;
|
23
|
+
margin: 0;
|
24
|
+
padding: 5px 0 5px 20px;
|
25
|
+
text-align: left;
|
26
|
+
}
|
27
|
+
#logo a {
|
28
|
+
color: #FFF;
|
29
|
+
text-decoration: none;
|
30
|
+
}
|
31
|
+
#logo a:hover {
|
32
|
+
text-decoration: underline;
|
33
|
+
}
|
34
|
+
|
35
|
+
/*** footer ***/
|
36
|
+
#footer {
|
37
|
+
background: #099;
|
38
|
+
color: #FFF;
|
39
|
+
font-weight: bold;
|
40
|
+
margin: 20px 0 0 0;
|
41
|
+
padding: 20px 0 20px 0;
|
42
|
+
text-align: center;
|
43
|
+
}
|
44
|
+
|
45
|
+
/*** odd, even ***/
|
46
|
+
.odd {
|
47
|
+
background: #EFE;
|
48
|
+
}
|
49
|
+
.even {
|
50
|
+
background: #EEF;
|
51
|
+
}
|
52
|
+
|
53
|
+
/*** table ***/
|
54
|
+
table.list {
|
55
|
+
border-collapse: collapse;
|
56
|
+
max-width: 960px;
|
57
|
+
}
|
58
|
+
table.list th, table.list td {
|
59
|
+
border: solid 1px #DDD;
|
60
|
+
padding: 2px 5px;
|
61
|
+
}
|
62
|
+
table.list th {
|
63
|
+
font-weight: bold;
|
64
|
+
color: #FFF;
|
65
|
+
background: #099;
|
66
|
+
text-align: left;
|
67
|
+
vertical-align: top;
|
68
|
+
}
|
69
|
+
|
70
|
+
/*** <dl class="form"> ***/
|
71
|
+
dl.form dt {
|
72
|
+
float: left;
|
73
|
+
width: 200px;
|
74
|
+
}
|
75
|
+
dl.form dd {
|
76
|
+
margin-left: 210px;
|
77
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?rb # -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
@page_title = 'Environment Variables'
|
4
|
+
|
5
|
+
?>
|
6
|
+
<table class="list">
|
7
|
+
<tbody>
|
8
|
+
<?rb cycle = new_cycle('odd', 'even') ?>
|
9
|
+
<?rb ENV.keys.sort.each do |key| ?>
|
10
|
+
<tr class="${cycle}">
|
11
|
+
<th>${key}</th><td>${ENV[key]}</td>
|
12
|
+
</tr>
|
13
|
+
<?rb end ?>
|
14
|
+
</tbody>
|
15
|
+
</table>
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?rb # -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'cgi' # or 'cgialt' for performance
|
4
|
+
cgi = CGI.new
|
5
|
+
name = cgi.params['name'].first
|
6
|
+
name = 'World' if name.empty?
|
7
|
+
lang = ENV['HTTP_ACCEPT_LANGUAGE'] =~ /ja/ ? 'ja' : 'en'
|
8
|
+
?>
|
9
|
+
<?rb if lang == 'ja' ?>
|
10
|
+
<h1>こんにちは ${name}!</h1>
|
11
|
+
<?rb else ?>
|
12
|
+
<h1>Hello ${name}!</h1>
|
13
|
+
<?rb end ?>
|
14
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<?rb # -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
@page_title = 'Tenjin Example'
|
4
|
+
|
5
|
+
const_names = [
|
6
|
+
'RUBY_VERSION',
|
7
|
+
'RUBY_PATCHLEVEL',
|
8
|
+
'RUBY_RELEASE_DATE',
|
9
|
+
'RUBY_ENGINE',
|
10
|
+
'RUBY_PLATFORM',
|
11
|
+
]
|
12
|
+
|
13
|
+
?>
|
14
|
+
<p>Versions</p>
|
15
|
+
<table class="list">
|
16
|
+
<tbody>
|
17
|
+
<tr>
|
18
|
+
<th>Time.now</th><td>${Time.now}</td>
|
19
|
+
</tr>
|
20
|
+
<tr>
|
21
|
+
<th>Tenjin::RELEASE</th><td>${Tenjin::RELEASE}</td>
|
22
|
+
</tr>
|
23
|
+
<?rb for name in const_names ?>
|
24
|
+
<tr>
|
25
|
+
<?rb if Object.const_defined?(name) ?>
|
26
|
+
<th>${name}</th><td>${Object.const_get(name)}</td>
|
27
|
+
<?rb else ?>
|
28
|
+
<th>${name}</th><td>-</td>
|
29
|
+
<?rb end ?>
|
30
|
+
</tr>
|
31
|
+
<?rb end ?>
|
32
|
+
</tbody>
|
33
|
+
</table>
|
34
|
+
|
35
|
+
<p>Other examples</p>
|
36
|
+
<ul>
|
37
|
+
<li><a href="env.html">Environment Variables (env.html)</a></li>
|
38
|
+
<li><a href="hello.html?name=Tenjin">Hello World (hello.html?name=Tenjin)</a></li>
|
39
|
+
</ul>
|
@@ -0,0 +1,188 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
##
|
5
|
+
## CGI script to use Tenjin as PHP-like tool.
|
6
|
+
##
|
7
|
+
## setup:
|
8
|
+
##
|
9
|
+
## $ htdocs=/usr/local/apache2/htdocs # or $HOME/public_html
|
10
|
+
## $ tar xzf rbtenjin-X.X.X.tar.gz
|
11
|
+
## $ cd rbtenjin-X.X.X/
|
12
|
+
## $ cp lib/tenjin.rb $htdocs
|
13
|
+
## $ cp public_html/rbtenjin.cgi $htdocs
|
14
|
+
## $ cp public_html/.htaccess $htdocs
|
15
|
+
## $ cd public_html/*.rbhtml $htdocs
|
16
|
+
## $ chmod a+x $htdocs/rbtenjin.cgi
|
17
|
+
##
|
18
|
+
## and access to http://localhost/ (or http://localhost/~yourname/).
|
19
|
+
##
|
20
|
+
## $Release: 0.7.0 $
|
21
|
+
## copyright(c) 2007-2011 kuwata-lab.com all rights reserved
|
22
|
+
## $License: MIT License $
|
23
|
+
##
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'tenjin'
|
27
|
+
rescue LoadError
|
28
|
+
require './tenjin'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
class Http < Exception
|
33
|
+
def initialize(status, text, headers=nil)
|
34
|
+
super("#{status}: #{text}")
|
35
|
+
@status, @text, @headers = status, text, headers
|
36
|
+
end
|
37
|
+
attr_accessor :status, :text, :headers
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
class MainApp
|
42
|
+
include Tenjin::ContextHelper
|
43
|
+
include Tenjin::HtmlHelper
|
44
|
+
include Tenjin::HtmlTagHelper
|
45
|
+
include Tenjin::SafeHelper
|
46
|
+
|
47
|
+
def self.new_engine(opts={})
|
48
|
+
opts[:layout] ||= '_layout.rbhtml' if File.file?('_layout.rbhtml')
|
49
|
+
#opts[:cache] = true # enable cache always
|
50
|
+
opts[:cache] ||= File.writable?('.') # enable cache only when directory is writable
|
51
|
+
#opts[:preprocess] = true
|
52
|
+
return Tenjin::Engine.new(opts) # or Tenjin::SafeEngine
|
53
|
+
end
|
54
|
+
|
55
|
+
@@engine = self.new_engine()
|
56
|
+
|
57
|
+
## set debug mode when on localhost
|
58
|
+
@@debug = (addr = ENV['SERVER_ADDR']) == '127.0.0.1' || addr == '::1'
|
59
|
+
|
60
|
+
def initialize
|
61
|
+
@response_headers = {}
|
62
|
+
end
|
63
|
+
|
64
|
+
def run()
|
65
|
+
begin
|
66
|
+
handle_request()
|
67
|
+
rescue Http => ex
|
68
|
+
handle_http(ex)
|
69
|
+
rescue Exception => ex
|
70
|
+
handle_error(ex)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def handle_request()
|
77
|
+
## simulate CGI in command-line to debug your *.rbhtml file
|
78
|
+
#ENV['SCRIPT_NAME'] = '/A/B/rbtenjin.cgi'
|
79
|
+
#ENV['REQUEST_URI'] = '/A/B/hello.html'
|
80
|
+
|
81
|
+
## get script name and request path
|
82
|
+
script_name = ENV['SCRIPT_NAME'] or # ex. '/A/B/rbtenjin.cgi'
|
83
|
+
raise Http.new('500 Internal Error', "ENV['SCRIPT_NAME'] is not set.")
|
84
|
+
req_uri = ENV['REQUEST_URI'] or # ex. '/A/B/C/foo.html?x=1'
|
85
|
+
raise Http.new('500 Internal Error', "ENV['REQUEST_URI'] is not set.")
|
86
|
+
req_path, _ = req_uri.split(/\?/, 2) # ex. ['/A/B/C/foo.html', 'x=1']
|
87
|
+
|
88
|
+
## deny direct access to rbtenjin.cgi
|
89
|
+
req_path != script_name or
|
90
|
+
raise Http.new('403 Forbidden', "#{req_path}: not accessable.")
|
91
|
+
|
92
|
+
## get base path
|
93
|
+
base_path = File.dirname(script_name) # ex. '/A/B' (or '/')
|
94
|
+
if base_path == '/'
|
95
|
+
base_path = '' # base_path should not be end with '/'
|
96
|
+
else
|
97
|
+
req_path.index(base_path) == 0 or # assertion
|
98
|
+
raise "*** assertion failed: #{req_path.inspect}.index(#{base_path.inspect}) == #{req_path.index(base_path)}"
|
99
|
+
end
|
100
|
+
@base_path = base_path
|
101
|
+
|
102
|
+
## normalize request path and redirect if necessary
|
103
|
+
req_path2 = req_path.dup
|
104
|
+
req_path2.gsub!(/\\/, '/') # ex. '\A\B\C' -> '/A/B/C'
|
105
|
+
req_path2.gsub!(/\/\/+/, '/') # ex. '/A///B//C' -> '/A/B/C'
|
106
|
+
#nil while req_path2.gsub!(%r`/[^\/]+/\.\./`, '/') # ex. '/A/../B' -> '/B'
|
107
|
+
req_path == req_path2 or
|
108
|
+
raise Http.new('302 Found', req_path2, 'Location'=>req_path2)
|
109
|
+
|
110
|
+
## if file_path is a directory, add 'index.html'
|
111
|
+
file_path = req_path[(base_path.length+1)..-1] # ex. 'C/foo.html'
|
112
|
+
if file_path.to_s.empty? # access to root dir
|
113
|
+
file_path = "index.html"
|
114
|
+
elsif File.directory?(file_path) # access to directory
|
115
|
+
file_path[-1] == '/' or
|
116
|
+
raise "*** assertion failed: #{file_path.inspect}[-1] == '/'"
|
117
|
+
file_path << "index.html"
|
118
|
+
end
|
119
|
+
|
120
|
+
## request validation
|
121
|
+
file_path.sub!(/\.html\z/, '.rbhtml') or # expected '*.html'
|
122
|
+
raise Http.new('500 Internal Error', 'invalid .htaccess configuration.')
|
123
|
+
File.file?(file_path) or # file not found
|
124
|
+
raise Http.new('404 Not Found', "#{req_path}: not found.")
|
125
|
+
File.basename(file_path) !~ /\A_/ or # deny access to '_*' (ex. _layout.rbhtml)
|
126
|
+
raise Http.new('403 Forbidden', "#{req_path}: not accessable.")
|
127
|
+
|
128
|
+
## render template
|
129
|
+
output = @@engine.render(file_path, self)
|
130
|
+
|
131
|
+
## print response header and body
|
132
|
+
headers = @response_headers
|
133
|
+
print "Status: #{headers.delete('Status')}\r\n" if headers['Status']
|
134
|
+
headers.each {|k, v| print "#{k}: #{v}\r\n" }
|
135
|
+
print "Content-Type: text/html\r\n" unless headers['Content-Type']
|
136
|
+
print "Content-Length: #{output.length}\r\n" unless headers['Content-Length']
|
137
|
+
print "\r\n"
|
138
|
+
print output
|
139
|
+
end
|
140
|
+
|
141
|
+
def handle_http(http)
|
142
|
+
print "Status: #{h(http.status)}\r\n"
|
143
|
+
http.headers.each {|k, v| print "#{k}: #{v}\r\n" } if http.headers
|
144
|
+
print "Content-Type: text/html\r\n"
|
145
|
+
print "\r\n"
|
146
|
+
print "<h1>#{h(http.status)}</h1>\n"
|
147
|
+
print "<p>#{h(http.text)}</p>\n"
|
148
|
+
end
|
149
|
+
|
150
|
+
def handle_error(ex)
|
151
|
+
$stderr.puts "*** #{ex.class.name}: #{ex.message}"
|
152
|
+
$stderr.puts ex.backtrace.join("\n")
|
153
|
+
print "Status: 500 Internal Error\r\n"
|
154
|
+
print "Content-Type: text/html\r\n"
|
155
|
+
print "\r\n"
|
156
|
+
print "<h1>500 Internal Error</h1>\n"
|
157
|
+
if @@debug
|
158
|
+
print "<h3>#{h(ex.class.name)}: #{h(ex.message)}</h3>\n"
|
159
|
+
print "<style type=\"text/css\">\n"
|
160
|
+
print " pre.backtrace { font-size: large; }\n"
|
161
|
+
print " span.from { color: #933; }\n"
|
162
|
+
print " span.line { color: #333; }\n"
|
163
|
+
print " span.first { font-weight: bold; font-size: x-large; }\n"
|
164
|
+
print "</style>\n"
|
165
|
+
print "<pre class=\"backtrace\">\n"
|
166
|
+
klass = ' first'
|
167
|
+
lines = {}
|
168
|
+
ex.backtrace.each do |item|
|
169
|
+
print " <span class=\"from#{klass}\">from #{h(item)}</span>\n"
|
170
|
+
if item =~ /^(.*?):(\d+)/
|
171
|
+
filename, linenum = $1, $2.to_i
|
172
|
+
#line = File.open(filename) {|f| f.to_a[linenum-1] }
|
173
|
+
lines[filename] ||= File.open(filename) {|f| f.to_a }
|
174
|
+
line = lines[filename][linenum-1]
|
175
|
+
print " <span class=\"line#{klass}\">%4d: %s</span>\n" % [linenum, h(line.strip)]
|
176
|
+
end
|
177
|
+
klass = ''
|
178
|
+
end
|
179
|
+
print "</pre>\n"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
if __FILE__ == $0
|
187
|
+
MainApp.new().run()
|
188
|
+
end
|
data/tenjin.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Rev
|
5
|
-
### $Release: 0.
|
6
|
-
### copyright(c) 2007-
|
4
|
+
### $Rev$
|
5
|
+
### $Release: 0.7.0 $
|
6
|
+
### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
|
7
7
|
###
|
8
8
|
|
9
9
|
require 'rubygems'
|
@@ -14,7 +14,7 @@ spec = Gem::Specification.new do |s|
|
|
14
14
|
s.author = "makoto kuwata"
|
15
15
|
s.email = "kwa(at)kuwata-lab.com"
|
16
16
|
s.rubyforge_project = 'tenjin'
|
17
|
-
s.version = "0.
|
17
|
+
s.version = "0.7.0"
|
18
18
|
s.platform = Gem::Platform::RUBY
|
19
19
|
s.homepage = "http://www.kuwata-lab.com/tenjin/"
|
20
20
|
s.summary = "very fast and full-featured template engine"
|
@@ -33,14 +33,15 @@ spec = Gem::Specification.new do |s|
|
|
33
33
|
files = []
|
34
34
|
files += Dir.glob('lib/**/*')
|
35
35
|
files += Dir.glob('bin/*')
|
36
|
-
|
36
|
+
files += Dir.glob('examples/**/*')
|
37
37
|
files += Dir.glob('test/**/*')
|
38
38
|
files += Dir.glob('doc/**/*')
|
39
39
|
files += Dir.glob('examples/**/*')
|
40
40
|
files += %w[README.txt CHANGES.txt MIT-LICENSE setup.rb tenjin.gemspec]
|
41
41
|
#files += Dir.glob('contrib/*')
|
42
42
|
files += Dir.glob('benchmark/**/*')
|
43
|
-
files += Dir.glob('doc-api/**/*')
|
43
|
+
#files += Dir.glob('doc-api/**/*')
|
44
|
+
files += Dir.glob('public_html/**/*')
|
44
45
|
s.files = files
|
45
46
|
s.executables = ['rbtenjin']
|
46
47
|
s.bindir = 'bin'
|
@@ -60,3 +61,5 @@ if $0 == __FILE__
|
|
60
61
|
Gem::manage_gems
|
61
62
|
Gem::Builder.new(spec).build
|
62
63
|
end
|
64
|
+
|
65
|
+
spec
|
@@ -1,10 +1,10 @@
|
|
1
1
|
## create Engine object for each layout file
|
2
2
|
require 'tenjin'
|
3
|
-
engine1 = Tenjin::Engine.new(:layout=>'
|
4
|
-
engine2 = Tenjin::Engine.new(:layout=>'
|
3
|
+
engine1 = Tenjin::Engine.new(:layout=>'ex10-layout1.rbhtml')
|
4
|
+
engine2 = Tenjin::Engine.new(:layout=>'ex10-layout2.rbhtml')
|
5
5
|
|
6
6
|
## warm up
|
7
|
-
filename = '
|
7
|
+
filename = 'ex10-content.rbhtml'
|
8
8
|
output1 = engine1.render(filename)
|
9
9
|
output2 = engine2.render(filename)
|
10
10
|
raise "*** output1 != output2" if output1 != output2
|