kwartz 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/ChangeLog +103 -0
- data/README.txt +37 -0
- data/bin/kwartz +12 -0
- data/doc-api/classes/Kwartz.html +218 -0
- data/doc-api/classes/Kwartz/Assertion.html +140 -0
- data/doc-api/classes/Kwartz/AssertionError.html +148 -0
- data/doc-api/classes/Kwartz/AttrInfo.html +320 -0
- data/doc-api/classes/Kwartz/BaseError.html +206 -0
- data/doc-api/classes/Kwartz/BaseTranslator.html +331 -0
- data/doc-api/classes/Kwartz/CharacterType.html +212 -0
- data/doc-api/classes/Kwartz/CommandOptionError.html +154 -0
- data/doc-api/classes/Kwartz/CommandOptions.html +374 -0
- data/doc-api/classes/Kwartz/Config.html +150 -0
- data/doc-api/classes/Kwartz/ConvertError.html +191 -0
- data/doc-api/classes/Kwartz/Converter.html +252 -0
- data/doc-api/classes/Kwartz/CssStyleParser.html +483 -0
- data/doc-api/classes/Kwartz/DocumentRuleset.html +369 -0
- data/doc-api/classes/Kwartz/ElementExpander.html +325 -0
- data/doc-api/classes/Kwartz/ElementInfo.html +312 -0
- data/doc-api/classes/Kwartz/ElementRuleset.html +582 -0
- data/doc-api/classes/Kwartz/EperlHandler.html +338 -0
- data/doc-api/classes/Kwartz/EperlTranslator.html +167 -0
- data/doc-api/classes/Kwartz/ErubisHandler.html +113 -0
- data/doc-api/classes/Kwartz/ErubisTranslator.html +168 -0
- data/doc-api/classes/Kwartz/ErubyHandler.html +337 -0
- data/doc-api/classes/Kwartz/ErubyTranslator.html +167 -0
- data/doc-api/classes/Kwartz/ExpandStatement.html +227 -0
- data/doc-api/classes/Kwartz/Expression.html +119 -0
- data/doc-api/classes/Kwartz/Handler.html +558 -0
- data/doc-api/classes/Kwartz/JstlHandler.html +657 -0
- data/doc-api/classes/Kwartz/JstlTranslator.html +226 -0
- data/doc-api/classes/Kwartz/KwartzError.html +146 -0
- data/doc-api/classes/Kwartz/Main.html +384 -0
- data/doc-api/classes/Kwartz/NativeExpression.html +236 -0
- data/doc-api/classes/Kwartz/NativeStatement.html +254 -0
- data/doc-api/classes/Kwartz/Node.html +156 -0
- data/doc-api/classes/Kwartz/ParseError.html +148 -0
- data/doc-api/classes/Kwartz/PhpHandler.html +333 -0
- data/doc-api/classes/Kwartz/PhpTranslator.html +194 -0
- data/doc-api/classes/Kwartz/PresentationLogicParser.html +830 -0
- data/doc-api/classes/Kwartz/PrintStatement.html +221 -0
- data/doc-api/classes/Kwartz/RailsHandler.html +587 -0
- data/doc-api/classes/Kwartz/RailsTranslator.html +167 -0
- data/doc-api/classes/Kwartz/RubyStyleParser.html +558 -0
- data/doc-api/classes/Kwartz/Ruleset.html +117 -0
- data/doc-api/classes/Kwartz/Statement.html +119 -0
- data/doc-api/classes/Kwartz/StrutsTranslator.html +190 -0
- data/doc-api/classes/Kwartz/TagInfo.html +314 -0
- data/doc-api/classes/Kwartz/TextConverter.html +270 -0
- data/doc-api/classes/Kwartz/Translator.html +318 -0
- data/doc-api/classes/Test.html +107 -0
- data/doc-api/classes/Test/Unit.html +101 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/__/README_txt.html +150 -0
- data/doc-api/files/kwartz/assert_rb.html +114 -0
- data/doc-api/files/kwartz/binding/eperl_rb.html +116 -0
- data/doc-api/files/kwartz/binding/erubis_rb.html +116 -0
- data/doc-api/files/kwartz/binding/eruby_rb.html +115 -0
- data/doc-api/files/kwartz/binding/jstl_rb.html +116 -0
- data/doc-api/files/kwartz/binding/php_rb.html +116 -0
- data/doc-api/files/kwartz/binding/rails_rb.html +115 -0
- data/doc-api/files/kwartz/binding/struts_rb.html +117 -0
- data/doc-api/files/kwartz/config_rb.html +107 -0
- data/doc-api/files/kwartz/converter_rb.html +119 -0
- data/doc-api/files/kwartz/error_rb.html +107 -0
- data/doc-api/files/kwartz/main_rb.html +124 -0
- data/doc-api/files/kwartz/node_rb.html +114 -0
- data/doc-api/files/kwartz/parser_rb.html +117 -0
- data/doc-api/files/kwartz/translator_rb.html +115 -0
- data/doc-api/files/kwartz/util/assert-text-equal_rb.html +115 -0
- data/doc-api/files/kwartz/util/testcase-helper_rb.html +115 -0
- data/doc-api/files/kwartz_rb.html +120 -0
- data/doc-api/fr_class_index.html +75 -0
- data/doc-api/fr_file_index.html +45 -0
- data/doc-api/fr_method_index.html +216 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/docstyle.css +188 -0
- data/doc/p-pattern.html +1207 -0
- data/doc/reference.html +3396 -0
- data/doc/users-guide.html +1670 -0
- data/examples/breadcrumbs1/Makefile +15 -0
- data/examples/breadcrumbs1/breadcrumbs.eruby.plogic +27 -0
- data/examples/breadcrumbs1/breadcrumbs.html +12 -0
- data/examples/breadcrumbs1/breadcrumbs.jstl.plogic +28 -0
- data/examples/breadcrumbs1/breadcrumbs.php.plogic +26 -0
- data/examples/breadcrumbs1/main.php +12 -0
- data/examples/breadcrumbs1/main.rb +12 -0
- data/examples/breadcrumbs2/Makefile +15 -0
- data/examples/breadcrumbs2/breadcrumbs.eruby.plogic +22 -0
- data/examples/breadcrumbs2/breadcrumbs.html +14 -0
- data/examples/breadcrumbs2/breadcrumbs.jstl.plogic +24 -0
- data/examples/breadcrumbs2/breadcrumbs.php.plogic +23 -0
- data/examples/breadcrumbs2/main.php +12 -0
- data/examples/breadcrumbs2/main.rb +12 -0
- data/examples/pagelayout/Makefile +47 -0
- data/examples/pagelayout/content.eruby.plogic +44 -0
- data/examples/pagelayout/content.jstl.plogic +36 -0
- data/examples/pagelayout/content.php.plogic +37 -0
- data/examples/pagelayout/content1.html +36 -0
- data/examples/pagelayout/content2.html +29 -0
- data/examples/pagelayout/design.css +40 -0
- data/examples/pagelayout/layout.html +50 -0
- data/examples/pagelayout/main.php +55 -0
- data/examples/pagelayout/main.rb +77 -0
- data/examples/pagelayout/menu.eruby.plogic +14 -0
- data/examples/pagelayout/menu.html +13 -0
- data/examples/pagelayout/menu.jstl.plogic +14 -0
- data/examples/pagelayout/menu.php.plogic +14 -0
- data/examples/rails1/Makefile +36 -0
- data/examples/rails1/README +19 -0
- data/examples/rails1/application_helper.rb +31 -0
- data/examples/rails1/edit.html +28 -0
- data/examples/rails1/edit.plogic +10 -0
- data/examples/rails1/form.html +52 -0
- data/examples/rails1/form.plogic +33 -0
- data/examples/rails1/layout.plogic +15 -0
- data/examples/rails1/link_to.plogic +19 -0
- data/examples/rails1/list.html +48 -0
- data/examples/rails1/list.plogic +28 -0
- data/examples/rails1/new.html +27 -0
- data/examples/rails1/new.plogic +10 -0
- data/examples/rails1/reader.plogic +29 -0
- data/examples/rails1/show.html +40 -0
- data/examples/rails1/show.plogic +4 -0
- data/examples/rails1/writer.plogic +8 -0
- data/examples/table1/Makefile +15 -0
- data/examples/table1/main.php +11 -0
- data/examples/table1/main.rb +11 -0
- data/examples/table1/table1.eruby.plogic +21 -0
- data/examples/table1/table1.html +16 -0
- data/examples/table1/table1.jstl.plogic +21 -0
- data/examples/table1/table1.php.plogic +22 -0
- data/kwartz.gemspec +55 -0
- data/lib/kwartz.rb +13 -0
- data/lib/kwartz/assert.rb +31 -0
- data/lib/kwartz/binding/eperl.rb +166 -0
- data/lib/kwartz/binding/erubis.rb +61 -0
- data/lib/kwartz/binding/eruby.rb +164 -0
- data/lib/kwartz/binding/jstl.rb +334 -0
- data/lib/kwartz/binding/php.rb +167 -0
- data/lib/kwartz/binding/rails.rb +295 -0
- data/lib/kwartz/binding/struts.rb +109 -0
- data/lib/kwartz/config.rb +28 -0
- data/lib/kwartz/converter.rb +920 -0
- data/lib/kwartz/error.rb +41 -0
- data/lib/kwartz/main.rb +464 -0
- data/lib/kwartz/node.rb +454 -0
- data/lib/kwartz/parser.rb +903 -0
- data/lib/kwartz/translator.rb +153 -0
- data/lib/kwartz/util/assert-text-equal.rb +44 -0
- data/lib/kwartz/util/testcase-helper.rb +112 -0
- data/setup.rb +1331 -0
- data/test/test-compile.rb +36 -0
- data/test/test-compile.yaml +178 -0
- data/test/test-converter.rb +34 -0
- data/test/test-converter.yaml +127 -0
- data/test/test-directives.rb +32 -0
- data/test/test-directives.yaml +1411 -0
- data/test/test-main.rb +464 -0
- data/test/test-parser.rb +54 -0
- data/test/test-parser.yaml +394 -0
- data/test/test-rails.rb +28 -0
- data/test/test-rails.yaml +301 -0
- data/test/test-ruleset.rb +36 -0
- data/test/test-ruleset.yaml +804 -0
- data/test/test.rb +44 -0
- metadata +236 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
#row {
|
2
|
+
attrs: "bgcolor" color;
|
3
|
+
logic: {
|
4
|
+
<c:forEach var="item" items="${list}" varStatus="loop">
|
5
|
+
<c:set var="color" value="${loop.index % 2 == 0 ? '#FFCCCC' : '#CCCCFF'}"/>
|
6
|
+
_elem
|
7
|
+
</c:forEach>
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
#name {
|
12
|
+
value: item.name;
|
13
|
+
}
|
14
|
+
|
15
|
+
#mail {
|
16
|
+
value: item.mail;
|
17
|
+
}
|
18
|
+
|
19
|
+
#dummy1 {
|
20
|
+
logic: { } /* ignore this element */
|
21
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#row {
|
2
|
+
attrs: "bgcolor" $color;
|
3
|
+
logic: {
|
4
|
+
$i = 0;
|
5
|
+
foreach ($list as $item) {
|
6
|
+
$color = ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF';
|
7
|
+
_elem();
|
8
|
+
}
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
#name {
|
13
|
+
value: $item['name'];
|
14
|
+
}
|
15
|
+
|
16
|
+
#mail {
|
17
|
+
value: $item['mail'];
|
18
|
+
}
|
19
|
+
|
20
|
+
#dummy1 {
|
21
|
+
logic: { } /* ignore this element */
|
22
|
+
}
|
data/kwartz.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
###
|
4
|
+
### RubyGems Specification file for Kwartz-ruby
|
5
|
+
###
|
6
|
+
### $Rev: 117 $
|
7
|
+
### $Release: 3.0.0 $
|
8
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
9
|
+
###
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
## package information
|
15
|
+
s.name = 'kwartz'
|
16
|
+
s.author = 'Makoto Kuwata'
|
17
|
+
s.version = ("$Release: 3.0.0 $" =~ /[\.\d]+/) && $&
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.homepage = 'http://www.kuwata-lab.com/kwartz'
|
20
|
+
s.summary = "a template system for Ruby, PHP, and Java"
|
21
|
+
s.description = <<-'END'
|
22
|
+
Kwartz is a template system which realized the concept
|
23
|
+
'Independence of Presentation Logic'(IoPL).
|
24
|
+
It means that Kwartz can separates presentation logics from
|
25
|
+
both business logics (= main program) and presentation data
|
26
|
+
file (= HTML file), thus HTML design is not breaded at all.
|
27
|
+
In addition, Kwartz supports eRuby, PHP, JSP, and ePerl.
|
28
|
+
END
|
29
|
+
|
30
|
+
## files
|
31
|
+
files = []
|
32
|
+
files += Dir.glob('lib/**/*')
|
33
|
+
files += Dir.glob('bin/**/*')
|
34
|
+
files += Dir.glob('examples/**/*')
|
35
|
+
files += Dir.glob('test/**/*')
|
36
|
+
#files += Dir.glob('man/**/*')
|
37
|
+
files += [ "doc/users-guide.html",
|
38
|
+
"doc/reference.html",
|
39
|
+
"doc/p-pattern.html",
|
40
|
+
"doc/docstyle.css",
|
41
|
+
#"doc/design.css", "doc/design.html",
|
42
|
+
]
|
43
|
+
files += Dir.glob('doc-api/**/*')
|
44
|
+
files += %w[README.txt ChangeLog COPYING setup.rb kwartz.gemspec]
|
45
|
+
s.files = files
|
46
|
+
s.executables = ["kwartz"]
|
47
|
+
s.bindir = "bin"
|
48
|
+
s.test_file = 'test/test.rb'
|
49
|
+
s.add_dependency('abstract', ['>= 1.0.0'])
|
50
|
+
end
|
51
|
+
|
52
|
+
if $0 == __FILE__
|
53
|
+
Gem::manage_gems
|
54
|
+
Gem::Builder.new(spec).build
|
55
|
+
end
|
data/lib/kwartz.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 103 $
|
3
|
+
### $Release: 3.0.0 $
|
4
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'kwartz/config'
|
8
|
+
require 'kwartz/error'
|
9
|
+
require 'kwartz/assert'
|
10
|
+
require 'kwartz/node'
|
11
|
+
require 'kwartz/parser'
|
12
|
+
require 'kwartz/converter'
|
13
|
+
require 'kwartz/translator'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
####
|
2
|
+
#### $Rev: 103 $
|
3
|
+
#### $Release: 3.0.0 $
|
4
|
+
#### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
####
|
6
|
+
|
7
|
+
|
8
|
+
require 'kwartz/error'
|
9
|
+
|
10
|
+
|
11
|
+
module Kwartz
|
12
|
+
|
13
|
+
|
14
|
+
class AssertionError < KwartzError
|
15
|
+
def initialize(message)
|
16
|
+
super(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
module Assertion
|
22
|
+
|
23
|
+
def assert(message="")
|
24
|
+
raise AssertionError.new("*** assertion failed: #{message}")
|
25
|
+
end
|
26
|
+
|
27
|
+
module_function :assert
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 117 $
|
3
|
+
### $Release: 3.0.0 $
|
4
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'kwartz/assert'
|
8
|
+
require 'kwartz/converter'
|
9
|
+
require 'kwartz/translator'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
module Kwartz
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
##
|
18
|
+
## directive handler for ePerl
|
19
|
+
##
|
20
|
+
class EperlHandler < Handler
|
21
|
+
|
22
|
+
|
23
|
+
PERL_DIRECTIVE_PATTERN = /\A(\w+)(?:\s*\(\s*(.*)\))?\z/
|
24
|
+
|
25
|
+
def directive_pattern
|
26
|
+
return PERL_DIRECTIVE_PATTERN
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
PERL_MAPPING_PATTERN = /\A'([-:\w]+)',\s*(.*)\z/
|
31
|
+
|
32
|
+
def mapping_pattern
|
33
|
+
return PERL_MAPPING_PATTERN
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
PERL_DIRECTIVE_FORMAT = '%s(%s)'
|
38
|
+
|
39
|
+
def directive_format
|
40
|
+
return PERL_DIRECTIVE_FORMAT
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
|
45
|
+
ret = super
|
46
|
+
return ret if ret
|
47
|
+
|
48
|
+
d_name = directive_name
|
49
|
+
d_arg = directive_arg
|
50
|
+
d_str = directive_str
|
51
|
+
|
52
|
+
case directive_name
|
53
|
+
|
54
|
+
when :foreach, :Foreach, :FOREACH, :list, :List, :LIST
|
55
|
+
is_foreach = d_name == :foreach || d_name == :Foreach || d_name == :FOREACH
|
56
|
+
unless d_arg =~ /\A(\$\w+)(?:,\s*(\$\w+))?\s+in\s+(.*)\z/
|
57
|
+
raise convert_error("'#{d_str}': invalid argument.", stag_info.linenum)
|
58
|
+
end
|
59
|
+
loopvar = $1 ; loopval = $2 ; looplist = $3
|
60
|
+
counter = d_name == :foreach || d_name == :list ? nil : "#{loopvar}_ctr"
|
61
|
+
toggle = d_name != :FOREACH && d_name != :LIST ? nil : "#{loopvar}_tgl"
|
62
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_foreach
|
63
|
+
stmt_list << NativeStatement.new("my #{counter} = 0;") if counter
|
64
|
+
if loopval
|
65
|
+
stmt_list << NativeStatement.new("foreach my #{loopvar} (keys #{looplist}) {", :foreach)
|
66
|
+
stmt_list << NativeStatement.new(" my #{loopval} = #{looplist.sub(/\A%/,'$')}{#{loopvar}};")
|
67
|
+
else
|
68
|
+
stmt_list << NativeStatement.new("foreach my #{loopvar} (#{looplist}) {", :foreach)
|
69
|
+
end
|
70
|
+
stmt_list << NativeStatement.new(" #{counter}++;") if counter
|
71
|
+
stmt_list << NativeStatement.new(" my #{toggle} = #{counter}%2==0 ? #{self.even} : #{self.odd};") if toggle
|
72
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_foreach
|
73
|
+
stmt_list.concat(cont_stmts)
|
74
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if is_foreach
|
75
|
+
stmt_list << NativeStatement.new("}", :foreach)
|
76
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_foreach
|
77
|
+
|
78
|
+
when :while, :loop
|
79
|
+
is_while = d_name == :while
|
80
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_while
|
81
|
+
stmt_list << NativeStatement.new("while (#{d_arg}) {", :while)
|
82
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_while
|
83
|
+
stmt_list.concat(cont_stmts)
|
84
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if is_while
|
85
|
+
stmt_list << NativeStatement.new("}", :while)
|
86
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_while
|
87
|
+
|
88
|
+
when :set
|
89
|
+
stmt_list << NativeStatement.new("#{d_arg};", :set)
|
90
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
91
|
+
stmt_list.concat(cont_stmts)
|
92
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
93
|
+
|
94
|
+
when :if
|
95
|
+
stmt_list << NativeStatement.new("if (#{d_arg}) {", :if)
|
96
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
97
|
+
stmt_list.concat(cont_stmts)
|
98
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
99
|
+
stmt_list << NativeStatement.new("}", :if)
|
100
|
+
|
101
|
+
when :elsif, :else
|
102
|
+
unless !stmt_list.empty? && (st=stmt_list[-1]).is_a?(NativeStatement) && (st.kind == :if || st.kind == :elseif)
|
103
|
+
raise convert_error("'#{d_str}': previous statement should be 'if' or 'elsif'.", stag_info.linenum)
|
104
|
+
end
|
105
|
+
stmt_list.pop # delete 'end'
|
106
|
+
if d_name == :else
|
107
|
+
kind = :else
|
108
|
+
stmt_list << NativeStatement.new("} else {", :else)
|
109
|
+
else
|
110
|
+
kind = :elseif
|
111
|
+
stmt_list << NativeStatement.new("} elsif (#{d_arg}) {", :elseif)
|
112
|
+
end
|
113
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
114
|
+
stmt_list.concat(cont_stmts)
|
115
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
116
|
+
stmt_list << NativeStatement.new("}", kind)
|
117
|
+
|
118
|
+
when :default, :Default, :DEFAULT
|
119
|
+
error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
|
120
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
121
|
+
stmt_list << NativeStatement.new_without_newline("if (#{d_arg}) {", :if)
|
122
|
+
flag_escape = d_name == :default ? nil : (d_name == :Default)
|
123
|
+
stmt_list << PrintStatement.new([ NativeExpression.new(d_arg, flag_escape) ])
|
124
|
+
stmt_list << NativeStatement.new_without_newline("} else {", :else)
|
125
|
+
stmt_list.concat(cont_stmts)
|
126
|
+
stmt_list << NativeStatement.new_without_newline("}", :else)
|
127
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
128
|
+
|
129
|
+
else
|
130
|
+
return false
|
131
|
+
|
132
|
+
end #case
|
133
|
+
return true
|
134
|
+
|
135
|
+
end #def
|
136
|
+
|
137
|
+
|
138
|
+
end #class
|
139
|
+
Handler.register_class('eperl', EperlHandler)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
##
|
144
|
+
## translator for ePerl
|
145
|
+
##
|
146
|
+
class EperlTranslator < BaseTranslator
|
147
|
+
|
148
|
+
|
149
|
+
EPERL_EMBED_PATTERNS = [
|
150
|
+
'<? ', ' !>', # statement
|
151
|
+
'<?= ', ' !>', # expression
|
152
|
+
'<?= encode_entities(', ') !>' # escaped expression
|
153
|
+
]
|
154
|
+
|
155
|
+
|
156
|
+
def initialize(properties={})
|
157
|
+
super(EPERL_EMBED_PATTERNS, properties)
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
end
|
162
|
+
Translator.register_class('eperl', EperlTranslator)
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
end #module
|
@@ -0,0 +1,61 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 110 $
|
3
|
+
### $Release: 3.0.0 $
|
4
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'kwartz/converter'
|
8
|
+
require 'kwartz/translator'
|
9
|
+
require 'kwartz/binding/eruby'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
module Kwartz
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
class ErubisHandler < ErubyHandler
|
18
|
+
|
19
|
+
|
20
|
+
end #class
|
21
|
+
Handler.register_class('erubis', ErubisHandler)
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
##
|
26
|
+
## translator for Erubis
|
27
|
+
##
|
28
|
+
class ErubisTranslator < BaseTranslator
|
29
|
+
|
30
|
+
|
31
|
+
ERUBIS_EMBED_PATTERNS = [
|
32
|
+
'<% ', ' %>', # statement
|
33
|
+
'<%= ', ' %>', # expression
|
34
|
+
'<%== ', ' %>', # escaped expression
|
35
|
+
]
|
36
|
+
|
37
|
+
|
38
|
+
def initialize(properties={})
|
39
|
+
super(ERUBIS_EMBED_PATTERNS, properties)
|
40
|
+
@escape = true if @escape == nil
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#def translate_native_expr(expr)
|
45
|
+
# assert unless expr.is_a?(NativeExpression)
|
46
|
+
# flag_escape = expr.escape?
|
47
|
+
# flag_escape = @escape if flag_escape == nil
|
48
|
+
# if flag_escape == false
|
49
|
+
# @sb << @expr_l << expr.code << @expr_r # ex. <%== expr %>
|
50
|
+
# else
|
51
|
+
# @sb << @escape_l << expr.code << @escape_r # ex. <%= expr %>
|
52
|
+
# end
|
53
|
+
#end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
Translator.register_class('erubis', ErubisTranslator)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
end #module
|
@@ -0,0 +1,164 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 111 $
|
3
|
+
### $Release: 3.0.0 $
|
4
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'kwartz/converter'
|
8
|
+
require 'kwartz/translator'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
module Kwartz
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
##
|
17
|
+
## directive handler for eRuby
|
18
|
+
##
|
19
|
+
class ErubyHandler < Handler
|
20
|
+
|
21
|
+
|
22
|
+
ERUBY_DIRECTIVE_PATTERN = /\A(\w+)(?:[:\s]\s*(.*))?\z/
|
23
|
+
|
24
|
+
def directive_pattern
|
25
|
+
return ERUBY_DIRECTIVE_PATTERN
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
ERUBY_MAPPING_PATTERN = /\A'([-:\w]+)'\s+(.*)\z/
|
30
|
+
|
31
|
+
def mapping_pattern
|
32
|
+
return ERUBY_MAPPING_PATTERN
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
ERUBY_DIRECTIVE_FORMAT = '%s: %s'
|
37
|
+
|
38
|
+
def directive_format
|
39
|
+
return ERUBY_DIRECTIVE_FORMAT
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
|
44
|
+
ret = super
|
45
|
+
return ret if ret
|
46
|
+
|
47
|
+
d_name = directive_name
|
48
|
+
d_arg = directive_arg
|
49
|
+
d_str = directive_str
|
50
|
+
|
51
|
+
case directive_name
|
52
|
+
|
53
|
+
when :for, :For, :FOR, :list, :List, :LIST
|
54
|
+
unless d_arg =~ /\A(\w+)(?:,\s*(\w+))?\s+in\s+(.*)\z/ || d_arg =~ /\A(\w+)(?:,(\w+))?\s*[:=]\s*(.*)\z/
|
55
|
+
raise convert_error("#'{d_str}': invalid argument.", stag_info.linenum)
|
56
|
+
end
|
57
|
+
loopvar = $1 ; loopval = $2 ; looplist = $3
|
58
|
+
is_foreach = d_name == :for || d_name == :For || d_name == :FOR
|
59
|
+
counter = d_name == :for || d_name == :list ? nil : "#{loopvar}_ctr"
|
60
|
+
toggle = d_name != :FOR && d_name != :LIST ? nil : "#{loopvar}_tgl"
|
61
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_foreach
|
62
|
+
stmt_list << NativeStatement.new("#{counter} = 0") if counter
|
63
|
+
if loopval
|
64
|
+
stmt_list << NativeStatement.new("#{looplist}.each do |#{loopvar}, #{loopval}|", :foreach)
|
65
|
+
else
|
66
|
+
stmt_list << NativeStatement.new("for #{loopvar} in #{looplist} do", :foreach)
|
67
|
+
end
|
68
|
+
stmt_list << NativeStatement.new(" #{counter} += 1") if counter
|
69
|
+
stmt_list << NativeStatement.new(" #{toggle} = #{counter}%2==0 ? #{self.even} : #{self.odd}") if toggle
|
70
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_foreach
|
71
|
+
stmt_list.concat(cont_stmts)
|
72
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if is_foreach
|
73
|
+
stmt_list << NativeStatement.new("end", :foreach)
|
74
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_foreach
|
75
|
+
|
76
|
+
when :while, :loop
|
77
|
+
is_while = d_name == :while
|
78
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if !is_while
|
79
|
+
stmt_list << NativeStatement.new("while #{d_arg} do", :while)
|
80
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if is_while
|
81
|
+
stmt_list.concat(cont_stmts)
|
82
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if is_while
|
83
|
+
stmt_list << NativeStatement.new("end", :while)
|
84
|
+
stmt_list << build_print_stmt(etag_info, nil, nil) if !is_while
|
85
|
+
|
86
|
+
when :set
|
87
|
+
stmt_list << NativeStatement.new(d_arg, :set)
|
88
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
89
|
+
stmt_list.concat(cont_stmts)
|
90
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
91
|
+
|
92
|
+
when :if
|
93
|
+
stmt_list << NativeStatement.new("if #{d_arg} then", :if)
|
94
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
95
|
+
stmt_list.concat(cont_stmts)
|
96
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
97
|
+
stmt_list << NativeStatement.new("end", :if)
|
98
|
+
|
99
|
+
when :elsif, :else
|
100
|
+
unless !stmt_list.empty? && (st=stmt_list[-1]).is_a?(NativeStatement) && (st.kind == :if || st.kind == :elseif)
|
101
|
+
raise convert_error("'#{d_str}': previous statement should be 'if' or 'elsif'.", stag_info.linenum)
|
102
|
+
end
|
103
|
+
stmt_list.pop # delete 'end'
|
104
|
+
if d_name == :else
|
105
|
+
kind = :else
|
106
|
+
stmt_list << NativeStatement.new("else", :else)
|
107
|
+
else
|
108
|
+
kind = :elseif
|
109
|
+
stmt_list << NativeStatement.new("elsif #{d_arg} then", :elseif)
|
110
|
+
end
|
111
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
112
|
+
stmt_list.concat(cont_stmts)
|
113
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
114
|
+
stmt_list << NativeStatement.new("end", kind)
|
115
|
+
|
116
|
+
when :default, :Default, :DEFAULT
|
117
|
+
error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
|
118
|
+
stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
|
119
|
+
stmt_list << NativeStatement.new_without_newline("if (#{d_arg}) && !(#{d_arg}).to_s.empty? then", :if)
|
120
|
+
flag_escape = d_name == :default ? nil : (d_name == :Default)
|
121
|
+
stmt_list << PrintStatement.new([ NativeExpression.new(d_arg, flag_escape) ])
|
122
|
+
stmt_list << NativeStatement.new_without_newline("else", :else)
|
123
|
+
stmt_list.concat(cont_stmts)
|
124
|
+
stmt_list << NativeStatement.new_without_newline("end", :else)
|
125
|
+
stmt_list << build_print_stmt(etag_info, nil, nil)
|
126
|
+
|
127
|
+
else
|
128
|
+
return false
|
129
|
+
|
130
|
+
end #case
|
131
|
+
return true
|
132
|
+
|
133
|
+
end #def
|
134
|
+
|
135
|
+
|
136
|
+
end #class
|
137
|
+
Handler.register_class('eruby', ErubyHandler)
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
##
|
142
|
+
## translator for eRuby
|
143
|
+
##
|
144
|
+
class ErubyTranslator < BaseTranslator
|
145
|
+
|
146
|
+
|
147
|
+
ERUBY_EMBED_PATTERNS = [
|
148
|
+
'<% ', ' %>', # statement
|
149
|
+
'<%= ', ' %>', # expression
|
150
|
+
'<%=h ', ' %>', # escaped expression
|
151
|
+
]
|
152
|
+
|
153
|
+
|
154
|
+
def initialize(properties={})
|
155
|
+
super(ERUBY_EMBED_PATTERNS, properties)
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
end #class
|
160
|
+
Translator.register_class('eruby', ErubyTranslator)
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
end #module
|