html-template-pro 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +44 -45
  3. data/README.rdoc +36 -11
  4. data/Rakefile +6 -1
  5. data/ext/html/template/{internal/Pro.xs → Pro.xs} +0 -0
  6. data/ext/html/template/{internal/builtin_findfile.inc → builtin_findfile.inc} +0 -0
  7. data/ext/html/template/{internal/calc.h → calc.h} +0 -0
  8. data/ext/html/template/{internal/calc.inc → calc.inc} +0 -0
  9. data/ext/html/template/{internal/callback_stubs.inc → callback_stubs.inc} +0 -0
  10. data/ext/html/template/{internal/expr.c → expr.c} +2 -2
  11. data/ext/html/template/{internal/expr.y → expr.y} +1 -1
  12. data/ext/html/template/{internal/expr_iface.c → expr_iface.c} +0 -0
  13. data/ext/html/template/{internal/exprpstr.h → exprpstr.h} +0 -0
  14. data/ext/html/template/{internal/exprpstr.inc → exprpstr.inc} +0 -0
  15. data/ext/html/template/{internal/exprtool.h → exprtool.h} +0 -0
  16. data/ext/html/template/{internal/exprtool.inc → exprtool.inc} +0 -0
  17. data/ext/html/template/{internal/exprtype.h → exprtype.h} +0 -0
  18. data/ext/html/template/{internal/exprval.h → exprval.h} +0 -0
  19. data/ext/html/template/{internal/extconf.rb → extconf.rb} +0 -0
  20. data/ext/html/template/{internal/internal.c → internal.c} +2 -2
  21. data/ext/html/template/{internal/loadfile.h → loadfile.h} +0 -0
  22. data/ext/html/template/{internal/loadfile.inc → loadfile.inc} +0 -0
  23. data/ext/html/template/{internal/pabidecl.h → pabidecl.h} +0 -0
  24. data/ext/html/template/{internal/pabstract.h → pabstract.h} +0 -0
  25. data/ext/html/template/{internal/parse_expr.h → parse_expr.h} +0 -0
  26. data/ext/html/template/{internal/pbuffer.c → pbuffer.c} +0 -0
  27. data/ext/html/template/{internal/pbuffer.h → pbuffer.h} +0 -0
  28. data/ext/html/template/{internal/pmiscdef.h → pmiscdef.h} +0 -0
  29. data/ext/html/template/{internal/pparam.h → pparam.h} +0 -0
  30. data/ext/html/template/{internal/ppport.h → ppport.h} +0 -0
  31. data/ext/html/template/{internal/procore.c → procore.c} +0 -0
  32. data/ext/html/template/{internal/procore.h → procore.h} +0 -0
  33. data/ext/html/template/{internal/proparam.c → proparam.c} +0 -0
  34. data/ext/html/template/{internal/proparam.h → proparam.h} +0 -0
  35. data/ext/html/template/{internal/proscope.h → proscope.h} +0 -0
  36. data/ext/html/template/{internal/proscope.inc → proscope.inc} +0 -0
  37. data/ext/html/template/{internal/prostate.h → prostate.h} +0 -0
  38. data/ext/html/template/{internal/prostate.inc → prostate.inc} +0 -0
  39. data/ext/html/template/{internal/provalue.h → provalue.h} +0 -0
  40. data/ext/html/template/{internal/pstring.h → pstring.h} +0 -0
  41. data/ext/html/template/{internal/pstrutils.h → pstrutils.h} +0 -0
  42. data/ext/html/template/{internal/pstrutils.inc → pstrutils.inc} +0 -0
  43. data/ext/html/template/{internal/tagstack.h → tagstack.h} +0 -0
  44. data/ext/html/template/{internal/tagstack.inc → tagstack.inc} +0 -0
  45. data/ext/html/template/{internal/tmpllog.c → tmpllog.c} +0 -0
  46. data/ext/html/template/{internal/tmpllog.h → tmpllog.h} +0 -0
  47. data/ext/html/template/{internal/tmplpro.h → tmplpro.h} +0 -0
  48. data/ext/html/template/{internal/tmplpro_version.c → tmplpro_version.c} +0 -0
  49. data/lib/html/template/pro.rb +265 -18
  50. data/tasks/extconf/tmplpro.rake +1 -1
  51. data/website/index.txt +37 -9
  52. metadata +56 -53
  53. data/test/test_html_template_internal_extn.rb +0 -10
@@ -1,3 +1,7 @@
1
+ === 0.0.3 2009-10-03
2
+
3
+ * Add documentations.
4
+
1
5
  === 0.0.1 2009-09-29
2
6
 
3
7
  * 1 major enhancement:
@@ -7,50 +7,50 @@ README.rdoc
7
7
  Rakefile
8
8
  benchmark.rb
9
9
  config/website.yml
