tenjin 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.txt +54 -0
- data/benchmark/bench.rb +502 -0
- data/benchmark/bench_context.rb +17 -0
- data/benchmark/bench_context.yaml +141 -0
- data/benchmark/templates/_footer.html +4 -0
- data/benchmark/templates/_header.html +52 -0
- data/benchmark/templates/bench_eruby.rhtml +29 -0
- data/benchmark/templates/bench_tenjin.rbhtml +29 -0
- data/bin/rbtenjin +449 -0
- data/doc-api/classes/Tenjin.html +141 -0
- data/doc-api/classes/Tenjin/ArrayBufferTemplate.html +270 -0
- data/doc-api/classes/Tenjin/BaseContext.html +312 -0
- data/doc-api/classes/Tenjin/Context.html +126 -0
- data/doc-api/classes/Tenjin/ContextHelper.html +433 -0
- data/doc-api/classes/Tenjin/Engine.html +616 -0
- data/doc-api/classes/Tenjin/ErubisTemplate.html +166 -0
- data/doc-api/classes/Tenjin/HtmlHelper.html +359 -0
- data/doc-api/classes/Tenjin/Preprocessor.html +242 -0
- data/doc-api/classes/Tenjin/Template.html +916 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/README_txt.html +185 -0
- data/doc-api/files/lib/tenjin_rb.html +136 -0
- data/doc-api/fr_class_index.html +36 -0
- data/doc-api/fr_file_index.html +28 -0
- data/doc-api/fr_method_index.html +89 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/docstyle.css +188 -0
- data/doc/examples.html +312 -0
- data/doc/faq.html +909 -0
- data/doc/users-guide.html +1691 -0
- data/lib/tenjin.rb +959 -0
- data/setup.rb +1331 -0
- data/tenjin.gemspec +58 -0
- data/test/assert-text-equal.rb +45 -0
- data/test/data/examples/form/create.rbhtml +4 -0
- data/test/data/examples/form/form.rbhtml +14 -0
- data/test/data/examples/form/layout.rbhtml +8 -0
- data/test/data/examples/form/main.rb +9 -0
- data/test/data/examples/form/main.result +21 -0
- data/test/data/examples/form/update.rbhtml +4 -0
- data/test/data/examples/preprocessing/helper.rb +16 -0
- data/test/data/examples/preprocessing/main.rb +11 -0
- data/test/data/examples/preprocessing/main.result +17 -0
- data/test/data/examples/preprocessing/select.rbhtml +15 -0
- data/test/data/examples/preprocessing/select_P.result +18 -0
- data/test/data/examples/table/table.rb +9 -0
- data/test/data/examples/table/table.rbhtml +16 -0
- data/test/data/examples/table/table.result +20 -0
- data/test/data/examples/table/table_s.result +18 -0
- data/test/data/faq/ex1.rbhtml +5 -0
- data/test/data/faq/ex10-baselayout.rbhtml +27 -0
- data/test/data/faq/ex10-content.rbhtml +12 -0
- data/test/data/faq/ex10-customlayout.rbhtml +11 -0
- data/test/data/faq/ex10_inherit.result +25 -0
- data/test/data/faq/ex11-bench.rb +28 -0
- data/test/data/faq/ex11-content.rbhtml +9 -0
- data/test/data/faq/ex11-layout1.rbhtml +5 -0
- data/test/data/faq/ex11-layout2.rbhtml +6 -0
- data/test/data/faq/ex11.rb +5 -0
- data/test/data/faq/ex11.rbhtml +8 -0
- data/test/data/faq/ex11.source +11 -0
- data/test/data/faq/ex11_arraybuffer.result +15 -0
- data/test/data/faq/ex1_chksyntax.result +3 -0
- data/test/data/faq/ex2-content.rbhtml +3 -0
- data/test/data/faq/ex2-layout.rbhtml +11 -0
- data/test/data/faq/ex2_removenl.result +19 -0
- data/test/data/faq/ex3.rb +4 -0
- data/test/data/faq/ex3.rbhtml +1 -0
- data/test/data/faq/ex3_escapefunc1.result +2 -0
- data/test/data/faq/ex3_escapefunc2.result +2 -0
- data/test/data/faq/ex5.rbhtml +7 -0
- data/test/data/faq/ex5_template_args.source +9 -0
- data/test/data/faq/ex6-content.rhtml +6 -0
- data/test/data/faq/ex6-layout.rhtml +6 -0
- data/test/data/faq/ex6.rb +10 -0
- data/test/data/faq/ex6_eruby.result +12 -0
- data/test/data/faq/ex7-expr-pattern.rb +34 -0
- data/test/data/faq/ex7-expr-pattern.rbhtml +3 -0
- data/test/data/faq/ex7_expr_pattern.result +4 -0
- data/test/data/faq/ex8-m18n.rb +77 -0
- data/test/data/faq/ex8-m18n.rbhtml +4 -0
- data/test/data/faq/ex8_m18n.result +10 -0
- data/test/data/faq/ex9-baselayout.rbhtml +8 -0
- data/test/data/faq/ex9-content.rbhtml +6 -0
- data/test/data/faq/ex9-mylayout.rbhtml +5 -0
- data/test/data/faq/ex9_changelayout.result +11 -0
- data/test/data/users_guide/content6.rbhtml +3 -0
- data/test/data/users_guide/content7.rbhtml +5 -0
- data/test/data/users_guide/content8.rbhtml +2 -0
- data/test/data/users_guide/contextdata.rb +7 -0
- data/test/data/users_guide/datafile.rb +5 -0
- data/test/data/users_guide/datafile.yaml +10 -0
- data/test/data/users_guide/ex.rbhtml +6 -0
- data/test/data/users_guide/ex.result +7 -0
- data/test/data/users_guide/ex.script +5 -0
- data/test/data/users_guide/ex_script.result +7 -0
- data/test/data/users_guide/ex_source.result +8 -0
- data/test/data/users_guide/example1.rbhtml +12 -0
- data/test/data/users_guide/example1.result +17 -0
- data/test/data/users_guide/example10.rbhtml +4 -0
- data/test/data/users_guide/example10_template_args.result +6 -0
- data/test/data/users_guide/example11.rbhtml +5 -0
- data/test/data/users_guide/example11_template_args_result +2 -0
- data/test/data/users_guide/example12.rbhtml +12 -0
- data/test/data/users_guide/example12_preprocessed.result +10 -0
- data/test/data/users_guide/example12_preprocessed_source.result +10 -0
- data/test/data/users_guide/example13.rbhtml +6 -0
- data/test/data/users_guide/example13_preprocessed.result +2 -0
- data/test/data/users_guide/example13_preprocessed_source.result +2 -0
- data/test/data/users_guide/example14.rb +32 -0
- data/test/data/users_guide/example14.rbhtml +6 -0
- data/test/data/users_guide/example14_tmplclass.result +15 -0
- data/test/data/users_guide/example15.rb +10 -0
- data/test/data/users_guide/example15_escapefunc.result +14 -0
- data/test/data/users_guide/example16.rbhtml +4 -0
- data/test/data/users_guide/example16a.rb +10 -0
- data/test/data/users_guide/example16a.result +4 -0
- data/test/data/users_guide/example16b.rb +13 -0
- data/test/data/users_guide/example16b.result +4 -0
- data/test/data/users_guide/example16c.rb +12 -0
- data/test/data/users_guide/example16c.result +4 -0
- data/test/data/users_guide/example1_S.result +14 -0
- data/test/data/users_guide/example1_SXNC.result +10 -0
- data/test/data/users_guide/example1_source.result +14 -0
- data/test/data/users_guide/example2.rbhtml +3 -0
- data/test/data/users_guide/example2_sb.result2 +9 -0
- data/test/data/users_guide/example3.rbhtml +5 -0
- data/test/data/users_guide/example3_syntaxcheck.result +2 -0
- data/test/data/users_guide/example4.rbhtml +13 -0
- data/test/data/users_guide/example4_datafile_rb.result +13 -0
- data/test/data/users_guide/example4_yaml.result +13 -0
- data/test/data/users_guide/example5.rbhtml +9 -0
- data/test/data/users_guide/example5_datastr_rb.result +9 -0
- data/test/data/users_guide/example5_datastr_yaml.result +9 -0
- data/test/data/users_guide/example6.rbhtml +19 -0
- data/test/data/users_guide/example6_layout.result +29 -0
- data/test/data/users_guide/example6_nested.result +28 -0
- data/test/data/users_guide/example7_layout2.result +13 -0
- data/test/data/users_guide/example8_layout3.result +8 -0
- data/test/data/users_guide/example9.rbhtml +18 -0
- data/test/data/users_guide/example9_capture.result +26 -0
- data/test/data/users_guide/footer.html +5 -0
- data/test/data/users_guide/footer.rbhtml +4 -0
- data/test/data/users_guide/layout6.rbhtml +17 -0
- data/test/data/users_guide/layout7.rbhtml +9 -0
- data/test/data/users_guide/layout8_html.rbhtml +5 -0
- data/test/data/users_guide/layout8_xhtml.rbhtml +6 -0
- data/test/data/users_guide/layout9.rbhtml +25 -0
- data/test/data/users_guide/sidemenu.rbhtml +5 -0
- data/test/data/users_guide/user_app.cgi +39 -0
- data/test/data/users_guide/user_app.result +30 -0
- data/test/data/users_guide/user_create.rbhtml +6 -0
- data/test/data/users_guide/user_edit.rbhtml +7 -0
- data/test/data/users_guide/user_form.rbhtml +10 -0
- data/test/data/users_guide/user_layout.rbhtml +16 -0
- data/test/test_all.rb +23 -0
- data/test/test_engine.rb +526 -0
- data/test/test_engine.yaml +2039 -0
- data/test/test_examples.rb +81 -0
- data/test/test_faq.rb +60 -0
- data/test/test_htmlhelper.rb +78 -0
- data/test/test_main.rb +564 -0
- data/test/test_main.yaml +174 -0
- data/test/test_template.rb +113 -0
- data/test/test_template.yaml +1244 -0
- data/test/test_users_guide.rb +75 -0
- data/test/testcase-helper.rb +166 -0
- metadata +226 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
$ rbtenjin -s --templateclass=Tenjin::ArrayBufferTemplate ex11.rbhtml
|
2
|
+
_buf = []; _buf.push('<table>
|
3
|
+
'); @items.each_with_index do |item, i|
|
4
|
+
_buf.push(' <tr>
|
5
|
+
<td>', (i).to_s, '</td>
|
6
|
+
<td>', escape((item).to_s), '</td>
|
7
|
+
</tr>
|
8
|
+
'); end
|
9
|
+
_buf.push('</table>
|
10
|
+
');
|
11
|
+
_buf.to_s
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello ${@name}!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
require 'tenjin'
|
3
|
+
|
4
|
+
include Erubis::XmlHelper
|
5
|
+
|
6
|
+
context = { :items => ['<AAA>', 'B&B', '"CCC"'] }
|
7
|
+
engine = Tenjin::Engine.new(:layout=>'ex6-layout.rhtml',
|
8
|
+
:templateclass=>Tenjin::ErubisTemplate)
|
9
|
+
output = engine.render('ex6-content.rhtml', context)
|
10
|
+
print output
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'tenjin'
|
2
|
+
|
3
|
+
class MyTemplate < Tenjin::Template
|
4
|
+
|
5
|
+
## return pattern object for embedded expressions
|
6
|
+
def expr_pattern()
|
7
|
+
return /([$#])\{(.*?)\}|<%=(.*?)%>/m
|
8
|
+
end
|
9
|
+
|
10
|
+
## if you don't use '#{...}', you must escape '#' in addition to '\\' and '`'
|
11
|
+
#def escape_str(str)
|
12
|
+
# return str.gsub(/[\\`\#]/, '\\\\\&')
|
13
|
+
#end
|
14
|
+
|
15
|
+
## return expression string and flag whether escape or not from matched object
|
16
|
+
def get_expr_and_escapeflag(match)
|
17
|
+
if match[1]
|
18
|
+
expr = match[2]
|
19
|
+
escapeflag = match[1] == '$'
|
20
|
+
else
|
21
|
+
expr = match[3].strip()
|
22
|
+
escapeflag = false
|
23
|
+
end
|
24
|
+
return expr, escapeflag
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
if __FILE__ == $0
|
30
|
+
context = { :value => 'AAA&BBB' }
|
31
|
+
engine = Tenjin::Engine.new(:templateclass=>MyTemplate)
|
32
|
+
output = engine.render('ex7-expr-pattern.rbhtml', context)
|
33
|
+
puts output
|
34
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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
|
+
##
|
15
|
+
## add translation method to Context class
|
16
|
+
##
|
17
|
+
class Tenjin::Context
|
18
|
+
|
19
|
+
def _(message_key)
|
20
|
+
message_dict = MESSAGE_CATALOG[@_lang]
|
21
|
+
return message_key unless message_dict
|
22
|
+
return message_dict[message_key] || message_key
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
##
|
29
|
+
## engine class which supports M17N
|
30
|
+
##
|
31
|
+
class M17NEngine < Tenjin::Engine
|
32
|
+
|
33
|
+
attr_accessor :lang
|
34
|
+
|
35
|
+
## constructor takes ':lang' options
|
36
|
+
def initialize(properties={})
|
37
|
+
super(properties)
|
38
|
+
@lang = properties[:lang] || 'en' # set language
|
39
|
+
end
|
40
|
+
|
41
|
+
## change cache filename to 'file.html.lang.cache'
|
42
|
+
def cachename(filename)
|
43
|
+
return "#{filename}.#{@lang}.cache"
|
44
|
+
end
|
45
|
+
|
46
|
+
## set language to context object
|
47
|
+
def hook_context(context)
|
48
|
+
context = super(context)
|
49
|
+
context['_lang'] = @lang
|
50
|
+
return context
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
##
|
57
|
+
## test program
|
58
|
+
##
|
59
|
+
if $0 == __FILE__
|
60
|
+
|
61
|
+
template_name = 'ex8-m18n.rbhtml'
|
62
|
+
context = { :username => 'World' }
|
63
|
+
|
64
|
+
## engine for english
|
65
|
+
engine = M17NEngine.new(:preprocess=>true)
|
66
|
+
output = engine.render(template_name, context) # same template
|
67
|
+
puts "--- lang: %s ---" % engine.lang
|
68
|
+
puts output
|
69
|
+
puts
|
70
|
+
|
71
|
+
## engine for French
|
72
|
+
engine = M17NEngine.new(:preprocess=>true, :lang=>'fr')
|
73
|
+
output = engine.render(template_name, context) # same template
|
74
|
+
puts "--- lang: %s ---" % engine.lang
|
75
|
+
puts output
|
76
|
+
|
77
|
+
end
|