html-template-pro 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +9 -0
- data/ARTISTIC +131 -0
- data/History.txt +4 -0
- data/LGPL +504 -0
- data/Manifest.txt +221 -0
- data/README.rdoc +52 -0
- data/Rakefile +18 -0
- data/benchmark.rb +136 -0
- data/config/website.yml +2 -0
- data/ext/html/template/internal/Pro.xs +679 -0
- data/ext/html/template/internal/builtin_findfile.inc +361 -0
- data/ext/html/template/internal/calc.h +26 -0
- data/ext/html/template/internal/calc.inc +120 -0
- data/ext/html/template/internal/callback_stubs.inc +63 -0
- data/ext/html/template/internal/expr.c +2267 -0
- data/ext/html/template/internal/expr.y +476 -0
- data/ext/html/template/internal/expr_iface.c +94 -0
- data/ext/html/template/internal/exprpstr.h +36 -0
- data/ext/html/template/internal/exprpstr.inc +144 -0
- data/ext/html/template/internal/exprtool.h +99 -0
- data/ext/html/template/internal/exprtool.inc +289 -0
- data/ext/html/template/internal/exprtype.h +62 -0
- data/ext/html/template/internal/exprval.h +30 -0
- data/ext/html/template/internal/extconf.rb +6 -0
- data/ext/html/template/internal/internal.c +449 -0
- data/ext/html/template/internal/loadfile.h +11 -0
- data/ext/html/template/internal/loadfile.inc +171 -0
- data/ext/html/template/internal/pabidecl.h +54 -0
- data/ext/html/template/internal/pabstract.h +426 -0
- data/ext/html/template/internal/parse_expr.h +15 -0
- data/ext/html/template/internal/pbuffer.c +76 -0
- data/ext/html/template/internal/pbuffer.h +31 -0
- data/ext/html/template/internal/pmiscdef.h +54 -0
- data/ext/html/template/internal/pparam.h +101 -0
- data/ext/html/template/internal/ppport.h +1098 -0
- data/ext/html/template/internal/procore.c +1189 -0
- data/ext/html/template/internal/procore.h +18 -0
- data/ext/html/template/internal/proparam.c +443 -0
- data/ext/html/template/internal/proparam.h +571 -0
- data/ext/html/template/internal/proscope.h +32 -0
- data/ext/html/template/internal/proscope.inc +107 -0
- data/ext/html/template/internal/prostate.h +49 -0
- data/ext/html/template/internal/prostate.inc +24 -0
- data/ext/html/template/internal/provalue.h +14 -0
- data/ext/html/template/internal/pstring.h +60 -0
- data/ext/html/template/internal/pstrutils.h +25 -0
- data/ext/html/template/internal/pstrutils.inc +150 -0
- data/ext/html/template/internal/tagstack.h +30 -0
- data/ext/html/template/internal/tagstack.inc +65 -0
- data/ext/html/template/internal/tmpllog.c +62 -0
- data/ext/html/template/internal/tmpllog.h +27 -0
- data/ext/html/template/internal/tmplpro.h +218 -0
- data/ext/html/template/internal/tmplpro_version.c +35 -0
- data/lib/html/template/pro.rb +225 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/extconf/tmplpro.rake +43 -0
- data/templates-Pro/a.incl +1 -0
- data/templates-Pro/empty.incl +0 -0
- data/templates-Pro/include/1/a.incl +1 -0
- data/templates-Pro/include/2.out +3 -0
- data/templates-Pro/include/2.tmpl +1 -0
- data/templates-Pro/include/2/a.incl +1 -0
- data/templates-Pro/include/3.tmpl +1 -0
- data/templates-Pro/include/4.tmpl +1 -0
- data/templates-Pro/include/a.incl +1 -0
- data/templates-Pro/test_broken.tmpl +25 -0
- data/templates-Pro/test_broken1.out +1 -0
- data/templates-Pro/test_broken1.tmpl +1 -0
- data/templates-Pro/test_esc1.out +4 -0
- data/templates-Pro/test_esc1.tmpl +4 -0
- data/templates-Pro/test_esc2.out +5 -0
- data/templates-Pro/test_esc2.tmpl +6 -0
- data/templates-Pro/test_esc3.out +4 -0
- data/templates-Pro/test_esc3.tmpl +4 -0
- data/templates-Pro/test_esc4.out +3 -0
- data/templates-Pro/test_esc4.tmpl +4 -0
- data/templates-Pro/test_expr1.out +26 -0
- data/templates-Pro/test_expr1.tmpl +26 -0
- data/templates-Pro/test_expr2.out +34 -0
- data/templates-Pro/test_expr2.tmpl +34 -0
- data/templates-Pro/test_expr3.out +6 -0
- data/templates-Pro/test_expr3.tmpl +6 -0
- data/templates-Pro/test_expr4.out +4 -0
- data/templates-Pro/test_expr4.tmpl +4 -0
- data/templates-Pro/test_expr5.out +18 -0
- data/templates-Pro/test_expr5.tmpl +18 -0
- data/templates-Pro/test_expr6.out +18 -0
- data/templates-Pro/test_expr6.tmpl +18 -0
- data/templates-Pro/test_expr7.out +44 -0
- data/templates-Pro/test_expr7.tmpl +20 -0
- data/templates-Pro/test_expr8.out +15 -0
- data/templates-Pro/test_expr8.tmpl +15 -0
- data/templates-Pro/test_if1.out +25 -0
- data/templates-Pro/test_if1.tmpl +28 -0
- data/templates-Pro/test_if2.out +17 -0
- data/templates-Pro/test_if2.tmpl +25 -0
- data/templates-Pro/test_if3.out +12 -0
- data/templates-Pro/test_if3.tmpl +14 -0
- data/templates-Pro/test_if4.out +15 -0
- data/templates-Pro/test_if4.tmpl +31 -0
- data/templates-Pro/test_if5.out +16 -0
- data/templates-Pro/test_if5.tmpl +16 -0
- data/templates-Pro/test_if6.out +15 -0
- data/templates-Pro/test_if6.tmpl +31 -0
- data/templates-Pro/test_if7.out +14 -0
- data/templates-Pro/test_if7.tmpl +18 -0
- data/templates-Pro/test_include1.out +23 -0
- data/templates-Pro/test_include1.tmpl +7 -0
- data/templates-Pro/test_include2.out +120 -0
- data/templates-Pro/test_include2.tmpl +10 -0
- data/templates-Pro/test_include3.out +8 -0
- data/templates-Pro/test_include3.tmpl +8 -0
- data/templates-Pro/test_include4.out +7 -0
- data/templates-Pro/test_include4.tmpl +6 -0
- data/templates-Pro/test_include5.out +7 -0
- data/templates-Pro/test_include5.tmpl +6 -0
- data/templates-Pro/test_loop1.erb +17 -0
- data/templates-Pro/test_loop1.out +12 -0
- data/templates-Pro/test_loop1.tmpl +16 -0
- data/templates-Pro/test_loop2.erb +19 -0
- data/templates-Pro/test_loop2.out +40 -0
- data/templates-Pro/test_loop2.tmpl +19 -0
- data/templates-Pro/test_loop3.out +38 -0
- data/templates-Pro/test_loop3.tmpl +40 -0
- data/templates-Pro/test_loop4.out +44 -0
- data/templates-Pro/test_loop4.tmpl +20 -0
- data/templates-Pro/test_loop5.out +9 -0
- data/templates-Pro/test_loop5.tmpl +11 -0
- data/templates-Pro/test_loop6.out +33 -0
- data/templates-Pro/test_loop6.tmpl +15 -0
- data/templates-Pro/test_malloc.tmpl +1 -0
- data/templates-Pro/test_userfunc1.out +14 -0
- data/templates-Pro/test_userfunc1.tmpl +14 -0
- data/templates-Pro/test_userfunc2.out +35 -0
- data/templates-Pro/test_userfunc2.tmpl +5 -0
- data/templates-Pro/test_userfunc3.out +5 -0
- data/templates-Pro/test_userfunc3.tmpl +5 -0
- data/templates-Pro/test_userfunc4.out +10 -0
- data/templates-Pro/test_userfunc4.tmpl +10 -0
- data/templates-Pro/test_userfunc5.out +4 -0
- data/templates-Pro/test_userfunc5.tmpl +4 -0
- data/templates-Pro/test_userfunc6.out +4 -0
- data/templates-Pro/test_userfunc6.tmpl +4 -0
- data/templates-Pro/test_var1.erb +23 -0
- data/templates-Pro/test_var1.out +20 -0
- data/templates-Pro/test_var1.tmpl +23 -0
- data/templates-Pro/test_var2.erb +7 -0
- data/templates-Pro/test_var2.out +6 -0
- data/templates-Pro/test_var2.tmpl +7 -0
- data/templates-Pro/test_var3.out +14 -0
- data/templates-Pro/test_var3.tmpl +16 -0
- data/templates/case_loop.tmpl +3 -0
- data/templates/context.tmpl +3 -0
- data/templates/counter.tmpl +2 -0
- data/templates/default.tmpl +1 -0
- data/templates/default_escape.tmpl +4 -0
- data/templates/double_loop.tmpl +7 -0
- data/templates/escape.tmpl +5 -0
- data/templates/global-loops.tmpl +9 -0
- data/templates/globals.tmpl +11 -0
- data/templates/if.tmpl +7 -0
- data/templates/ifelse.tmpl +6 -0
- data/templates/include.tmpl +14 -0
- data/templates/include_path/a.tmpl +2 -0
- data/templates/include_path/b.tmpl +1 -0
- data/templates/include_path/inner.tmpl +1 -0
- data/templates/include_path/one.tmpl +2 -0
- data/templates/include_path2/inner.tmpl +1 -0
- data/templates/included.tmpl +4 -0
- data/templates/included2.tmpl +3 -0
- data/templates/js.tmpl +1 -0
- data/templates/long_loops.tmpl +307 -0
- data/templates/loop-context.tmpl +2 -0
- data/templates/loop-if.tmpl +9 -0
- data/templates/medium.tmpl +217 -0
- data/templates/multiline_tags.tmpl +7 -0
- data/templates/newline_test1.tmpl +1 -0
- data/templates/newline_test2.tmpl +1 -0
- data/templates/other-loop.tmpl +7 -0
- data/templates/outer.tmpl +3 -0
- data/templates/query-test.tmpl +21 -0
- data/templates/query-test2.tmpl +12 -0
- data/templates/recursive.tmpl +2 -0
- data/templates/searchpath/included.tmpl +4 -0
- data/templates/searchpath/three.tmpl +1 -0
- data/templates/searchpath/two.tmpl +2 -0
- data/templates/simple-loop-nonames.tmpl +13 -0
- data/templates/simple-loop.tmpl +12 -0
- data/templates/simple.tmpl +9 -0
- data/templates/unless.tmpl +5 -0
- data/templates/urlescape.tmpl +3 -0
- data/templates/vanguard1.tmpl +2 -0
- data/templates/vanguard2.tmpl +3 -0
- data/test/templates/complex.tmpl +24 -0
- data/test/templates/foo.tmpl +6 -0
- data/test/templates/func.tmpl +2 -0
- data/test/templates/loop.tmpl +14 -0
- data/test/templates/negative.tmpl +1 -0
- data/test/templates/numerics.tmpl +6 -0
- data/test/templates/register.tmpl +2 -0
- data/test/test_basic.rb +23 -0
- data/test/test_coderefs.rb +16 -0
- data/test/test_complex.rb +106 -0
- data/test/test_helper.rb +3 -0
- data/test/test_html_template.rb +583 -0
- data/test/test_html_template_internal_extn.rb +10 -0
- data/test/test_html_template_pro.rb +177 -0
- data/test/test_path_like_variable_scope.rb +59 -0
- data/test/test_random.rb +21 -0
- data/test/test_realloc.rb +16 -0
- data/test/test_register.rb +25 -0
- data/test/test_tmplpro.rb +9 -0
- data/test/tests.rb +9 -0
- data/website/index.txt +57 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +159 -0
- data/website/template.html.erb +50 -0
- metadata +303 -0
@@ -0,0 +1,177 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: iso-8859-1 -*-
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'html/template/pro'
|
6
|
+
|
7
|
+
class TestHtmlTemplatePro < Test::Unit::TestCase
|
8
|
+
|
9
|
+
@@varset1 = {
|
10
|
+
:VAR1 => 'VAR1', :VAR2 => 'VAR2',
|
11
|
+
:VAR3 => 'VAR3', :VAR10 => 'VAR10',
|
12
|
+
}
|
13
|
+
|
14
|
+
@@varset2 = {
|
15
|
+
:STUFF1 => '\<>"; %FA' + "hidden:\r\012end",
|
16
|
+
:STUFF2 => 'Some"' + "' Txt'",
|
17
|
+
}
|
18
|
+
|
19
|
+
@@refset1 = {
|
20
|
+
:HASHREF0 => [],
|
21
|
+
:HASHREF2 => [{}, {}],
|
22
|
+
:HASHREF1 => [
|
23
|
+
{ :LOOPVAR1=>'LOOP1-VAR1',:LOOPVAR2=>'LOOP1-VAR2',
|
24
|
+
:LOOPVAR3=>'LOOP1-VAR3',:LOOPVAR10=>'LOOP1-VAR10'},
|
25
|
+
{ :LOOPVAR1=>'LOOP2-VAR1',:LOOPVAR2=>'LOOP2-VAR2',
|
26
|
+
:LOOPVAR3=>'LOOP2-VAR3',:LOOPVAR10=>'LOOP2-VAR10'},
|
27
|
+
{ :LOOPVAR1=>'LOOP3-VAR1',:LOOPVAR2=>'LOOP3-VAR2',
|
28
|
+
:LOOPVAR3=>'LOOP3-VAR3',:LOOPVAR10=>'LOOP3-VAR10'},
|
29
|
+
{ :LOOPVAR1=>'LOOP4-VAR1',:LOOPVAR2=>'LOOP4-VAR2',
|
30
|
+
:LOOPVAR3=>'LOOP4-VAR3',:LOOPVAR10=>'LOOP4-VAR10'},
|
31
|
+
],
|
32
|
+
}
|
33
|
+
|
34
|
+
@@outer = [{:TEST=>'1'},{:TEST=>'2'},{:TEST=>'3'}]
|
35
|
+
@@inner = [{:TST=>'A'},{:TST=>'B'}]
|
36
|
+
|
37
|
+
@@refset2 = { :INNER => @@inner, :OUTER => @@outer }
|
38
|
+
|
39
|
+
def test_tmplpro
|
40
|
+
test_tmpl_std('test_esc1', @@varset1, @@varset2)
|
41
|
+
test_tmpl_std('test_esc2', @@varset1, @@varset2)
|
42
|
+
test_tmpl_std('test_esc3', @@varset1, @@varset2)
|
43
|
+
test_tmpl_std('test_esc4', @@varset1, @@varset2)
|
44
|
+
test_tmpl_std('test_var1', @@varset1)
|
45
|
+
test_tmpl_std('test_var2', @@varset1)
|
46
|
+
test_tmpl_std('test_var3', @@varset1, @@varset2)
|
47
|
+
test_tmpl_std('test_if1', @@varset1)
|
48
|
+
test_tmpl_std('test_if2', @@varset1)
|
49
|
+
test_tmpl_std('test_if3', @@refset1)
|
50
|
+
test_tmpl_std('test_if4', @@varset1)
|
51
|
+
test_tmpl_std('test_if5', @@varset1)
|
52
|
+
test_tmpl_std('test_if7', @@varset1)
|
53
|
+
test_tmpl_std('test_include1', @@varset1)
|
54
|
+
test_tmpl('test_include2', { :max_include => 10 }, @@varset1)
|
55
|
+
test_tmpl_std('test_include3', @@varset1)
|
56
|
+
test_tmpl('test_include4', { :path => ['include/1', 'include/2'] });
|
57
|
+
test_tmpl('test_include5', {
|
58
|
+
:path => ['include/1', 'include/2'],
|
59
|
+
:search_path_on_include => 1,
|
60
|
+
});
|
61
|
+
test_tmpl_std('test_loop1', @@varset1, @@refset1)
|
62
|
+
test_tmpl_std('test_loop2', @@varset1, @@refset1)
|
63
|
+
test_tmpl_std('test_loop3', @@varset1, @@refset1)
|
64
|
+
test_tmpl_std('test_loop4', @@varset1, @@refset1)
|
65
|
+
test_tmpl_std('test_loop5', @@varset1, @@refset1)
|
66
|
+
test_tmpl('test_loop6', {
|
67
|
+
:loop_context_vars => true,
|
68
|
+
:global_vars => true,
|
69
|
+
}, @@refset2)
|
70
|
+
|
71
|
+
test_tmpl_std('include/2', { :LIST => [{ :TEST => 1 }, { :TEST => 2 }] });
|
72
|
+
test_tmpl('test_broken1', { :debug => -1 }, @@varset1, @@refset1);
|
73
|
+
|
74
|
+
assert(true)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_tmplpro_expr
|
78
|
+
|
79
|
+
HTML::Template::Pro.register_function(:registered_func) { |x| x }
|
80
|
+
HTML::Template::Pro.register_function(:hello_string) { 'hello!' }
|
81
|
+
HTML::Template::Pro.register_function(:arglist) { |*args| '[' + args.join('][') + ']' }
|
82
|
+
HTML::Template::Pro.register_function(:f1) { |*args| "F1: #{args.join(' ')}" }
|
83
|
+
HTML::Template::Pro.register_function(:f2) { |*args| "F2: #{args.join(' ')}" }
|
84
|
+
HTML::Template::Pro.register_function(:fUNDEF) { nil }
|
85
|
+
|
86
|
+
exprset1 = {
|
87
|
+
:ONE=>1, :TWO=>2, :THREE=>3, :ZERO=>0, :MINUSTEN=>-10,
|
88
|
+
:FILE=>'test_if1.tmpl', :TWENTY=>20, :FOURTY=>50,
|
89
|
+
}
|
90
|
+
|
91
|
+
brunoext = { :'FOO.BAR' => '<test passed>' }
|
92
|
+
|
93
|
+
refset1 = {
|
94
|
+
:HASHREF0 => [],
|
95
|
+
:HASHREF2 => [{},{}],
|
96
|
+
:HASHREF1 => [
|
97
|
+
{:LOOPVAR1=>'LOOP1-VAR1',:LOOPVAR2=>'LOOP1-VAR2',:LOOPVAR3=>'LOOP1-VAR3',:LOOPVAR10=>'LOOP1-VAR10'},
|
98
|
+
{:LOOPVAR1=>'LOOP2-VAR1',:LOOPVAR2=>'LOOP2-VAR2',:LOOPVAR3=>'LOOP2-VAR3',:LOOPVAR10=>'LOOP2-VAR10'},
|
99
|
+
{:LOOPVAR1=>'LOOP3-VAR1',:LOOPVAR2=>'LOOP3-VAR2',:LOOPVAR3=>'LOOP3-VAR3',:LOOPVAR10=>'LOOP3-VAR10'},
|
100
|
+
{:LOOPVAR1=>'LOOP4-VAR1',:LOOPVAR2=>'LOOP4-VAR2',:LOOPVAR3=>'LOOP4-VAR3',:LOOPVAR10=>'LOOP4-VAR10'},
|
101
|
+
]
|
102
|
+
}
|
103
|
+
|
104
|
+
test_tmpl_std('test_expr1', exprset1);
|
105
|
+
test_tmpl_std('test_expr2', exprset1);
|
106
|
+
test_tmpl_std('test_expr3', exprset1);
|
107
|
+
test_tmpl_std('test_expr4', brunoext);
|
108
|
+
test_tmpl_std('test_expr5', exprset1);
|
109
|
+
test_tmpl_std('test_expr6', exprset1);
|
110
|
+
test_tmpl_std('test_expr7', refset1);
|
111
|
+
test_tmpl_std('test_expr8', exprset1);
|
112
|
+
|
113
|
+
test_tmpl_expr('test_userfunc1', exprset1)
|
114
|
+
test_tmpl_expr('test_userfunc2', exprset1)
|
115
|
+
test_tmpl_expr('test_userfunc3', exprset1)
|
116
|
+
test_tmpl_expr('test_userfunc4', exprset1)
|
117
|
+
test_tmpl_expr('test_userfunc5', exprset1)
|
118
|
+
test_tmpl_expr('test_userfunc6', exprset1)
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def test_tmpl(file, option, *args)
|
125
|
+
params = args.inject({}) do |result, item|
|
126
|
+
result.update(item)
|
127
|
+
end
|
128
|
+
Dir.chdir 'templates-Pro'
|
129
|
+
tmpl = HTML::Template::Pro.new({ :filename => file + '.tmpl',
|
130
|
+
:debug => $DEBUG || 0 }.merge(option) )
|
131
|
+
tmpl.param(params)
|
132
|
+
dryrun(tmpl, file);
|
133
|
+
Dir.chdir '..'
|
134
|
+
end
|
135
|
+
|
136
|
+
@@case_ext = {
|
137
|
+
:loop_context_vars => true,
|
138
|
+
:case_sensitive => false,
|
139
|
+
}
|
140
|
+
|
141
|
+
@@case_int = {
|
142
|
+
:loop_context_vars => true,
|
143
|
+
:case_sensitive => true,
|
144
|
+
:tmpl_var_case => HTML::Template::Pro::ASK_NAME_UPPERCASE,
|
145
|
+
}
|
146
|
+
|
147
|
+
def test_tmpl_std(file, *args)
|
148
|
+
test_tmpl(file, @@case_ext, *args)
|
149
|
+
test_tmpl(file, @@case_int, *args)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_tmpl_expr(file, *args)
|
153
|
+
Dir.chdir 'templates-Pro'
|
154
|
+
tmpl = HTML::Template::Pro.new(:filename => file + '.tmpl',
|
155
|
+
:loop_context_vars => true,
|
156
|
+
:case_sensitive => true,
|
157
|
+
:tmpl_var_case => HTML::Template::Pro::ASK_NAME_UPPERCASE | HTML::Template::Pro::ASK_NAME_AS_IS,
|
158
|
+
:debug => $DEBUG || 0,
|
159
|
+
:functions => { :hello => lambda { |x| "hi, #{x}!" } }
|
160
|
+
)
|
161
|
+
tmpl.param(*args)
|
162
|
+
tmpl.register_function(:per_object_call) { |x| "#{x}-arg" }
|
163
|
+
tmpl.register_function(:perobjectcall2) { |x| "#{x}-arg"}
|
164
|
+
dryrun(tmpl, file)
|
165
|
+
Dir.chdir '..'
|
166
|
+
end
|
167
|
+
|
168
|
+
def dryrun(tmpl, file)
|
169
|
+
File.open("#{file}.raw", 'w') do |f|
|
170
|
+
tmpl.output(:print_to => f)
|
171
|
+
end
|
172
|
+
assert_equal(File.read("#{file}.out"), File.read("#{file}.raw"))
|
173
|
+
File.unlink("#{file}.raw")
|
174
|
+
output = tmpl.output;
|
175
|
+
assert_equal(File.read("#{file}.out"), output)
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'html/template/pro'
|
3
|
+
|
4
|
+
class TestPathLikeVariableScope < Test::Unit::TestCase
|
5
|
+
def test_path_like_variable_scope
|
6
|
+
|
7
|
+
template_text = <<'END'
|
8
|
+
<TMPL_LOOP NAME=class>
|
9
|
+
<TMPL_LOOP NAME=person>
|
10
|
+
<TMPL_VAR NAME="../teacher_name"> <!-- access to class.teacher_name -->
|
11
|
+
<TMPL_VAR NAME="name">
|
12
|
+
<TMPL_VAR NAME="age">
|
13
|
+
<TMPL_VAR NAME="/top_level_value"> <!-- access to top level value -->
|
14
|
+
<TMPL_VAR EXPR="${/top_level_value} * 5"> <!-- need ${} to use path_like_variable in EXPR -->
|
15
|
+
</TMPL_LOOP>
|
16
|
+
</TMPL_LOOP>
|
17
|
+
END
|
18
|
+
|
19
|
+
template = HTML::Template::Pro.new(:path_like_variable_scope => true,
|
20
|
+
:scalarref => template_text)
|
21
|
+
template.param(:top_level_value => "3",
|
22
|
+
:class => [
|
23
|
+
{
|
24
|
+
:teacher_name => "Adam",
|
25
|
+
:person => [
|
26
|
+
{
|
27
|
+
:name => "Jon",
|
28
|
+
:age => "20",
|
29
|
+
},
|
30
|
+
{
|
31
|
+
:name => "Bob",
|
32
|
+
:age => "21",
|
33
|
+
},
|
34
|
+
],
|
35
|
+
},
|
36
|
+
{
|
37
|
+
}
|
38
|
+
])
|
39
|
+
assert_equal(<<'END', template.output)
|
40
|
+
|
41
|
+
|
42
|
+
Adam <!-- access to class.teacher_name -->
|
43
|
+
Jon
|
44
|
+
20
|
45
|
+
3 <!-- access to top level value -->
|
46
|
+
15 <!-- need ${} to use path_like_variable in EXPR -->
|
47
|
+
|
48
|
+
Adam <!-- access to class.teacher_name -->
|
49
|
+
Bob
|
50
|
+
21
|
51
|
+
3 <!-- access to top level value -->
|
52
|
+
15 <!-- need ${} to use path_like_variable in EXPR -->
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
END
|
58
|
+
end
|
59
|
+
end
|
data/test/test_random.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'html/template/pro'
|
3
|
+
|
4
|
+
class TestRandom < Test::Unit::TestCase
|
5
|
+
def test_random
|
6
|
+
text = %{<TMPL_IF foo>YES<TMPL_ELSE>NO</TMPL_IF>}
|
7
|
+
|
8
|
+
template = HTML::Template::Pro.new(:scalarref => text)
|
9
|
+
template.param(:foo) do
|
10
|
+
rand(2).to_i == 0 ? false : true
|
11
|
+
end
|
12
|
+
before, changed = template.output, false
|
13
|
+
200.times do
|
14
|
+
r = template.output
|
15
|
+
changed = true if before != r
|
16
|
+
assert((r == 'YES' || r == 'NO'))
|
17
|
+
before = r
|
18
|
+
end
|
19
|
+
assert(changed, 'changed')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'html/template/pro'
|
3
|
+
|
4
|
+
class TestRealloc < Test::Unit::TestCase
|
5
|
+
def test_realloc
|
6
|
+
mult = 10
|
7
|
+
tests = 30
|
8
|
+
t = HTML::Template::Pro.new( :filename => 'templates-Pro/test_malloc.tmpl',
|
9
|
+
:debug=>0 )
|
10
|
+
25.step(25+tests*mult-1, mult) do |x|
|
11
|
+
txt = 'xxxxxxxxxx' * x
|
12
|
+
t.param(:text => txt)
|
13
|
+
assert_equal((txt +"\n"), t.output)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'html/template/pro'
|
3
|
+
|
4
|
+
class TestRegister < Test::Unit::TestCase
|
5
|
+
def test_register
|
6
|
+
HTML::Template::Expr.register_function(:directory_exists) { |dir| FileTest.directory? dir }
|
7
|
+
HTML::Template::Expr.register_function(:commify => lambda do |x|
|
8
|
+
x = x.to_s
|
9
|
+
1 while x.gsub!(/^([-+]?\d+)(\d{3})/, '\1,\2')
|
10
|
+
return x
|
11
|
+
end)
|
12
|
+
|
13
|
+
template = HTML::Template::Expr.new(:path => ['test/templates'],
|
14
|
+
:filename => 'register.tmpl')
|
15
|
+
output = template.output
|
16
|
+
assert_match(/^OK/, output, 'directory_exists()')
|
17
|
+
assert_match(/2,000/, output, 'comify')
|
18
|
+
|
19
|
+
begin
|
20
|
+
HTML::Template::Expr.register_function(:foo => 'bar');
|
21
|
+
rescue => e
|
22
|
+
assert_match(/must be kind_of Proc/, e.message, 'type check')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'test/test_basic'
|
3
|
+
require 'test/test_random'
|
4
|
+
require 'test/test_coderefs'
|
5
|
+
require 'test/test_path_like_variable_scope'
|
6
|
+
require 'test/test_realloc'
|
7
|
+
require 'test/test_register'
|
8
|
+
require 'test/test_html_template'
|
9
|
+
require 'test/test_html_template_pro'
|
data/test/tests.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/test_basic'
|
3
|
+
require 'test/test_random'
|
4
|
+
require 'test/test_coderefs'
|
5
|
+
require 'test/test_path_like_variable_scope'
|
6
|
+
require 'test/test_realloc'
|
7
|
+
require 'test/test_register'
|
8
|
+
require 'test/test_html_template'
|
9
|
+
require 'test/test_html_template_pro'
|
data/website/index.txt
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
h1. html-template-pro
|
2
|
+
|
3
|
+
|
4
|
+
h2. What
|
5
|
+
|
6
|
+
A Ruby port of HTML::Template::Pro (template engine originally written
|
7
|
+
in Perl and XS).
|
8
|
+
|
9
|
+
h2. Installing
|
10
|
+
|
11
|
+
<pre syntax="ruby">sudo gem install html-template-pro</pre>
|
12
|
+
|
13
|
+
h2. The basics
|
14
|
+
|
15
|
+
|
16
|
+
h2. Demonstration of usage
|
17
|
+
|
18
|
+
|
19
|
+
<% if rubyforge_project_id %>
|
20
|
+
|
21
|
+
* rubyforge: "http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>":http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>
|
22
|
+
|
23
|
+
<pre>git clone git://rubyforge.org/tmplpro.git</pre>
|
24
|
+
|
25
|
+
<% else %>
|
26
|
+
|
27
|
+
* rubyforge: MISSING IN ACTION
|
28
|
+
|
29
|
+
TODO - You can not created a RubyForge project, OR have not run <code>rubyforge config</code>
|
30
|
+
yet to refresh your local rubyforge data with this projects' id information.
|
31
|
+
|
32
|
+
When you do this, this message will magically disappear!
|
33
|
+
|
34
|
+
Or you can hack website/index.txt and make it all go away!!
|
35
|
+
|
36
|
+
<% end %>
|
37
|
+
|
38
|
+
* github: "http://github.com/tom-lpsd/ruby-html-template-pro/tree/master":http://github.com/tom-lpsd/ruby-html-template-pro/tree/master
|
39
|
+
|
40
|
+
<pre>git clone git://github.com/tom-lpsd/ruby-html-template-pro.git</pre>
|
41
|
+
|
42
|
+
|
43
|
+
h3. Build and test instructions
|
44
|
+
|
45
|
+
<pre>cd tmplpro
|
46
|
+
rake test
|
47
|
+
rake install_gem</pre>
|
48
|
+
|
49
|
+
|
50
|
+
h2. License
|
51
|
+
|
52
|
+
LGPL
|
53
|
+
|
54
|
+
h2. Contact
|
55
|
+
|
56
|
+
Comments are welcome. Send an email to "Tom Tsuruhara":mailto:tom.lpsd@gmail.com
|
57
|
+
|
@@ -0,0 +1,285 @@
|
|
1
|
+
|
2
|
+
/****************************************************************
|
3
|
+
* *
|
4
|
+
* curvyCorners *
|
5
|
+
* ------------ *
|
6
|
+
* *
|
7
|
+
* This script generates rounded corners for your divs. *
|
8
|
+
* *
|
9
|
+
* Version 1.2.9 *
|
10
|
+
* Copyright (c) 2006 Cameron Cooke *
|
11
|
+
* By: Cameron Cooke and Tim Hutchison. *
|
12
|
+
* *
|
13
|
+
* *
|
14
|
+
* Website: http://www.curvycorners.net *
|
15
|
+
* Email: info@totalinfinity.com *
|
16
|
+
* Forum: http://www.curvycorners.net/forum/ *
|
17
|
+
* *
|
18
|
+
* *
|
19
|
+
* This library is free software; you can redistribute *
|
20
|
+
* it and/or modify it under the terms of the GNU *
|
21
|
+
* Lesser General Public License as published by the *
|
22
|
+
* Free Software Foundation; either version 2.1 of the *
|
23
|
+
* License, or (at your option) any later version. *
|
24
|
+
* *
|
25
|
+
* This library is distributed in the hope that it will *
|
26
|
+
* be useful, but WITHOUT ANY WARRANTY; without even the *
|
27
|
+
* implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
28
|
+
* PARTICULAR PURPOSE. See the GNU Lesser General Public *
|
29
|
+
* License for more details. *
|
30
|
+
* *
|
31
|
+
* You should have received a copy of the GNU Lesser *
|
32
|
+
* General Public License along with this library; *
|
33
|
+
* Inc., 59 Temple Place, Suite 330, Boston, *
|
34
|
+
* MA 02111-1307 USA *
|
35
|
+
* *
|
36
|
+
****************************************************************/
|
37
|
+
|
38
|
+
var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1; var isMoz = document.implementation && document.implementation.createDocument; var isSafari = ((navigator.userAgent.toLowerCase().indexOf('safari')!=-1)&&(navigator.userAgent.toLowerCase().indexOf('mac')!=-1))?true:false; function curvyCorners()
|
39
|
+
{ if(typeof(arguments[0]) != "object") throw newCurvyError("First parameter of curvyCorners() must be an object."); if(typeof(arguments[1]) != "object" && typeof(arguments[1]) != "string") throw newCurvyError("Second parameter of curvyCorners() must be an object or a class name."); if(typeof(arguments[1]) == "string")
|
40
|
+
{ var startIndex = 0; var boxCol = getElementsByClass(arguments[1]);}
|
41
|
+
else
|
42
|
+
{ var startIndex = 1; var boxCol = arguments;}
|
43
|
+
var curvyCornersCol = new Array(); if(arguments[0].validTags)
|
44
|
+
var validElements = arguments[0].validTags; else
|
45
|
+
var validElements = ["div"]; for(var i = startIndex, j = boxCol.length; i < j; i++)
|
46
|
+
{ var currentTag = boxCol[i].tagName.toLowerCase(); if(inArray(validElements, currentTag) !== false)
|
47
|
+
{ curvyCornersCol[curvyCornersCol.length] = new curvyObject(arguments[0], boxCol[i]);}
|
48
|
+
}
|
49
|
+
this.objects = curvyCornersCol; this.applyCornersToAll = function()
|
50
|
+
{ for(var x = 0, k = this.objects.length; x < k; x++)
|
51
|
+
{ this.objects[x].applyCorners();}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
function curvyObject()
|
55
|
+
{ this.box = arguments[1]; this.settings = arguments[0]; this.topContainer = null; this.bottomContainer = null; this.masterCorners = new Array(); this.contentDIV = null; var boxHeight = get_style(this.box, "height", "height"); var boxWidth = get_style(this.box, "width", "width"); var borderWidth = get_style(this.box, "borderTopWidth", "border-top-width"); var borderColour = get_style(this.box, "borderTopColor", "border-top-color"); var boxColour = get_style(this.box, "backgroundColor", "background-color"); var backgroundImage = get_style(this.box, "backgroundImage", "background-image"); var boxPosition = get_style(this.box, "position", "position"); var boxPadding = get_style(this.box, "paddingTop", "padding-top"); this.boxHeight = parseInt(((boxHeight != "" && boxHeight != "auto" && boxHeight.indexOf("%") == -1)? boxHeight.substring(0, boxHeight.indexOf("px")) : this.box.scrollHeight)); this.boxWidth = parseInt(((boxWidth != "" && boxWidth != "auto" && boxWidth.indexOf("%") == -1)? boxWidth.substring(0, boxWidth.indexOf("px")) : this.box.scrollWidth)); this.borderWidth = parseInt(((borderWidth != "" && borderWidth.indexOf("px") !== -1)? borderWidth.slice(0, borderWidth.indexOf("px")) : 0)); this.boxColour = format_colour(boxColour); this.boxPadding = parseInt(((boxPadding != "" && boxPadding.indexOf("px") !== -1)? boxPadding.slice(0, boxPadding.indexOf("px")) : 0)); this.borderColour = format_colour(borderColour); this.borderString = this.borderWidth + "px" + " solid " + this.borderColour; this.backgroundImage = ((backgroundImage != "none")? backgroundImage : ""); this.boxContent = this.box.innerHTML; if(boxPosition != "absolute") this.box.style.position = "relative"; this.box.style.padding = "0px"; if(isIE && boxWidth == "auto" && boxHeight == "auto") this.box.style.width = "100%"; if(this.settings.autoPad == true && this.boxPadding > 0)
|
56
|
+
this.box.innerHTML = ""; this.applyCorners = function()
|
57
|
+
{ for(var t = 0; t < 2; t++)
|
58
|
+
{ switch(t)
|
59
|
+
{ case 0:
|
60
|
+
if(this.settings.tl || this.settings.tr)
|
61
|
+
{ var newMainContainer = document.createElement("DIV"); newMainContainer.style.width = "100%"; newMainContainer.style.fontSize = "1px"; newMainContainer.style.overflow = "hidden"; newMainContainer.style.position = "absolute"; newMainContainer.style.paddingLeft = this.borderWidth + "px"; newMainContainer.style.paddingRight = this.borderWidth + "px"; var topMaxRadius = Math.max(this.settings.tl ? this.settings.tl.radius : 0, this.settings.tr ? this.settings.tr.radius : 0); newMainContainer.style.height = topMaxRadius + "px"; newMainContainer.style.top = 0 - topMaxRadius + "px"; newMainContainer.style.left = 0 - this.borderWidth + "px"; this.topContainer = this.box.appendChild(newMainContainer);}
|
62
|
+
break; case 1:
|
63
|
+
if(this.settings.bl || this.settings.br)
|
64
|
+
{ var newMainContainer = document.createElement("DIV"); newMainContainer.style.width = "100%"; newMainContainer.style.fontSize = "1px"; newMainContainer.style.overflow = "hidden"; newMainContainer.style.position = "absolute"; newMainContainer.style.paddingLeft = this.borderWidth + "px"; newMainContainer.style.paddingRight = this.borderWidth + "px"; var botMaxRadius = Math.max(this.settings.bl ? this.settings.bl.radius : 0, this.settings.br ? this.settings.br.radius : 0); newMainContainer.style.height = botMaxRadius + "px"; newMainContainer.style.bottom = 0 - botMaxRadius + "px"; newMainContainer.style.left = 0 - this.borderWidth + "px"; this.bottomContainer = this.box.appendChild(newMainContainer);}
|
65
|
+
break;}
|
66
|
+
}
|
67
|
+
if(this.topContainer) this.box.style.borderTopWidth = "0px"; if(this.bottomContainer) this.box.style.borderBottomWidth = "0px"; var corners = ["tr", "tl", "br", "bl"]; for(var i in corners)
|
68
|
+
{ if(i > -1 < 4)
|
69
|
+
{ var cc = corners[i]; if(!this.settings[cc])
|
70
|
+
{ if(((cc == "tr" || cc == "tl") && this.topContainer != null) || ((cc == "br" || cc == "bl") && this.bottomContainer != null))
|
71
|
+
{ var newCorner = document.createElement("DIV"); newCorner.style.position = "relative"; newCorner.style.fontSize = "1px"; newCorner.style.overflow = "hidden"; if(this.backgroundImage == "")
|
72
|
+
newCorner.style.backgroundColor = this.boxColour; else
|
73
|
+
newCorner.style.backgroundImage = this.backgroundImage; switch(cc)
|
74
|
+
{ case "tl":
|
75
|
+
newCorner.style.height = topMaxRadius - this.borderWidth + "px"; newCorner.style.marginRight = this.settings.tr.radius - (this.borderWidth*2) + "px"; newCorner.style.borderLeft = this.borderString; newCorner.style.borderTop = this.borderString; newCorner.style.left = -this.borderWidth + "px"; break; case "tr":
|
76
|
+
newCorner.style.height = topMaxRadius - this.borderWidth + "px"; newCorner.style.marginLeft = this.settings.tl.radius - (this.borderWidth*2) + "px"; newCorner.style.borderRight = this.borderString; newCorner.style.borderTop = this.borderString; newCorner.style.backgroundPosition = "-" + (topMaxRadius + this.borderWidth) + "px 0px"; newCorner.style.left = this.borderWidth + "px"; break; case "bl":
|
77
|
+
newCorner.style.height = botMaxRadius - this.borderWidth + "px"; newCorner.style.marginRight = this.settings.br.radius - (this.borderWidth*2) + "px"; newCorner.style.borderLeft = this.borderString; newCorner.style.borderBottom = this.borderString; newCorner.style.left = -this.borderWidth + "px"; newCorner.style.backgroundPosition = "-" + (this.borderWidth) + "px -" + (this.boxHeight + (botMaxRadius + this.borderWidth)) + "px"; break; case "br":
|
78
|
+
newCorner.style.height = botMaxRadius - this.borderWidth + "px"; newCorner.style.marginLeft = this.settings.bl.radius - (this.borderWidth*2) + "px"; newCorner.style.borderRight = this.borderString; newCorner.style.borderBottom = this.borderString; newCorner.style.left = this.borderWidth + "px"
|
79
|
+
newCorner.style.backgroundPosition = "-" + (botMaxRadius + this.borderWidth) + "px -" + (this.boxHeight + (botMaxRadius + this.borderWidth)) + "px"; break;}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
else
|
83
|
+
{ if(this.masterCorners[this.settings[cc].radius])
|
84
|
+
{ var newCorner = this.masterCorners[this.settings[cc].radius].cloneNode(true);}
|
85
|
+
else
|
86
|
+
{ var newCorner = document.createElement("DIV"); newCorner.style.height = this.settings[cc].radius + "px"; newCorner.style.width = this.settings[cc].radius + "px"; newCorner.style.position = "absolute"; newCorner.style.fontSize = "1px"; newCorner.style.overflow = "hidden"; var borderRadius = parseInt(this.settings[cc].radius - this.borderWidth); for(var intx = 0, j = this.settings[cc].radius; intx < j; intx++)
|
87
|
+
{ if((intx +1) >= borderRadius)
|
88
|
+
var y1 = -1; else
|
89
|
+
var y1 = (Math.floor(Math.sqrt(Math.pow(borderRadius, 2) - Math.pow((intx+1), 2))) - 1); if(borderRadius != j)
|
90
|
+
{ if((intx) >= borderRadius)
|
91
|
+
var y2 = -1; else
|
92
|
+
var y2 = Math.ceil(Math.sqrt(Math.pow(borderRadius,2) - Math.pow(intx, 2))); if((intx+1) >= j)
|
93
|
+
var y3 = -1; else
|
94
|
+
var y3 = (Math.floor(Math.sqrt(Math.pow(j ,2) - Math.pow((intx+1), 2))) - 1);}
|
95
|
+
if((intx) >= j)
|
96
|
+
var y4 = -1; else
|
97
|
+
var y4 = Math.ceil(Math.sqrt(Math.pow(j ,2) - Math.pow(intx, 2))); if(y1 > -1) this.drawPixel(intx, 0, this.boxColour, 100, (y1+1), newCorner, -1, this.settings[cc].radius); if(borderRadius != j)
|
98
|
+
{ for(var inty = (y1 + 1); inty < y2; inty++)
|
99
|
+
{ if(this.settings.antiAlias)
|
100
|
+
{ if(this.backgroundImage != "")
|
101
|
+
{ var borderFract = (pixelFraction(intx, inty, borderRadius) * 100); if(borderFract < 30)
|
102
|
+
{ this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, 0, this.settings[cc].radius);}
|
103
|
+
else
|
104
|
+
{ this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, -1, this.settings[cc].radius);}
|
105
|
+
}
|
106
|
+
else
|
107
|
+
{ var pixelcolour = BlendColour(this.boxColour, this.borderColour, pixelFraction(intx, inty, borderRadius)); this.drawPixel(intx, inty, pixelcolour, 100, 1, newCorner, 0, this.settings[cc].radius, cc);}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
if(this.settings.antiAlias)
|
111
|
+
{ if(y3 >= y2)
|
112
|
+
{ if (y2 == -1) y2 = 0; this.drawPixel(intx, y2, this.borderColour, 100, (y3 - y2 + 1), newCorner, 0, 0);}
|
113
|
+
}
|
114
|
+
else
|
115
|
+
{ if(y3 >= y1)
|
116
|
+
{ this.drawPixel(intx, (y1 + 1), this.borderColour, 100, (y3 - y1), newCorner, 0, 0);}
|
117
|
+
}
|
118
|
+
var outsideColour = this.borderColour;}
|
119
|
+
else
|
120
|
+
{ var outsideColour = this.boxColour; var y3 = y1;}
|
121
|
+
if(this.settings.antiAlias)
|
122
|
+
{ for(var inty = (y3 + 1); inty < y4; inty++)
|
123
|
+
{ this.drawPixel(intx, inty, outsideColour, (pixelFraction(intx, inty , j) * 100), 1, newCorner, ((this.borderWidth > 0)? 0 : -1), this.settings[cc].radius);}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
this.masterCorners[this.settings[cc].radius] = newCorner.cloneNode(true);}
|
127
|
+
if(cc != "br")
|
128
|
+
{ for(var t = 0, k = newCorner.childNodes.length; t < k; t++)
|
129
|
+
{ var pixelBar = newCorner.childNodes[t]; var pixelBarTop = parseInt(pixelBar.style.top.substring(0, pixelBar.style.top.indexOf("px"))); var pixelBarLeft = parseInt(pixelBar.style.left.substring(0, pixelBar.style.left.indexOf("px"))); var pixelBarHeight = parseInt(pixelBar.style.height.substring(0, pixelBar.style.height.indexOf("px"))); if(cc == "tl" || cc == "bl"){ pixelBar.style.left = this.settings[cc].radius -pixelBarLeft -1 + "px";}
|
130
|
+
if(cc == "tr" || cc == "tl"){ pixelBar.style.top = this.settings[cc].radius -pixelBarHeight -pixelBarTop + "px";}
|
131
|
+
switch(cc)
|
132
|
+
{ case "tr":
|
133
|
+
pixelBar.style.backgroundPosition = "-" + Math.abs((this.boxWidth - this.settings[cc].radius + this.borderWidth) + pixelBarLeft) + "px -" + Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth) + "px"; break; case "tl":
|
134
|
+
pixelBar.style.backgroundPosition = "-" + Math.abs((this.settings[cc].radius -pixelBarLeft -1) - this.borderWidth) + "px -" + Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth) + "px"; break; case "bl":
|
135
|
+
pixelBar.style.backgroundPosition = "-" + Math.abs((this.settings[cc].radius -pixelBarLeft -1) - this.borderWidth) + "px -" + Math.abs((this.boxHeight + this.settings[cc].radius + pixelBarTop) -this.borderWidth) + "px"; break;}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
if(newCorner)
|
140
|
+
{ switch(cc)
|
141
|
+
{ case "tl":
|
142
|
+
if(newCorner.style.position == "absolute") newCorner.style.top = "0px"; if(newCorner.style.position == "absolute") newCorner.style.left = "0px"; if(this.topContainer) this.topContainer.appendChild(newCorner); break; case "tr":
|
143
|
+
if(newCorner.style.position == "absolute") newCorner.style.top = "0px"; if(newCorner.style.position == "absolute") newCorner.style.right = "0px"; if(this.topContainer) this.topContainer.appendChild(newCorner); break; case "bl":
|
144
|
+
if(newCorner.style.position == "absolute") newCorner.style.bottom = "0px"; if(newCorner.style.position == "absolute") newCorner.style.left = "0px"; if(this.bottomContainer) this.bottomContainer.appendChild(newCorner); break; case "br":
|
145
|
+
if(newCorner.style.position == "absolute") newCorner.style.bottom = "0px"; if(newCorner.style.position == "absolute") newCorner.style.right = "0px"; if(this.bottomContainer) this.bottomContainer.appendChild(newCorner); break;}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
var radiusDiff = new Array(); radiusDiff["t"] = Math.abs(this.settings.tl.radius - this.settings.tr.radius)
|
150
|
+
radiusDiff["b"] = Math.abs(this.settings.bl.radius - this.settings.br.radius); for(z in radiusDiff)
|
151
|
+
{ if(z == "t" || z == "b")
|
152
|
+
{ if(radiusDiff[z])
|
153
|
+
{ var smallerCornerType = ((this.settings[z + "l"].radius < this.settings[z + "r"].radius)? z +"l" : z +"r"); var newFiller = document.createElement("DIV"); newFiller.style.height = radiusDiff[z] + "px"; newFiller.style.width = this.settings[smallerCornerType].radius+ "px"
|
154
|
+
newFiller.style.position = "absolute"; newFiller.style.fontSize = "1px"; newFiller.style.overflow = "hidden"; newFiller.style.backgroundColor = this.boxColour; switch(smallerCornerType)
|
155
|
+
{ case "tl":
|
156
|
+
newFiller.style.bottom = "0px"; newFiller.style.left = "0px"; newFiller.style.borderLeft = this.borderString; this.topContainer.appendChild(newFiller); break; case "tr":
|
157
|
+
newFiller.style.bottom = "0px"; newFiller.style.right = "0px"; newFiller.style.borderRight = this.borderString; this.topContainer.appendChild(newFiller); break; case "bl":
|
158
|
+
newFiller.style.top = "0px"; newFiller.style.left = "0px"; newFiller.style.borderLeft = this.borderString; this.bottomContainer.appendChild(newFiller); break; case "br":
|
159
|
+
newFiller.style.top = "0px"; newFiller.style.right = "0px"; newFiller.style.borderRight = this.borderString; this.bottomContainer.appendChild(newFiller); break;}
|
160
|
+
}
|
161
|
+
var newFillerBar = document.createElement("DIV"); newFillerBar.style.position = "relative"; newFillerBar.style.fontSize = "1px"; newFillerBar.style.overflow = "hidden"; newFillerBar.style.backgroundColor = this.boxColour; newFillerBar.style.backgroundImage = this.backgroundImage; switch(z)
|
162
|
+
{ case "t":
|
163
|
+
if(this.topContainer)
|
164
|
+
{ if(this.settings.tl.radius && this.settings.tr.radius)
|
165
|
+
{ newFillerBar.style.height = topMaxRadius - this.borderWidth + "px"; newFillerBar.style.marginLeft = this.settings.tl.radius - this.borderWidth + "px"; newFillerBar.style.marginRight = this.settings.tr.radius - this.borderWidth + "px"; newFillerBar.style.borderTop = this.borderString; if(this.backgroundImage != "")
|
166
|
+
newFillerBar.style.backgroundPosition = "-" + (topMaxRadius + this.borderWidth) + "px 0px"; this.topContainer.appendChild(newFillerBar);}
|
167
|
+
this.box.style.backgroundPosition = "0px -" + (topMaxRadius - this.borderWidth) + "px";}
|
168
|
+
break; case "b":
|
169
|
+
if(this.bottomContainer)
|
170
|
+
{ if(this.settings.bl.radius && this.settings.br.radius)
|
171
|
+
{ newFillerBar.style.height = botMaxRadius - this.borderWidth + "px"; newFillerBar.style.marginLeft = this.settings.bl.radius - this.borderWidth + "px"; newFillerBar.style.marginRight = this.settings.br.radius - this.borderWidth + "px"; newFillerBar.style.borderBottom = this.borderString; if(this.backgroundImage != "")
|
172
|
+
newFillerBar.style.backgroundPosition = "-" + (botMaxRadius + this.borderWidth) + "px -" + (this.boxHeight + (topMaxRadius + this.borderWidth)) + "px"; this.bottomContainer.appendChild(newFillerBar);}
|
173
|
+
}
|
174
|
+
break;}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
if(this.settings.autoPad == true && this.boxPadding > 0)
|
178
|
+
{ var contentContainer = document.createElement("DIV"); contentContainer.style.position = "relative"; contentContainer.innerHTML = this.boxContent; contentContainer.className = "autoPadDiv"; var topPadding = Math.abs(topMaxRadius - this.boxPadding); var botPadding = Math.abs(botMaxRadius - this.boxPadding); if(topMaxRadius < this.boxPadding)
|
179
|
+
contentContainer.style.paddingTop = topPadding + "px"; if(botMaxRadius < this.boxPadding)
|
180
|
+
contentContainer.style.paddingBottom = botMaxRadius + "px"; contentContainer.style.paddingLeft = this.boxPadding + "px"; contentContainer.style.paddingRight = this.boxPadding + "px"; this.contentDIV = this.box.appendChild(contentContainer);}
|
181
|
+
}
|
182
|
+
this.drawPixel = function(intx, inty, colour, transAmount, height, newCorner, image, cornerRadius)
|
183
|
+
{ var pixel = document.createElement("DIV"); pixel.style.height = height + "px"; pixel.style.width = "1px"; pixel.style.position = "absolute"; pixel.style.fontSize = "1px"; pixel.style.overflow = "hidden"; var topMaxRadius = Math.max(this.settings["tr"].radius, this.settings["tl"].radius); if(image == -1 && this.backgroundImage != "")
|
184
|
+
{ pixel.style.backgroundImage = this.backgroundImage; pixel.style.backgroundPosition = "-" + (this.boxWidth - (cornerRadius - intx) + this.borderWidth) + "px -" + ((this.boxHeight + topMaxRadius + inty) -this.borderWidth) + "px";}
|
185
|
+
else
|
186
|
+
{ pixel.style.backgroundColor = colour;}
|
187
|
+
if (transAmount != 100)
|
188
|
+
setOpacity(pixel, transAmount); pixel.style.top = inty + "px"; pixel.style.left = intx + "px"; newCorner.appendChild(pixel);}
|
189
|
+
}
|
190
|
+
function insertAfter(parent, node, referenceNode)
|
191
|
+
{ parent.insertBefore(node, referenceNode.nextSibling);}
|
192
|
+
function BlendColour(Col1, Col2, Col1Fraction)
|
193
|
+
{ var red1 = parseInt(Col1.substr(1,2),16); var green1 = parseInt(Col1.substr(3,2),16); var blue1 = parseInt(Col1.substr(5,2),16); var red2 = parseInt(Col2.substr(1,2),16); var green2 = parseInt(Col2.substr(3,2),16); var blue2 = parseInt(Col2.substr(5,2),16); if(Col1Fraction > 1 || Col1Fraction < 0) Col1Fraction = 1; var endRed = Math.round((red1 * Col1Fraction) + (red2 * (1 - Col1Fraction))); if(endRed > 255) endRed = 255; if(endRed < 0) endRed = 0; var endGreen = Math.round((green1 * Col1Fraction) + (green2 * (1 - Col1Fraction))); if(endGreen > 255) endGreen = 255; if(endGreen < 0) endGreen = 0; var endBlue = Math.round((blue1 * Col1Fraction) + (blue2 * (1 - Col1Fraction))); if(endBlue > 255) endBlue = 255; if(endBlue < 0) endBlue = 0; return "#" + IntToHex(endRed)+ IntToHex(endGreen)+ IntToHex(endBlue);}
|
194
|
+
function IntToHex(strNum)
|
195
|
+
{ base = strNum / 16; rem = strNum % 16; base = base - (rem / 16); baseS = MakeHex(base); remS = MakeHex(rem); return baseS + '' + remS;}
|
196
|
+
function MakeHex(x)
|
197
|
+
{ if((x >= 0) && (x <= 9))
|
198
|
+
{ return x;}
|
199
|
+
else
|
200
|
+
{ switch(x)
|
201
|
+
{ case 10: return "A"; case 11: return "B"; case 12: return "C"; case 13: return "D"; case 14: return "E"; case 15: return "F";}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
function pixelFraction(x, y, r)
|
205
|
+
{ var pixelfraction = 0; var xvalues = new Array(1); var yvalues = new Array(1); var point = 0; var whatsides = ""; var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(x,2))); if ((intersect >= y) && (intersect < (y+1)))
|
206
|
+
{ whatsides = "Left"; xvalues[point] = 0; yvalues[point] = intersect - y; point = point + 1;}
|
207
|
+
var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(y+1,2))); if ((intersect >= x) && (intersect < (x+1)))
|
208
|
+
{ whatsides = whatsides + "Top"; xvalues[point] = intersect - x; yvalues[point] = 1; point = point + 1;}
|
209
|
+
var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(x+1,2))); if ((intersect >= y) && (intersect < (y+1)))
|
210
|
+
{ whatsides = whatsides + "Right"; xvalues[point] = 1; yvalues[point] = intersect - y; point = point + 1;}
|
211
|
+
var intersect = Math.sqrt((Math.pow(r,2) - Math.pow(y,2))); if ((intersect >= x) && (intersect < (x+1)))
|
212
|
+
{ whatsides = whatsides + "Bottom"; xvalues[point] = intersect - x; yvalues[point] = 0;}
|
213
|
+
switch (whatsides)
|
214
|
+
{ case "LeftRight":
|
215
|
+
pixelfraction = Math.min(yvalues[0],yvalues[1]) + ((Math.max(yvalues[0],yvalues[1]) - Math.min(yvalues[0],yvalues[1]))/2); break; case "TopRight":
|
216
|
+
pixelfraction = 1-(((1-xvalues[0])*(1-yvalues[1]))/2); break; case "TopBottom":
|
217
|
+
pixelfraction = Math.min(xvalues[0],xvalues[1]) + ((Math.max(xvalues[0],xvalues[1]) - Math.min(xvalues[0],xvalues[1]))/2); break; case "LeftBottom":
|
218
|
+
pixelfraction = (yvalues[0]*xvalues[1])/2; break; default:
|
219
|
+
pixelfraction = 1;}
|
220
|
+
return pixelfraction;}
|
221
|
+
function rgb2Hex(rgbColour)
|
222
|
+
{ try{ var rgbArray = rgb2Array(rgbColour); var red = parseInt(rgbArray[0]); var green = parseInt(rgbArray[1]); var blue = parseInt(rgbArray[2]); var hexColour = "#" + IntToHex(red) + IntToHex(green) + IntToHex(blue);}
|
223
|
+
catch(e){ alert("There was an error converting the RGB value to Hexadecimal in function rgb2Hex");}
|
224
|
+
return hexColour;}
|
225
|
+
function rgb2Array(rgbColour)
|
226
|
+
{ var rgbValues = rgbColour.substring(4, rgbColour.indexOf(")")); var rgbArray = rgbValues.split(", "); return rgbArray;}
|
227
|
+
function setOpacity(obj, opacity)
|
228
|
+
{ opacity = (opacity == 100)?99.999:opacity; if(isSafari && obj.tagName != "IFRAME")
|
229
|
+
{ var rgbArray = rgb2Array(obj.style.backgroundColor); var red = parseInt(rgbArray[0]); var green = parseInt(rgbArray[1]); var blue = parseInt(rgbArray[2]); obj.style.backgroundColor = "rgba(" + red + ", " + green + ", " + blue + ", " + opacity/100 + ")";}
|
230
|
+
else if(typeof(obj.style.opacity) != "undefined")
|
231
|
+
{ obj.style.opacity = opacity/100;}
|
232
|
+
else if(typeof(obj.style.MozOpacity) != "undefined")
|
233
|
+
{ obj.style.MozOpacity = opacity/100;}
|
234
|
+
else if(typeof(obj.style.filter) != "undefined")
|
235
|
+
{ obj.style.filter = "alpha(opacity:" + opacity + ")";}
|
236
|
+
else if(typeof(obj.style.KHTMLOpacity) != "undefined")
|
237
|
+
{ obj.style.KHTMLOpacity = opacity/100;}
|
238
|
+
}
|
239
|
+
function inArray(array, value)
|
240
|
+
{ for(var i = 0; i < array.length; i++){ if (array[i] === value) return i;}
|
241
|
+
return false;}
|
242
|
+
function inArrayKey(array, value)
|
243
|
+
{ for(key in array){ if(key === value) return true;}
|
244
|
+
return false;}
|
245
|
+
function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true;}
|
246
|
+
else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r;}
|
247
|
+
else { elm['on' + evType] = fn;}
|
248
|
+
}
|
249
|
+
function removeEvent(obj, evType, fn, useCapture){ if (obj.removeEventListener){ obj.removeEventListener(evType, fn, useCapture); return true;} else if (obj.detachEvent){ var r = obj.detachEvent("on"+evType, fn); return r;} else { alert("Handler could not be removed");}
|
250
|
+
}
|
251
|
+
function format_colour(colour)
|
252
|
+
{ var returnColour = "#ffffff"; if(colour != "" && colour != "transparent")
|
253
|
+
{ if(colour.substr(0, 3) == "rgb")
|
254
|
+
{ returnColour = rgb2Hex(colour);}
|
255
|
+
else if(colour.length == 4)
|
256
|
+
{ returnColour = "#" + colour.substring(1, 2) + colour.substring(1, 2) + colour.substring(2, 3) + colour.substring(2, 3) + colour.substring(3, 4) + colour.substring(3, 4);}
|
257
|
+
else
|
258
|
+
{ returnColour = colour;}
|
259
|
+
}
|
260
|
+
return returnColour;}
|
261
|
+
function get_style(obj, property, propertyNS)
|
262
|
+
{ try
|
263
|
+
{ if(obj.currentStyle)
|
264
|
+
{ var returnVal = eval("obj.currentStyle." + property);}
|
265
|
+
else
|
266
|
+
{ if(isSafari && obj.style.display == "none")
|
267
|
+
{ obj.style.display = ""; var wasHidden = true;}
|
268
|
+
var returnVal = document.defaultView.getComputedStyle(obj, '').getPropertyValue(propertyNS); if(isSafari && wasHidden)
|
269
|
+
{ obj.style.display = "none";}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
catch(e)
|
273
|
+
{ }
|
274
|
+
return returnVal;}
|
275
|
+
function getElementsByClass(searchClass, node, tag)
|
276
|
+
{ var classElements = new Array(); if(node == null)
|
277
|
+
node = document; if(tag == null)
|
278
|
+
tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)"); for (i = 0, j = 0; i < elsLen; i++)
|
279
|
+
{ if(pattern.test(els[i].className))
|
280
|
+
{ classElements[j] = els[i]; j++;}
|
281
|
+
}
|
282
|
+
return classElements;}
|
283
|
+
function newCurvyError(errorMessage)
|
284
|
+
{ return new Error("curvyCorners Error:\n" + errorMessage)
|
285
|
+
}
|