10
- ext/html/template/internal/Pro.xs
11
- ext/html/template/internal/builtin_findfile.inc
12
- ext/html/template/internal/calc.h
13
- ext/html/template/internal/calc.inc
14
- ext/html/template/internal/callback_stubs.inc
15
- ext/html/template/internal/expr.c
16
- ext/html/template/internal/expr.y
17
- ext/html/template/internal/expr_iface.c
18
- ext/html/template/internal/exprpstr.h
19
- ext/html/template/internal/exprpstr.inc
20
- ext/html/template/internal/exprtool.h
21
- ext/html/template/internal/exprtool.inc
22
- ext/html/template/internal/exprtype.h
23
- ext/html/template/internal/exprval.h
24
- ext/html/template/internal/extconf.rb
25
- ext/html/template/internal/internal.c
26
- ext/html/template/internal/loadfile.h
27
- ext/html/template/internal/loadfile.inc
28
- ext/html/template/internal/pabidecl.h
29
- ext/html/template/internal/pabstract.h
30
- ext/html/template/internal/parse_expr.h
31
- ext/html/template/internal/pbuffer.c
32
- ext/html/template/internal/pbuffer.h
33
- ext/html/template/internal/pmiscdef.h
34
- ext/html/template/internal/pparam.h
35
- ext/html/template/internal/ppport.h
36
- ext/html/template/internal/procore.c
37
- ext/html/template/internal/procore.h
38
- ext/html/template/internal/proparam.c
39
- ext/html/template/internal/proparam.h
40
- ext/html/template/internal/proscope.h
41
- ext/html/template/internal/proscope.inc
42
- ext/html/template/internal/prostate.h
43
- ext/html/template/internal/prostate.inc
44
- ext/html/template/internal/provalue.h
45
- ext/html/template/internal/pstring.h
46
- ext/html/template/internal/pstrutils.h
47
- ext/html/template/internal/pstrutils.inc
48
- ext/html/template/internal/tagstack.h
49
- ext/html/template/internal/tagstack.inc
50
- ext/html/template/internal/tmpllog.c
51
- ext/html/template/internal/tmpllog.h
52
- ext/html/template/internal/tmplpro.h
53
- ext/html/template/internal/tmplpro_version.c
10
+ ext/html/template/Pro.xs
11
+ ext/html/template/builtin_findfile.inc
12
+ ext/html/template/calc.h
13
+ ext/html/template/calc.inc
14
+ ext/html/template/callback_stubs.inc
15
+ ext/html/template/expr.c
16
+ ext/html/template/expr.y
17
+ ext/html/template/expr_iface.c
18
+ ext/html/template/exprpstr.h
19
+ ext/html/template/exprpstr.inc
20
+ ext/html/template/exprtool.h
21
+ ext/html/template/exprtool.inc
22
+ ext/html/template/exprtype.h
23
+ ext/html/template/exprval.h
24
+ ext/html/template/extconf.rb
25
+ ext/html/template/internal.c
26
+ ext/html/template/loadfile.h
27
+ ext/html/template/loadfile.inc
28
+ ext/html/template/pabidecl.h
29
+ ext/html/template/pabstract.h
30
+ ext/html/template/parse_expr.h
31
+ ext/html/template/pbuffer.c
32
+ ext/html/template/pbuffer.h
33
+ ext/html/template/pmiscdef.h
34
+ ext/html/template/pparam.h
35
+ ext/html/template/ppport.h
36
+ ext/html/template/procore.c
37
+ ext/html/template/procore.h
38
+ ext/html/template/proparam.c
39
+ ext/html/template/proparam.h
40
+ ext/html/template/proscope.h
41
+ ext/html/template/proscope.inc
42
+ ext/html/template/prostate.h
43
+ ext/html/template/prostate.inc
44
+ ext/html/template/provalue.h
45
+ ext/html/template/pstring.h
46
+ ext/html/template/pstrutils.h
47
+ ext/html/template/pstrutils.inc
48
+ ext/html/template/tagstack.h
49
+ ext/html/template/tagstack.inc
50
+ ext/html/template/tmpllog.c
51
+ ext/html/template/tmpllog.h
52
+ ext/html/template/tmplpro.h
53
+ ext/html/template/tmplpro_version.c
54
54
  lib/html/template/pro.rb
55
55
  script/console
56
56
  script/destroy
@@ -207,7 +207,6 @@ test/test_coderefs.rb
207
207
  test/test_complex.rb
208
208
  test/test_helper.rb
209
209
  test/test_html_template.rb
210
- test/test_html_template_internal_extn.rb
211
210
  test/test_html_template_pro.rb
212
211
  test/test_path_like_variable_scope.rb
213
212
  test/test_random.rb
@@ -1,16 +1,16 @@
1
- = tmplpro
1
+ = html-template-pro
2
2
 
3
3
  * http://github.com/tom-lpsd/ruby-html-template-pro
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- A Ruby port of HTML::Template::Pro (template engine originally written
8
- in Perl and XS).
7
+ A Ruby port of `HTML::Template::Pro'. `HTML::Template::Pro' is
8
+ template engine originally written in Perl and XS. It's so fast
9
+ because of its C based implementation. Its syntax is very simple.
10
+ This results clearly separation of application logic and its view.
9
11
 
