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,81 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 54 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2007 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
#require 'testutil'
|
9
|
+
#require 'testcase-helper'
|
10
|
+
require 'assert-text-equal'
|
11
|
+
|
12
|
+
#class Symbol
|
13
|
+
# def <=>(other)
|
14
|
+
# return self.to_s <=> other.to_s
|
15
|
+
# end
|
16
|
+
#end
|
17
|
+
#
|
18
|
+
#class Hash
|
19
|
+
# def each
|
20
|
+
# self.keys.sort.each do |key|
|
21
|
+
# val = self[key]
|
22
|
+
# yield key, val
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#end
|
26
|
+
|
27
|
+
require 'tenjin'
|
28
|
+
|
29
|
+
class TenjinExamplesTest < Test::Unit::TestCase
|
30
|
+
|
31
|
+
DIR = File.expand_path(File.dirname(__FILE__) + '/data/examples')
|
32
|
+
CWD = Dir.pwd()
|
33
|
+
|
34
|
+
|
35
|
+
def setup
|
36
|
+
Dir.chdir DIR
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def teardown
|
41
|
+
Dir.chdir CWD
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def _test
|
46
|
+
dirname = File.dirname(@filename)
|
47
|
+
if dirname == '.'
|
48
|
+
filename = @filename
|
49
|
+
else
|
50
|
+
filename = File.basename(@filename)
|
51
|
+
Dir.chdir(dirname)
|
52
|
+
end
|
53
|
+
s = File.read(filename)
|
54
|
+
s =~ /\A\$ (.*?)\n/
|
55
|
+
command = $1
|
56
|
+
expected = $'
|
57
|
+
result = `#{command}`
|
58
|
+
assert_text_equal(expected, result)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
Dir.chdir DIR do
|
63
|
+
filenames = []
|
64
|
+
filenames += Dir.glob('**/*.result')
|
65
|
+
filenames += Dir.glob('**/*.source')
|
66
|
+
filenames.each do |filename|
|
67
|
+
name = filename.gsub(/[^\w]/, '_')
|
68
|
+
s = <<-END
|
69
|
+
def test_#{name}
|
70
|
+
# $stderr.puts "*** debug: test_#{name}"
|
71
|
+
@name = '#{name}'
|
72
|
+
@filename = '#{filename}'
|
73
|
+
_test()
|
74
|
+
end
|
75
|
+
END
|
76
|
+
eval s
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
data/test/test_faq.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 45 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2007 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
#require 'testutil'
|
9
|
+
#require 'testcase-helper'
|
10
|
+
require 'assert-text-equal'
|
11
|
+
|
12
|
+
require 'tenjin'
|
13
|
+
|
14
|
+
class TenjinFaqTest < Test::Unit::TestCase
|
15
|
+
|
16
|
+
DIR = File.expand_path(File.dirname(__FILE__) + '/data/faq')
|
17
|
+
CWD = Dir.pwd()
|
18
|
+
|
19
|
+
|
20
|
+
def setup
|
21
|
+
Dir.chdir DIR
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
Dir.chdir CWD
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def _test
|
31
|
+
@name = (caller()[0] =~ /`(.*?)'/) && $1
|
32
|
+
s = File.read(@filename)
|
33
|
+
s =~ /\A\$ (.*?)\n/
|
34
|
+
command = $1
|
35
|
+
expected = $'
|
36
|
+
result = `#{command}`
|
37
|
+
assert_text_equal(expected, result)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
Dir.chdir DIR do
|
42
|
+
filenames = []
|
43
|
+
filenames += Dir.glob('*.result')
|
44
|
+
filenames += Dir.glob('*.source')
|
45
|
+
filenames.each do |filename|
|
46
|
+
name = filename.gsub(/[^\w]/, '_')
|
47
|
+
s = <<-END
|
48
|
+
def test_#{name}
|
49
|
+
# $stderr.puts "*** debug: test_#{name}"
|
50
|
+
@name = '#{name}'
|
51
|
+
@filename = '#{filename}'
|
52
|
+
_test()
|
53
|
+
end
|
54
|
+
END
|
55
|
+
eval s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 52 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2007 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
#require 'testutil'
|
9
|
+
require 'testcase-helper'
|
10
|
+
require 'assert-text-equal'
|
11
|
+
require 'tenjin'
|
12
|
+
|
13
|
+
|
14
|
+
class TenjinHtmlHelperTest < Test::Unit::TestCase
|
15
|
+
|
16
|
+
def test_tagattr
|
17
|
+
actual = Tenjin::HtmlHelper.tagattr('size', 20)
|
18
|
+
expected = ' size="20"'
|
19
|
+
assert_equal(expected, actual)
|
20
|
+
#
|
21
|
+
actual = Tenjin::HtmlHelper.tagattr('size', nil)
|
22
|
+
expected = ''
|
23
|
+
assert_equal(expected, actual)
|
24
|
+
#
|
25
|
+
actual = Tenjin::HtmlHelper.tagattr('checked', true, 'checked')
|
26
|
+
expected = ' checked="checked"'
|
27
|
+
assert_equal(expected, actual)
|
28
|
+
#
|
29
|
+
actual = Tenjin::HtmlHelper.tagattr('checked', false, 'checked')
|
30
|
+
expected = ''
|
31
|
+
assert_equal(expected, actual)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_checked
|
35
|
+
actual = Tenjin::HtmlHelper.checked(1==1)
|
36
|
+
expected = ' checked="checked"'
|
37
|
+
assert_equal(expected, actual)
|
38
|
+
#
|
39
|
+
actual = Tenjin::HtmlHelper.checked(1==0)
|
40
|
+
expected = ''
|
41
|
+
assert_equal(expected, actual)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_selected
|
45
|
+
actual = Tenjin::HtmlHelper.selected(1==1)
|
46
|
+
expected = ' selected="selected"'
|
47
|
+
assert_equal(expected, actual)
|
48
|
+
#
|
49
|
+
actual = Tenjin::HtmlHelper.selected(1==0)
|
50
|
+
expected = ''
|
51
|
+
assert_equal(expected, actual)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_disabled
|
55
|
+
actual = Tenjin::HtmlHelper.disabled(1==1)
|
56
|
+
expected = ' disabled="disabled"'
|
57
|
+
assert_equal(expected, actual)
|
58
|
+
#
|
59
|
+
actual = Tenjin::HtmlHelper.disabled(1==0)
|
60
|
+
expected = ''
|
61
|
+
assert_equal(expected, actual)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_nl2br
|
65
|
+
s = """foo\nbar\nbaz\n"""
|
66
|
+
actual = Tenjin::HtmlHelper.nl2br(s)
|
67
|
+
expected = "foo<br />\nbar<br />\nbaz<br />\n"
|
68
|
+
assert_equal(expected, actual)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_text2html
|
72
|
+
s = """foo\n bar\nba z\n"""
|
73
|
+
actual = Tenjin::HtmlHelper.text2html(s)
|
74
|
+
expected = "foo<br />\n bar<br />\nba z<br />\n"
|
75
|
+
assert_equal(expected, actual)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/test/test_main.rb
ADDED
@@ -0,0 +1,564 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 59 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2007 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
#require 'testutil'
|
9
|
+
require 'testcase-helper'
|
10
|
+
require 'assert-text-equal'
|
11
|
+
|
12
|
+
require 'tenjin'
|
13
|
+
DONT_INVOKE = true
|
14
|
+
load File.dirname(File.dirname(File.expand_path(__FILE__))) + '/bin/rbtenjin'
|
15
|
+
|
16
|
+
|
17
|
+
def to_list(value)
|
18
|
+
return value.is_a?(Array) ? value : [value]
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
INPUT = <<'END'
|
23
|
+
<ul>
|
24
|
+
<?rb for item in ['<a&b>', '["c",'+"'d']"] ?>
|
25
|
+
<li>#{item}
|
26
|
+
${item}</li>
|
27
|
+
<?rb end ?>
|
28
|
+
</ul>
|
29
|
+
END
|
30
|
+
|
31
|
+
INPUT2 = <<'END'
|
32
|
+
<ul>
|
33
|
+
<?rb for item in ['<a&b>', '["c",'+"'d']"] ?>
|
34
|
+
<li>#{item}
|
35
|
+
${item}</li>
|
36
|
+
<?rb end ?>
|
37
|
+
</ul>
|
38
|
+
END
|
39
|
+
INPUT2.gsub!(/\n/, "\r\n")
|
40
|
+
|
41
|
+
INPUT3 = <<'END'
|
42
|
+
<?rb
|
43
|
+
#title = _context['title']
|
44
|
+
#items = _context.items
|
45
|
+
?>
|
46
|
+
<h1>#{@title}</h1>
|
47
|
+
<ul>
|
48
|
+
<?rb for item in @items ?>
|
49
|
+
<li>#{item}</li>
|
50
|
+
<?rb end ?>
|
51
|
+
</ul>
|
52
|
+
END
|
53
|
+
|
54
|
+
SOURCE = <<'END'
|
55
|
+
_buf = ''; _buf << %Q`<ul>\n`
|
56
|
+
for item in ['<a&b>', '["c",'+"'d']"]
|
57
|
+
_buf << %Q` <li>#{item}
|
58
|
+
#{escape((item).to_s)}</li>\n`
|
59
|
+
end
|
60
|
+
_buf << %Q`</ul>\n`
|
61
|
+
_buf.to_s
|
62
|
+
END
|
63
|
+
|
64
|
+
SOURCE2 = <<'END'
|
65
|
+
_buf = ''; _buf << %Q`<ul>\r\n`
|
66
|
+
for item in ['<a&b>', '["c",'+"'d']"]
|
67
|
+
_buf << %Q` <li>#{item}\r
|
68
|
+
#{escape((item).to_s)}</li>\r\n`
|
69
|
+
end
|
70
|
+
_buf << %Q`</ul>\r\n`
|
71
|
+
_buf.to_s
|
72
|
+
END
|
73
|
+
SOURCE2.gsub!(/\n/, "\r\n")
|
74
|
+
|
75
|
+
SOURCE4 = <<'END'
|
76
|
+
_buf = []; _buf.push('<ul>
|
77
|
+
'); for item in ['<a&b>', '["c",'+"'d']"]
|
78
|
+
_buf.push(' <li>', (item).to_s, '
|
79
|
+
', escape((item).to_s), '</li>
|
80
|
+
'); end
|
81
|
+
_buf.push('</ul>
|
82
|
+
');
|
83
|
+
_buf.to_s
|
84
|
+
END
|
85
|
+
|
86
|
+
OUTPUT = <<'END'
|
87
|
+
<ul>
|
88
|
+
<li><a&b>
|
89
|
+
<a&b></li>
|
90
|
+
<li>["c",'d']
|
91
|
+
["c",'d']</li>
|
92
|
+
</ul>
|
93
|
+
END
|
94
|
+
|
95
|
+
OUTPUT2 = <<'END'
|
96
|
+
<ul>
|
97
|
+
<li><a&b>
|
98
|
+
<a&b></li>
|
99
|
+
<li>["c",'d']
|
100
|
+
["c",'d']</li>
|
101
|
+
</ul>
|
102
|
+
END
|
103
|
+
OUTPUT2.gsub!(/\n/, "\r\n")
|
104
|
+
|
105
|
+
OUTPUT3 = <<'END'
|
106
|
+
<h1>rbtenjin example</h1>
|
107
|
+
<ul>
|
108
|
+
<li>aaa</li>
|
109
|
+
<li>bbb</li>
|
110
|
+
<li>ccc</li>
|
111
|
+
</ul>
|
112
|
+
END
|
113
|
+
|
114
|
+
CONTEXT1 = <<'END'
|
115
|
+
title: rbtenjin example
|
116
|
+
items:
|
117
|
+
- aaa
|
118
|
+
- bbb
|
119
|
+
- ccc
|
120
|
+
END
|
121
|
+
|
122
|
+
CONTEXT2 = <<'END'
|
123
|
+
@title = 'rbtenjin example'
|
124
|
+
@items = ['aaa', 'bbb', 'ccc']
|
125
|
+
END
|
126
|
+
|
127
|
+
|
128
|
+
class TenjinMainTest < Test::Unit::TestCase
|
129
|
+
|
130
|
+
filename = __FILE__.sub(/\.\w+$/, '.yaml')
|
131
|
+
#load_yaml_testdata(filename)
|
132
|
+
eval load_yaml_testdata(filename)
|
133
|
+
|
134
|
+
def initialize(*args)
|
135
|
+
super
|
136
|
+
@name = @input = @options = @filename = @context_file = @exception = @errormsg = @expected = nil
|
137
|
+
end
|
138
|
+
|
139
|
+
def _test
|
140
|
+
@name = (caller[0] =~ /`(.*?)'/) && $&
|
141
|
+
return if ENV['TEST'] && ENV['TEST'] != @name
|
142
|
+
#
|
143
|
+
@input ||= ''
|
144
|
+
@options ||= ''
|
145
|
+
#
|
146
|
+
if @filename != false
|
147
|
+
@filename ||= '.test.rbhtml'
|
148
|
+
for fname, s in to_list(@filename).zip(to_list(@input))
|
149
|
+
File.open(fname, 'w') { |f| f.write(s) }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
#
|
153
|
+
if @options.is_a?(Array)
|
154
|
+
argv = @options.dup
|
155
|
+
elsif @options.is_a?(String)
|
156
|
+
argv = @options.split()
|
157
|
+
end
|
158
|
+
#argv.insert(0, 'rbtenjin')
|
159
|
+
argv.concat(to_list(@filename)) if @filename
|
160
|
+
if @context_file
|
161
|
+
File.open(@context_file, 'w') { |f| f.write(@context_data) }
|
162
|
+
end
|
163
|
+
main = Tenjin::Main.new(argv)
|
164
|
+
if @exception
|
165
|
+
if @exception.is_a?(@exception)
|
166
|
+
@exception = Kernel.const_get(@exception)
|
167
|
+
end
|
168
|
+
ex = assert_raise(@exception) do
|
169
|
+
output = main.execute()
|
170
|
+
end
|
171
|
+
if @errormsg
|
172
|
+
assert_text_equal(@errormsg, ex.to_s)
|
173
|
+
end
|
174
|
+
else
|
175
|
+
output = main.execute()
|
176
|
+
assert_text_equal(@expected, output)
|
177
|
+
end
|
178
|
+
ensure
|
179
|
+
to_list(@filename).each { |fname| File.unlink(fname) } if @filename
|
180
|
+
File.unlink(@context_file) if @context_file
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
def test_help() # -h
|
185
|
+
@options = "-h"
|
186
|
+
@input = ""
|
187
|
+
@expected = Tenjin::Main.new(['rbtenjin']).usage()
|
188
|
+
_test()
|
189
|
+
#
|
190
|
+
@options = "--help"
|
191
|
+
_test()
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
def test_version() # -v, --version
|
196
|
+
@options = "-v"
|
197
|
+
@input = ""
|
198
|
+
@expected = Tenjin::Main.new(['rbtenjin']).version() + "\n"
|
199
|
+
_test()
|
200
|
+
@options = "--version"
|
201
|
+
_test()
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
# def test_help_and_version() # -hVc
|
206
|
+
# @options = "-hVc"
|
207
|
+
# @input = "<?rb foo() ?>"
|
208
|
+
# app = Tenjin::Main.new(['rbtenjin'])
|
209
|
+
# @expected = app.version() + "\n" + app.usage('rbtenjin')
|
210
|
+
# _test()
|
211
|
+
# end
|
212
|
+
|
213
|
+
|
214
|
+
def test_execute() # ''
|
215
|
+
@options = ""
|
216
|
+
@input = INPUT
|
217
|
+
@expected = OUTPUT
|
218
|
+
_test()
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
def test_source() # -s, -a convert
|
223
|
+
@options = "-s"
|
224
|
+
@input = INPUT
|
225
|
+
@expected = SOURCE
|
226
|
+
_test()
|
227
|
+
@options = "-a convert"
|
228
|
+
_test()
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
def test_source2() # -s
|
233
|
+
@options = "-s"
|
234
|
+
n1 = "<ul>\n".length
|
235
|
+
n2 = "</ul>\n".length
|
236
|
+
@input = INPUT[n1...-n2]
|
237
|
+
#buf = SOURCE.to_a()[1...-2]
|
238
|
+
buf = SOURCE.split(/\n/).collect{|l| l+"\n"}[1..-3]
|
239
|
+
buf[0,0] = "_buf = ''; "
|
240
|
+
buf << "_buf.to_s\n"
|
241
|
+
@expected = buf.join
|
242
|
+
#$stderr.puts "*** debug: @input=#{@input}"
|
243
|
+
#$stderr.puts "*** debug: @expected=#{@expected}"
|
244
|
+
_test()
|
245
|
+
@options = "-a convert"
|
246
|
+
_test()
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
def test_source3() # -sb, -baconvert
|
251
|
+
@options = "-sb"
|
252
|
+
@input = INPUT
|
253
|
+
n1 = "_buf = ''; ".length
|
254
|
+
n2 = "_buf.to_s\n".length
|
255
|
+
@expected = SOURCE[n1...-n2]
|
256
|
+
_test()
|
257
|
+
@options = "-baconvert"
|
258
|
+
_test()
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
# def test_indent() # -si2
|
263
|
+
# @options = "-si2"
|
264
|
+
# @input = INPUT
|
265
|
+
# @expected = SOURCE.replace(' _buf', ' _buf')
|
266
|
+
# _test()
|
267
|
+
# end
|
268
|
+
|
269
|
+
|
270
|
+
def test_quiet() # -q
|
271
|
+
@options = "-z"
|
272
|
+
input = INPUT
|
273
|
+
@input = [input, input, input]
|
274
|
+
basename = ".test_quiet%d.rbhtml"
|
275
|
+
@filename = (0..3).collect { |i| basename % i }
|
276
|
+
@expected = (0..3).collect { |i| "#{basename % i}: Syntax OK\n" }.join
|
277
|
+
_test()
|
278
|
+
#
|
279
|
+
@options = "-zq"
|
280
|
+
@expected = ""
|
281
|
+
_test()
|
282
|
+
@options = "-qasyntax"
|
283
|
+
_test()
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
def test_invalid_options() # -Y, -i, -f, -c, -i foo
|
288
|
+
@input = INPUT
|
289
|
+
@expected = ""
|
290
|
+
@exception = Tenjin::CommandOptionError
|
291
|
+
#
|
292
|
+
@options = "-hY"
|
293
|
+
@errormsg = "-Y: unknown option."
|
294
|
+
_test()
|
295
|
+
#
|
296
|
+
# @options = "-i"
|
297
|
+
# @filename = false
|
298
|
+
# @errormsg = "-i: indent width required."
|
299
|
+
# _test()
|
300
|
+
#
|
301
|
+
@options = "-f"
|
302
|
+
@filename = false
|
303
|
+
#@errormsg = "-f: context data filename required."
|
304
|
+
@errormsg = "-f: argument required."
|
305
|
+
_test()
|
306
|
+
#
|
307
|
+
@options = "-c"
|
308
|
+
@filename = false
|
309
|
+
#@errormsg = "-c: context data string required."
|
310
|
+
@errormsg = "-c: argument required."
|
311
|
+
_test()
|
312
|
+
#
|
313
|
+
# @options = "-i foo"
|
314
|
+
# @errormsg = "-i: integer value required."
|
315
|
+
# _test()
|
316
|
+
end #
|
317
|
+
|
318
|
+
|
319
|
+
def test_newline()
|
320
|
+
@input = INPUT2
|
321
|
+
@expected = SOURCE2
|
322
|
+
@options = "-s"
|
323
|
+
_test()
|
324
|
+
@options = ""
|
325
|
+
@expected = OUTPUT2
|
326
|
+
_test()
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
def test_datafile_yaml() # -f datafile.yaml
|
331
|
+
context_filename = 'test.datafile.yaml'
|
332
|
+
@options = "-f " + context_filename
|
333
|
+
@input = INPUT3
|
334
|
+
@expected = OUTPUT3
|
335
|
+
@context_file = context_filename
|
336
|
+
@context_data = CONTEXT1
|
337
|
+
_test()
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
def test_datafile_rb() # -f datafile.rb
|
342
|
+
context_filename = 'test.datafile.rb'
|
343
|
+
@options = "-f " + context_filename
|
344
|
+
@input = INPUT3
|
345
|
+
@expected = OUTPUT3
|
346
|
+
@context_file = context_filename
|
347
|
+
@context_data = CONTEXT2
|
348
|
+
_test()
|
349
|
+
end
|
350
|
+
|
351
|
+
|
352
|
+
def test_datafile_error() # -f file.txt, not-a-mapping context data
|
353
|
+
context_filename = 'test.datafile.txt'
|
354
|
+
@options = "-f " + context_filename
|
355
|
+
@exception = Tenjin::CommandOptionError
|
356
|
+
@errormsg = "-f %s: file not found." % context_filename
|
357
|
+
_test()
|
358
|
+
#
|
359
|
+
@context_file = context_filename
|
360
|
+
@context_data = "- foo\n- bar\n -baz"
|
361
|
+
@errormsg = "-f %s: unknown file type ('*.yaml' or '*.rb' expected)." % context_filename
|
362
|
+
_test()
|
363
|
+
#
|
364
|
+
context_filename = 'test.datafile.yaml'
|
365
|
+
@options = "-f " + context_filename
|
366
|
+
@errormsg = "%s: not a mapping (hash)." % context_filename
|
367
|
+
@context_file = context_filename
|
368
|
+
_test()
|
369
|
+
end
|
370
|
+
|
371
|
+
|
372
|
+
def test_context_yaml() # -c yamlstr
|
373
|
+
@options = ['-c', '{title: rbtenjin example, items: [aaa, bbb, ccc]}']
|
374
|
+
@input = INPUT3
|
375
|
+
@expected = OUTPUT3
|
376
|
+
_test()
|
377
|
+
end
|
378
|
+
|
379
|
+
|
380
|
+
def test_context_rb() # -c python-code
|
381
|
+
@options = ['-c', '@title="rbtenjin example"; @items=["aaa", "bbb", "ccc"]']
|
382
|
+
@input = INPUT3
|
383
|
+
@expected = OUTPUT3
|
384
|
+
_test()
|
385
|
+
end
|
386
|
+
|
387
|
+
|
388
|
+
def test_untabify() # -T
|
389
|
+
context_filename = 'test.datafile.yaml'
|
390
|
+
@options = "-Tf " + context_filename
|
391
|
+
@input = INPUT3
|
392
|
+
@expected = OUTPUT3
|
393
|
+
@context_file = context_filename
|
394
|
+
@context_data = CONTEXT1
|
395
|
+
#@exception = yaml.parser.ScannerError
|
396
|
+
@exception = ArgumentError
|
397
|
+
_test()
|
398
|
+
end
|
399
|
+
|
400
|
+
|
401
|
+
def test_modules() # -r libraries
|
402
|
+
#@options = "--escapefunc=CGI.escapeHTML"
|
403
|
+
@options = "--escapefunc=ERB::Util.html_escape"
|
404
|
+
@input = INPUT
|
405
|
+
@expected = OUTPUT
|
406
|
+
@exception = NameError
|
407
|
+
if defined?(YARVCore)
|
408
|
+
#@errormsg = "uninitialized constant Tenjin::Context::CGI"
|
409
|
+
@errormsg = "uninitialized constant Tenjin::Context::ERB"
|
410
|
+
else
|
411
|
+
#@errormsg = "uninitialized constant Tenjin::Template::CGI"
|
412
|
+
@errormsg = "uninitialized constant Tenjin::Template::ERB"
|
413
|
+
end
|
414
|
+
_test()
|
415
|
+
#
|
416
|
+
#@options = "-r cgi --escapefunc=CGI.escapeHTML"
|
417
|
+
@options = "-r erb --escapefunc=ERB::Util.html_escape"
|
418
|
+
@input = INPUT
|
419
|
+
@expected = OUTPUT
|
420
|
+
@exception = nil
|
421
|
+
@errormsg = nil
|
422
|
+
_test()
|
423
|
+
end
|
424
|
+
|
425
|
+
|
426
|
+
def test_modules_err() # -r hogeratta
|
427
|
+
@options = '-r hogeratta'
|
428
|
+
@exception = Tenjin::CommandOptionError
|
429
|
+
@errormsg = '-r hogeratta: library not found.'
|
430
|
+
_test()
|
431
|
+
end
|
432
|
+
|
433
|
+
|
434
|
+
def test_escapefunc() # --escapefunc=cgi.escape
|
435
|
+
@options = "--escapefunc=CGI.escapeHTML -s"
|
436
|
+
@input = INPUT
|
437
|
+
@expected = SOURCE.gsub('escape', 'CGI.escapeHTML')
|
438
|
+
_test()
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
# def test_tostrfunc() # --tostrfunc=str
|
443
|
+
# @options = "--tostrfunc=str"
|
444
|
+
# @input = INPUT
|
445
|
+
# @expected = SOURCE.replace('to_str', 'str')
|
446
|
+
# _test()
|
447
|
+
# end
|
448
|
+
|
449
|
+
|
450
|
+
def test_preamble() # --preamble --postamble
|
451
|
+
@options = ["--preamble=_buf=[];", "--postamble=_buf.join", "-s"]
|
452
|
+
@input = INPUT
|
453
|
+
@expected = SOURCE.sub(/^_buf = ''; /, '_buf=[];').sub(/_buf.to_s/, '_buf.join')
|
454
|
+
_test()
|
455
|
+
end
|
456
|
+
|
457
|
+
|
458
|
+
def test_templateclass() # --templateclass
|
459
|
+
@options = "--templateclass=Tenjin::ArrayBufferTemplate -s"
|
460
|
+
@input = INPUT
|
461
|
+
@expected = SOURCE4
|
462
|
+
_test()
|
463
|
+
@options = "--templateclass=Tenjin::ArrayBufferTemplate"
|
464
|
+
@expected = OUTPUT
|
465
|
+
_test()
|
466
|
+
end
|
467
|
+
|
468
|
+
|
469
|
+
def test_template_path() # --path
|
470
|
+
layout = <<'END'
|
471
|
+
<html>
|
472
|
+
<body>
|
473
|
+
#{@_content}
|
474
|
+
<?rb import(:footer) ?>
|
475
|
+
</body>
|
476
|
+
</html>
|
477
|
+
END
|
478
|
+
body = <<'END'
|
479
|
+
<ul>
|
480
|
+
<?rb for item in %w[A B C] ?>
|
481
|
+
<li>${item}</li>
|
482
|
+
<?rb end ?>
|
483
|
+
</ul>
|
484
|
+
END
|
485
|
+
footer = <<'END'
|
486
|
+
<hr />
|
487
|
+
<a href="mailto:webmaster@localhost">webmaser</a>
|
488
|
+
END
|
489
|
+
expected = <<'END'
|
490
|
+
<html>
|
491
|
+
<body>
|
492
|
+
<ul>
|
493
|
+
<li>A</li>
|
494
|
+
<li>B</li>
|
495
|
+
<li>C</li>
|
496
|
+
</ul>
|
497
|
+
|
498
|
+
<hr />
|
499
|
+
<a href="mailto:webmaster@localhost">webmaser</a>
|
500
|
+
</body>
|
501
|
+
</html>
|
502
|
+
END
|
503
|
+
# setup
|
504
|
+
begin
|
505
|
+
Dir.mkdir("tmpl9") unless test(?d, "tmpl9")
|
506
|
+
Dir.mkdir("tmpl9/user") unless test(?d, "tmpl9/user")
|
507
|
+
File.write("tmpl9/layout.rbhtml", layout)
|
508
|
+
File.write("tmpl9/body.rbhtml", '')
|
509
|
+
File.write("tmpl9/footer.rbhtml", '')
|
510
|
+
File.write("tmpl9/user/body.rbhtml", body)
|
511
|
+
File.write("tmpl9/user/footer.rbhtml", footer)
|
512
|
+
# body
|
513
|
+
@options = "--path=.,tmpl9/user,tmpl9 --postfix=.rbhtml --layout=:layout"
|
514
|
+
@input = "<?rb import(:body) ?>"
|
515
|
+
@expected = expected
|
516
|
+
_test()
|
517
|
+
# footer
|
518
|
+
ensure
|
519
|
+
require 'fileutils'
|
520
|
+
FileUtils.rm_rf('tmpl9')
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
|
525
|
+
def test_preprocessor # -P --preprocess
|
526
|
+
@options = "-P"
|
527
|
+
@input = <<'END'
|
528
|
+
<?RB states = { "CA"=>"California", ?>
|
529
|
+
<?RB "NY"=>"New York", ?>
|
530
|
+
<?RB "FL"=>"Florida", } ?>
|
531
|
+
<?rb chk = { @user['state'] => ' checked="checked"' } ?>
|
532
|
+
<select name="state">
|
533
|
+
<?RB for code in states.keys.sort ?>
|
534
|
+
<option value="#{{code}}"#{chk[#{{code.inspect}}]}>${{states[code]}}</option>
|
535
|
+
<?RB end ?>
|
536
|
+
</select>
|
537
|
+
END
|
538
|
+
script = <<'END'
|
539
|
+
<?rb chk = { @user['state'] => ' checked="checked"' } ?>
|
540
|
+
<select name="state">
|
541
|
+
<option value="CA"#{chk["CA"]}>California</option>
|
542
|
+
<option value="FL"#{chk["FL"]}>Florida</option>
|
543
|
+
<option value="NY"#{chk["NY"]}>New York</option>
|
544
|
+
</select>
|
545
|
+
END
|
546
|
+
@expected = script
|
547
|
+
_test()
|
548
|
+
@options = "-apreprocess"
|
549
|
+
_test()
|
550
|
+
#
|
551
|
+
expected = <<'END'
|
552
|
+
<select name="state">
|
553
|
+
<option value="CA">California</option>
|
554
|
+
<option value="FL" checked="checked">Florida</option>
|
555
|
+
<option value="NY">New York</option>
|
556
|
+
</select>
|
557
|
+
END
|
558
|
+
@options = ["-c", "{user: {state: FL}}", "--preprocess"]
|
559
|
+
@expected = expected
|
560
|
+
_test()
|
561
|
+
end
|
562
|
+
|
563
|
+
|
564
|
+
end
|