10
- == FEATURES/PROBLEMS:
11
-
12
- * Fast. (Main part is written in C.)
13
- * Simple. (It avoids mixing up complex logic in View.)
12
+ Template syntax complies with original perl module's syntax.
13
+ Please see, HTML::Template::SYNTAX[http://search.cpan.org/~viy/HTML-Template-Pro-0.92/lib/HTML/Template/SYNTAX.pod#SYNOPSIS].
14
14
 
15
15
  == SYNOPSIS:
16
16
 
@@ -38,15 +38,40 @@ in Perl and XS).
38
38
  </body>
39
39
  </html>
40
40
 
41
-
42
41
  == REQUIREMENTS:
43
42
 
44
- * C99 C compiler.
43
+ * C99 compiler.
44
+ * ruby > 1.9.
45
45
 
46
46
  == INSTALL:
47
47
 
48
48
  * sudo gem install html-template-pro
49
49
 
50
- == LICENSE:
50
+ == SEE ALSO:
51
+
52
+ * Original perl module
53
+ HTML::Template::Pro[http://search.cpan.org/~viy/HTML-Template-Pro-0.92/]
54
+
55
+ == WEBSITE:
56
+
57
+ * http://tmplpro.rubyforge.org/
58
+
59
+ == AUTHOR:
60
+
61
+ Tom Tsuruhara <tom.lpsd@gmail.com>
62
+
63
+ Original perl module
64
+ HTML::Template::Pro[http://search.cpan.org/~viy/HTML-Template-Pro-0.92/]
65
+ (and most of this package's C code) is written by I. Vlasenko
66
+ <viy@altlinux.org>. Thanks to him for his great work.
67
+
68
+ == COPYRIGHT AND LICENSE:
69
+
70
+ Copyright (C) 2009 by Tom Tsuruhara.
71
+ Most of C codes (except internal.c) are
72
+ Copyright (C) 2005-2009 by I. Yu. Vlasenko.
51
73
 
52
- LGPL
74
+ This library is free software; you can redistribute it and/or modify
75
+ it under the same terms of the GNU Lesser General Public License as
76
+ published by the Free Software Foundation; either version 2 of the
77
+ License, or (at your option) any later version.
data/Rakefile CHANGED
@@ -5,13 +5,18 @@ require 'fileutils'
5
5
 
6
6
  Hoe.plugin :newgem
7
7
  Hoe.plugin :website
8
+ Hoe.add_include_dirs 'ext/html/template'
8
9
 
9
10
  $hoe = Hoe.spec 'html-template-pro' do
10
11
  self.developer 'Tsuruhara Tom', 'tom.lpsd@gmail.com'
11
12
  self.rubyforge_name = 'tmplpro'
12
- self.version = "0.0.2"
13
+ self.version = "0.0.3"
13
14
  self.summary = 'A Ruby port of HTML::Template::Pro'
14
15
  self.extra_rdoc_files = ['README.rdoc']
16
+
17
+ clean_globs.push('ext/html/template/*.o')
18
+
19
+ spec_extras[:required_ruby_version] = Gem::Requirement.new '> 1.9.0'
15
20
  end
16
21
 
17
22
  require 'newgem/tasks'
@@ -241,7 +241,7 @@ typedef short int yytype_int16;
241
241
  #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
242
242
 
243
243
  #ifndef YY_
244
- # if YYENABLE_NLS
244
+ # if defined YYENABLE_NLS && YYENABLE_NLS
245
245
  # if ENABLE_NLS
246
246
  # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
247
247
  # define YY_(msgid) dgettext ("bison-runtime", msgid)
@@ -762,7 +762,7 @@ while (YYID (0))
762
762
  we won't break user code: when these are the locations we know. */
763
763
 
764
764
  #ifndef YY_LOCATION_PRINT
765
- # if YYLTYPE_IS_TRIVIAL
765
+ # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
766
766
  # define YY_LOCATION_PRINT(File, Loc) \
767
767
  fprintf (File, "%d.%d-%d.%d", \
768
768
  (Loc).first_line, (Loc).first_column, \
@@ -188,7 +188,7 @@ numEXP: NUM { $$ = $1; }
188
188
  ;
189
189
 
190
190
  arglist: EXTFUNC '(' numEXP {
191
- $1.arglist=state->param->InitExprArglistFuncPtr(state->param->expr_func_map);
191
+ $1.arglist=state->param->InitExprArglistFuncPtr(state->param->ext_calluserfunc_state);
192
192
  pusharg_expr_userfunc(exprobj,state->param,$1,$3);
193
193
  $$ = $1;
194
194
  }
@@ -413,7 +413,7 @@ static void setup_internal(VALUE self)
413
413
  rb_ivar_set(self, rb_intern("@internal_expr_results"), rb_ary_new());
414
414
  }
415
415
 
416
- static VALUE exec_tmpl(VALUE self, VALUE output)
416
+ static VALUE exec_tmpl(VALUE module, VALUE self, VALUE output)
417
417
  {
418
418
  writer_functype writer;
419
419
  struct tmplpro_param* proparam;
@@ -444,6 +444,6 @@ void Init_internal(void)
444
444
  mHtml = rb_define_module("HTML");
445
445
  mHtmlTemplate = rb_define_module_under(mHtml, "Template");
446
446
  mHtmlTemplateInternal = rb_define_module_under(mHtmlTemplate, "Internal");
447
- rb_define_module_function(mHtmlTemplateInternal, "exec_tmpl", &exec_tmpl, 1);
447
+ rb_define_module_function(mHtmlTemplateInternal, "exec_tmpl", &exec_tmpl, 2);
448
448
  cHtmlTemplateInternalState = rb_define_class_under(mHtmlTemplateInternal, "State", rb_cObject);
449
449
  }
@@ -1,35 +1,45 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'html/template/internal'
2
3
 
3
- module HTML
4
- module Template
4
+ module HTML # :nodoc:
5
+ module Template # :nodoc:
5
6
 
6
- def Internal.register_functions_impl(registory, func_spec, &block)
7
- if block && func_spec.kind_of?(Symbol)
8
- registory[func_spec] = block
9
- elsif func_spec.kind_of? Hash
10
- unless func_spec.values.all?{|e| e.kind_of? Proc}
11
- raise ArgumentError, "functions must be kind_of Proc"
7
+ module Internal # :nodoc:
8
+
9
+ class State # :nodoc:
10
+ # supress documentation
11
+ end
12
+
13
+ module_function
14
+
15
+ def register_functions_impl(registory, func_spec, &block) # :nodoc:
16
+ if block && func_spec.kind_of?(Symbol)
17
+ registory[func_spec] = block
18
+ elsif func_spec.kind_of? Hash
19
+ unless func_spec.values.all?{|e| e.kind_of? Proc}
20
+ raise ArgumentError, "functions must be kind_of Proc"
21
+ end
22
+ registory.update(func_spec)
23
+ else
24
+ raise ArgumentError, "first argument must be symbol or hash contains functions"
12
25
  end
13
- registory.update(func_spec)
14
- else
15
- raise ArgumentError, "first argument must be symbol or hash contains functions"
16
26
  end
17
27
  end
18
28
 
19
29
  class Pro
20
30
 
21
- VERSION = "0.0.2"
22
-
23
- include HTML::Template::Internal
24
-
25
- INPUTS = [:filename, :filehandle, :arrayref, :scalarref, :source]
31
+ VERSION = "0.0.3"
26
32
 
33
+ # :stopdoc:
27
34
  ASK_NAME_DEFAULT = 0
28
35
  ASK_NAME_AS_IS = 1
29
36
  ASK_NAME_LOWERCASE = 2
30
37
  ASK_NAME_UPPERCASE = 4
31
38
  ASK_NAME_MASK = ASK_NAME_AS_IS | ASK_NAME_LOWERCASE | ASK_NAME_UPPERCASE
32
39
 
40
+ INPUTS = [:filename, :filehandle, :arrayref, :scalarref, :source]
41
+ # :startdoc:
42
+
33
43
  @@func = {
34
44
  # note that length,defined,sin,cos,log,tan,... are built-in
35
45
  :sprintf => lambda { |*args| sprintf(*args) },
@@ -47,6 +57,142 @@ module HTML
47
57
  :srand => lambda { |seed| srand seed },
48
58
  }
49
59
 
60
+ # Create a `Template' object. `Template' source is specified by several way.
61
+ # Exactly one kind of source must be specified.
62
+ #
63
+ # * specify filename
64
+ #
65
+ # template = HTML::Template::Pro.new(:filename => 'foo.tmpl')
66
+ #
67
+ # * specify source as string
68
+ #
69
+ # template = HTLM::Template::Pro.new(:source => '<html><body><TMPL_VAR NAME="hello">!!</body></html>')
70
+ #
71
+ # * specify source by array of string
72
+ #
73
+ # template = HTLM::Template::Pro.new(:source => ['<html>', '<body><TMPL_VAR NAME="hello">!!</body>', '</html>'])
74
+ #
75
+ # * specify IO object
76
+ #
77
+ # template = HTLM::Template::Pro.new(:source => $stdin)
78
+ #
79
+ # === Other options
80
+ #
81
+ # ==== path
82
+ #
83
+ # Array of file path which include template files.
84
+ #
85
+ # Example:
86
+ #
87
+ # # find out tmpl/foo.tmpl
88
+ # template = HTLM::Template::Pro.new(:filename => 'foo.tmpl', :path => ['tmpl'])
89
+ #
90
+ # ==== search_path_on_include
91
+ #
92
+ # Boolean that indicates whether we search directory specified
93
+ # by `path' param when we meet the TMPL_INCLUDE tag.
94
+ #
95
+ # Example:
96
+ #
97
+ # # tmpl_includes/foo.tmpl is used.
98
+ # template = HTLM::Template::Pro.new(:source => '<TMPL_INCLUDE NAME="foo.tmpl">',
99
+ # :path => ['tmpl_includes'],
100
+ # :search_path_on_include => true)
101
+ #
102
+ # ==== associate
103
+ #
104
+ # this option allows you to inherit the parameter values from
105
+ # other objects. The only requirement for the other object is
106
+ # that it have a "param()" method that works like HTML::Template::Pro#param.
107
+ #
108
+ # ==== case_sensitive
109
+ #
110
+ # if this options is true, template variable is treated as case sensitive.
111
+ #
112
+ # Example:
113
+ #
114
+ # template = HTML::Template::Pro.new(:source => '<TMPL_VAR NAME="FoO">',
115
+ # :case_sensitive => true)
116
+ # template.param(:foo => 100)
117
+ # puts template.output # output empty string ( foo is not 'FoO' )
118
+ #
119
+ # ==== loop_context_vars
120
+ #
121
+ # when this parameter is set to true (it is false by default)
122
+ # five loop context variables are made available inside a loop:
123
+ # __first__, __last__, __inner__, __odd__, __counter__. They
124
+ # can be used with <TMPL_IF>, <TMPL_UNLESS> and <TMPL_ELSE> to
125
+ # control how a loop is output.
126
+ #
127
+ # Example:
128
+ # In your templates,
129
+ #
130
+ # <TMPL_LOOP NAME="loop">
131
+ # <TMPL_IF NAME="__first__">First!</TMPL_IF>
132
+ # <TMPL_VAR NAME="__counter__">
133
+ # <TMPL_IF NAME="__last__">Last!</TMPL_IF>
134
+ # </TMPL_LOOP>
135
+ #
136
+ # ==== no_includes
137
+ #
138
+ # set this option to true to disallow the <TMPL_INCLUDE> tag in the
139
+ # template file. This can be used to make opening untrusted
140
+ # templates *slightly* less dangerous. Defaults to false.
141
+ #
142
+ # ==== max_includes
143
+ #
144
+ # set this variable to determine the maximum depth that includes
145
+ # can reach. Set to 10 by default. Including files to a depth
146
+ # greater than this value causes an error message to be
147
+ # displayed. Set to 0 to disable this protection.
148
+ #
149
+ # ==== global_vars
150
+ #
151
+ # normally variables declared outside a loop are not available
152
+ # inside a loop. This option makes <TMPL_VAR>s like global
153
+ # variables - they have unlimited scope. This option also
154
+ # affects <TMPL_IF> and <TMPL_UNLESS>.
155
+ #
156
+ # ==== path_like_variable_scope
157
+ #
158
+ # this option switches on a Shigeki Morimoto extension to
159
+ # HTML::Template::Pro that allows access to variables that are
160
+ # outside the current loop scope using path-like expressions.
161
+ #
162
+ # Example:
163
+ #
164
+ # <TMPL_LOOP NAME=class>
165
+ # <TMPL_LOOP NAME=person>
166
+ # <TMPL_VAR NAME="../teacher_name"> <!-- access to class.teacher_name -->
167
+ # <TMPL_VAR NAME="name">
168
+ # <TMPL_VAR NAME="/top_level_value"> <!-- access to top level value -->
169
+ # <TMPL_VAR NAME="age">
170
+ # <TMPL_LOOP NAME="../../school"> <!-- enter loop before accessing its vars -->
171
+ # <TMPL_VAR NAME="school_name"> <!-- access to [../../]school.school_name -->
172
+ # </TMPL_LOOP>
173
+ # </TMPL_LOOP>
174
+ # </TMPL_LOOP>
175
+ #
176
+ # ==== filter
177
+ #
178
+ # By using this option, you can filter the source of template
179
+ # before HTML::Template::Pro prcesses it.
180
+ #
181
+ # Example:
182
+ #
183
+ # myfilter = ->(source){ source.gsub(/Foo/, 'Bar') }
184
+ # template = HTML::Template::Pro.new(:source => '<TMPL_VAR NAME="Foo">!!',
185
+ # :filter => myfilter)
186
+ # template.param(:Bar => 'hello')
187
+ # puts template.output # displays 'hello!!'
188
+ #
189
+ # ==== default_escape
190
+ #
191
+ # Set this parameter to "HTML", "URL" or "JS" and
192
+ # HTML::Template::Pro will apply the specified escaping to all
193
+ # variables unless they declare a different escape in the
194
+ # template.
195
+ #
50
196
  def initialize(args={})
51
197
  @options = default_options.merge(args)
52
198
  if args.keys.count(&INPUTS.method(:include?)) != 1
@@ -66,6 +212,48 @@ module HTML
66
212
  @filtered_template = {}
67
213
  end
68
214
 
215
+ # #param can be called in a number of ways.
216
+ #
217
+ # 1. call with no arguments.
218
+ #
219
+ # returns a list of parameters set after new.
220
+ #
221
+ # Example:
222
+ # template = HTML::Template::Pro.new(:filename => 'foo.tmpl')
223
+ # template.param(:foo => 10, :bar => 20)
224
+ # params = template.param # returns [:foo, :bar]
225
+ #
226
+ # 2. pass one parameter name.
227
+ #
228
+ # returns the value of a parameter.
229
+ #
230
+ # Example:
231
+ # template = HTML::Template::Pro.new(:filename => 'foo.tmpl')
232
+ # template.param(:foo => 10, :bar => 20)
233
+ # val = template.param(:foo) # now `val' equals 10.
234
+ #
235
+ # 3. pass hash.
236
+ #
237
+ # assign values to parameters.
238
+ #
239
+ # Example:
240
+ #
241
+ # template = HTML::Template::Pro.new(:source => <<'TMPL')
242
+ # <TMPL_VAR NAME="foo">
243
+ # <TMPL_VAR NAME="bar">
244
+ # TMPL
245
+ # template.param(:foo => 10, :bar => 20)
246
+ # puts template.output # displays "10\n20\n"
247
+ #
248
+ # # you can specify the value by passing block.
249
+ # # in this way, you must assign exactly one parameter.
250
+ # template.param(:foo) { Time.now }
251
+ # puts template.output # prints the time #output is executed.
252
+ #
253
+ # # Or you can use proc or lambda.
254
+ # template.param(:foo => lambda { Time.now },
255
+ # :bar => lambda { rand(100) })
256
+ #
69
257
  def param(args=nil, &block)
70
258
  return @params.keys if args.nil?
71
259
  if !(args.kind_of? Hash)
@@ -79,10 +267,26 @@ module HTML
79
267
  merge_params(args)
80
268
  end
81
269
 
270
+ # Clear the internal param hash. All the parameters set before
271
+ # this call is reset.
82
272
  def clear_params
83
273
  @params.clear
84
274
  end
85
275
 
276
+ # returns the final result of the template. If you want to print
277
+ # out the result, you can do:
278
+ # puts template.output
279
+ #
280
+ # When `output' is called each occurrence of <TMPL_VAR
281
+ # NAME=name> is replaced with the value assigned to "name" via
282
+ # "param()". If a named parameter is unset it is simply replaced
283
+ # with ’’. <TMPL_LOOPS> are evaluated once per parameter set,
284
+ # accumulating output on each pass.
285
+ #
286
+ # You may optionally supply a IO object to print:
287
+ # File.open('result.html', 'w') do |file|
288
+ # template.output(:print_to => file)
289
+ # end
86
290
  def output(options={})
87
291
 
88
292
  @options[:associate].reverse.each do |assoc|
@@ -92,22 +296,65 @@ module HTML
92
296
  end
93
297
 
94
298
  if (options.include? :print_to)
95
- exec_tmpl(options[:print_to])
299
+ HTML::Template::Internal.exec_tmpl(self, options[:print_to])
96
300
  else
97
301
  output_string = String.new
98
- exec_tmpl(output_string)
302
+ HTML::Template::Internal.exec_tmpl(self, output_string)
99
303
  return output_string
100
304
  end
101
305
  end
102
306
 
307
+ # <b>for perl compatibility</b>
308
+ #
309
+ # shortcut to HTML::Template::Pro.new(:filehandle => file)
103
310
  def self.new_filehandle(file)
104
311
  self.new(:filehandle => file)
105
312
  end
106
313
 
314
+ # <b>for perl compatibility</b>
315
+ #
316
+ # shortcut to HTML::Template::Pro.new(:filename => filename)
317
+ def self.new_file(filename)
318
+ self.new(:filename => file)
319
+ end
320
+
321
+ # <b>for perl compatibility</b>
322
+ #
323
+ # shortcut to HTML::Template::Pro.new(:arrayref => lines)
324
+ def self.new_array_ref(lines)
325
+ self.new(:arrayref => lines)
326
+ end
327
+
328
+ # <b>for perl compatibility</b>
329
+ #
330
+ # shortcut to HTML::Template::Pro.new(:scalarref => source_string)
331
+ def self.new_scalar_ref(source)
332
+ self.new(:scalarref => source)
333
+ end
334
+
335
+ # register the function globally. See HTML::Template::Pro#register_function.
336
+ # Functions registered by this class method is shared by all instances.
107
337
  def self.register_function(func_spec, &block)
108
338
  HTML::Template::Internal.register_functions_impl(@@func, func_spec, &block)
109
339
  end
110
340
 
341
+ # define a new function that can be used in <tt><TMPL_VAR
342
+ # EXPR=""></tt> tag. function is specified by block or lambda.
343
+ #
344
+ # Example:
345
+ # template = HTML::Template::Pro.new(:source => '<TMPL_VAR EXPR="double(10)">')
346
+ # template.register_function(:double) {|num| num * 2 }
347
+ # # or template.register_function(:double => lambda {|num| num * 2 })
348
+ # puts template.output # displays `20'
349
+ #
350
+ # You can also register the functions by passing lambdas to new.
351
+ #
352
+ # Example:
353
+ # template = HTML::Template::Pro.new(:filename => 'foo.tmpl',
354
+ # :functions => {
355
+ # :square => lambda {|x| x * x },
356
+ # })
357
+ #
111
358
  def register_function(func_spec, &block)
112
359
  HTML::Template::Internal.register_functions_impl(@options[:expr_func], func_spec, &block)
113
360
  end
@@ -1,5 +1,5 @@
1
1
  namespace :extconf do
2
- extension = 'html/template/internal'
2
+ extension = 'html/template'
3
3
 
4
4
  ext = "ext/#{extension}"
5
5
  ext_so = "#{ext}/internal.#{Config::CONFIG['DLEXT']}"
@@ -1,6 +1,5 @@
1
1
  h1. html-template-pro
2
2
 
3
-
4
3
  h2. What
5
4
 
6
5
  A Ruby port of HTML::Template::Pro (template engine originally written
@@ -12,16 +11,41 @@ h2. Installing
12
11
 
13
12
  h2. The basics
14
13
 
15
-
16
- h2. Demonstration of usage
17
-
14
+ <pre syntex="ruby">
15
+ # foo.rb
16
+ require 'html/template/pro'
17
+
18
+ template = HTML::Template::Pro.new(:filename => 'foo.tmpl')
19
+ template.param(:param1 => 100)
20
+ puts template.output
21
+
22
+ # foo.tmpl
23
+ <html>
24
+ <head></head>
25
+ <body>
26
+ <h1><TMPL_VAR NAME="param1"></h1>
27
+ </body>
28
+ </html>
29
+
30
+ # results
31
+ $ ruby foo.rb
32
+ <html>
33
+ <head></head>
34
+ <body>
35
+ <h1>100</h1>
36
+ </body>
37
+ </html>
38
+ </pre>
39
+
40
+ Template syntax compies with original Perl module's. See also,
41
+ "HTML::Template::SYNTAX":http://search.cpan.org/~viy/HTML-Template-Pro-0.92/lib/HTML/Template/SYNTAX.pod#SYNOPSIS
42
+
43
+ h2. Project
18
44
 
19
45
  <% if rubyforge_project_id %>
20
46
 
21
47
  * rubyforge: "http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>":http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>
22
48
 
23
- <pre>git clone git://rubyforge.org/tmplpro.git</pre>
24
-
25
49
  <% else %>
26
50
 
27
51
  * rubyforge: MISSING IN ACTION
@@ -35,6 +59,8 @@ Or you can hack website/index.txt and make it all go away!!
35
59
 
36
60
  <% end %>
37
61
 
62
+ * rdoc documentations: "http://tmplpro.rubyforge.org/rdoc/":http://tmplpro.rubyforge.org/rdoc/
63
+
38
64
  * github: "http://github.com/tom-lpsd/ruby-html-template-pro/tree/master":http://github.com/tom-lpsd/ruby-html-template-pro/tree/master
39
65
 
40
66
  <pre>git clone git://github.com/tom-lpsd/ruby-html-template-pro.git</pre>
@@ -42,16 +68,18 @@ Or you can hack website/index.txt and make it all go away!!
42
68
 
43
69
  h3. Build and test instructions
44
70
 
45
- <pre>cd tmplpro
71
+ <pre>cd ruby-html-template-pro
46
72
  rake test
47
73
  rake install_gem</pre>
48
74
 
49
75
 
50
76
  h2. License
51
77
 
52
- LGPL
78
+ This library is free software; you can redistribute it and/or modify
79
+ it under the same terms of the GNU Lesser General Public License as
80
+ published by the Free Software Foundation; either version 2 of the
81
+ License, or (at your option) any later version.
53
82
 
54
83
  h2. Contact
55
84
 
56
85
  Comments are welcome. Send an email to "Tom Tsuruhara":mailto:tom.lpsd@gmail.com
57
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-template-pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsuruhara Tom
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-01 00:00:00 +09:00
12
+ date: 2009-10-03 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,14 +23,19 @@ dependencies:
23
23
  version: 2.3.3
24
24
  version:
25
25
  description: |-
26
- A Ruby port of HTML::Template::Pro (template engine originally written
27
- in Perl and XS).
26
+ A Ruby port of `HTML::Template::Pro'. `HTML::Template::Pro' is
27
+ template engine originally written in Perl and XS. It's so fast
28
+ because of its C based implementation. Its syntax is very simple.
29
+ This results clearly separation of application logic and its view.
30
+
31
+ Template syntax complies with original perl module's syntax.
32
+ Please see, HTML::Template::SYNTAX[http://search.cpan.org/~viy/HTML-Template-Pro-0.92/lib/HTML/Template/SYNTAX.pod#SYNOPSIS].
28
33
  email:
29
34
  - tom.lpsd@gmail.com
30
35
  executables: []
31
36
 
32
37
  extensions:
33
- - ext/html/template/internal/extconf.rb
38
+ - ext/html/template/extconf.rb
34
39
  extra_rdoc_files:
35
40
  - History.txt
36
41
  - Manifest.txt
@@ -46,50 +51,50 @@ files:
46
51
  - Rakefile
47
52
  - benchmark.rb
48
53
  - config/website.yml
49
- - ext/html/template/internal/Pro.xs
50
- - ext/html/template/internal/builtin_findfile.inc
51
- - ext/html/template/internal/calc.h
52
- - ext/html/template/internal/calc.inc
53
- - ext/html/template/internal/callback_stubs.inc
54
- - ext/html/template/internal/expr.c
55
- - ext/html/template/internal/expr.y
56
- - ext/html/template/internal/expr_iface.c
57
- - ext/html/template/internal/exprpstr.h
58
- - ext/html/template/internal/exprpstr.inc
59
- - ext/html/template/internal/exprtool.h
60
- - ext/html/template/internal/exprtool.inc
61
- - ext/html/template/internal/exprtype.h
62
- - ext/html/template/internal/exprval.h
63
- - ext/html/template/internal/extconf.rb
64
- - ext/html/template/internal/internal.c
65
- - ext/html/template/internal/loadfile.h
66
- - ext/html/template/internal/loadfile.inc
67
- - ext/html/template/internal/pabidecl.h
68
- - ext/html/template/internal/pabstract.h
69
- - ext/html/template/internal/parse_expr.h
70
- - ext/html/template/internal/pbuffer.c
71
- - ext/html/template/internal/pbuffer.h
72
- - ext/html/template/internal/pmiscdef.h
73
- - ext/html/template/internal/pparam.h
74
- - ext/html/template/internal/ppport.h
75
- - ext/html/template/internal/procore.c
76
- - ext/html/template/internal/procore.h
77
- - ext/html/template/internal/proparam.c
78
- - ext/html/template/internal/proparam.h
79
- - ext/html/template/internal/proscope.h
80
- - ext/html/template/internal/proscope.inc
81
- - ext/html/template/internal/prostate.h
82
- - ext/html/template/internal/prostate.inc
83
- - ext/html/template/internal/provalue.h
84
- - ext/html/template/internal/pstring.h
85
- - ext/html/template/internal/pstrutils.h
86
- - ext/html/template/internal/pstrutils.inc
87
- - ext/html/template/internal/tagstack.h
88
- - ext/html/template/internal/tagstack.inc
89
- - ext/html/template/internal/tmpllog.c
90
- - ext/html/template/internal/tmpllog.h
91
- - ext/html/template/internal/tmplpro.h
92
- - ext/html/template/internal/tmplpro_version.c
54
+ - ext/html/template/Pro.xs
55
+ - ext/html/template/builtin_findfile.inc
56
+ - ext/html/template/calc.h
57
+ - ext/html/template/calc.inc
58
+ - ext/html/template/callback_stubs.inc
59
+ - ext/html/template/expr.c
60
+ - ext/html/template/expr.y
61
+ - ext/html/template/expr_iface.c
62
+ - ext/html/template/exprpstr.h
63
+ - ext/html/template/exprpstr.inc
64
+ - ext/html/template/exprtool.h
65
+ - ext/html/template/exprtool.inc
66
+ - ext/html/template/exprtype.h
67
+ - ext/html/template/exprval.h
68
+ - ext/html/template/extconf.rb
69
+ - ext/html/template/internal.c
70
+ - ext/html/template/loadfile.h
71
+ - ext/html/template/loadfile.inc
72
+ - ext/html/template/pabidecl.h
73
+ - ext/html/template/pabstract.h
74
+ - ext/html/template/parse_expr.h
75
+ - ext/html/template/pbuffer.c
76
+ - ext/html/template/pbuffer.h
77
+ - ext/html/template/pmiscdef.h
78
+ - ext/html/template/pparam.h
79
+ - ext/html/template/ppport.h
80
+ - ext/html/template/procore.c
81
+ - ext/html/template/procore.h
82
+ - ext/html/template/proparam.c
83
+ - ext/html/template/proparam.h
84
+ - ext/html/template/proscope.h
85
+ - ext/html/template/proscope.inc
86
+ - ext/html/template/prostate.h
87
+ - ext/html/template/prostate.inc
88
+ - ext/html/template/provalue.h
89
+ - ext/html/template/pstring.h
90
+ - ext/html/template/pstrutils.h
91
+ - ext/html/template/pstrutils.inc
92
+ - ext/html/template/tagstack.h
93
+ - ext/html/template/tagstack.inc
94
+ - ext/html/template/tmpllog.c
95
+ - ext/html/template/tmpllog.h
96
+ - ext/html/template/tmplpro.h
97
+ - ext/html/template/tmplpro_version.c
93
98
  - lib/html/template/pro.rb
94
99
  - script/console
95
100
  - script/destroy
@@ -246,7 +251,6 @@ files:
246
251
  - test/test_complex.rb
247
252
  - test/test_helper.rb
248
253
  - test/test_html_template.rb
249
- - test/test_html_template_internal_extn.rb
250
254
  - test/test_html_template_pro.rb
251
255
  - test/test_path_like_variable_scope.rb
252
256
  - test/test_random.rb
@@ -271,9 +275,9 @@ require_paths:
271
275
  - ext/html
272
276
  required_ruby_version: !ruby/object:Gem::Requirement
273
277
  requirements:
274
- - - ">="
278
+ - - ">"
275
279
  - !ruby/object:Gem::Version
276
- version: "0"
280
+ version: 1.9.0
277
281
  version:
278
282
  required_rubygems_version: !ruby/object:Gem::Requirement
279
283
  requirements:
@@ -294,7 +298,6 @@ test_files:
294
298
  - test/test_complex.rb
295
299
  - test/test_helper.rb
296
300
  - test/test_html_template.rb
297
- - test/test_html_template_internal_extn.rb
298
301
  - test/test_html_template_pro.rb
299
302
  - test/test_path_like_variable_scope.rb
300
303
  - test/test_random.rb
@@ -1,10 +0,0 @@
1
- require "test/unit"
2
-
3
- $:.unshift File.dirname(__FILE__) + "/../ext/html_template_internal"
4
- require "html_template_internal.so"
5
-
6
- class TestHtmlTemplateInternalExtn < Test::Unit::TestCase
7
- def test_truth
8
- assert(true)
9
- end
10
- end