diff options
-rw-r--r-- | ChangeLog.txt | 9 | ||||
-rw-r--r-- | Rookbook.yaml | 2 | ||||
-rwxr-xr-x | bin/notext | 154 | ||||
-rw-r--r-- | doc/Rookbook.yaml | 8 | ||||
-rw-r--r-- | doc/users-guide.html | 482 | ||||
-rw-r--r-- | doc/users-guide.txt | 591 | ||||
-rw-r--r-- | lib/erubis/enhancer.rb | 4 | ||||
-rw-r--r-- | lib/erubis/main.rb | 44 | ||||
-rw-r--r-- | test/test-main.rb | 12 | ||||
-rw-r--r-- | test/test-notext.rb | 27 | ||||
-rw-r--r-- | test/test-notext.yaml | 504 | ||||
-rw-r--r-- | test/test.rb | 1 |
12 files changed, 577 insertions, 1261 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt index 6188c95..8abaaeb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,15 @@ .?lastupdate: $Date$ .?version: $Rev$ +: Rev.76 (2007-05-16) + .- [enhance] new command-line option '-X', '-N', '-C', and '-U' support + .- [change] command 'notext' has been removed + .- [change] remove test/test-notext.{rb,yaml} + .- [change] command-line option '-C' has been desupported + +: Rev.75 (2007-05-15) + .- [change] remove 'benchmark/erubybench*' + : Rev.74 (2007-05-15) .- [enhance] add 'benchmark/bench.rb' and 'benchmark/templates/*' diff --git a/Rookbook.yaml b/Rookbook.yaml index a0ad2db..d409bf2 100644 --- a/Rookbook.yaml +++ b/Rookbook.yaml @@ -128,7 +128,7 @@ recipes: end rm_f "#{dir}/test/Rookbook.yaml", "#{dir}/test/test.log" # - store 'benchmark/erubybench.{rb,rhtml,yaml}', 'benchmark/erubybench-lib.rb', dir + store 'benchmark/{bench.rb,bench_context.yaml}', 'benchmark/Makefile', dir # Dir.glob('examples/*').each { |d| chdir d do sys 'make clean' end } store 'examples/**/*', dir diff --git a/bin/notext b/bin/notext deleted file mode 100755 index 47e4bdd..0000000 --- a/bin/notext +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env ruby - -### -### notext - retrieve embedded code from eRuby, PHP, and so on -### -### $Rev$ -### $Release$ -### $Copyright$ -### - -require 'erubis' -require 'erubis/engine/eruby' -require 'erubis/engine/ephp' -require 'erubis/engine/ec' -require 'erubis/engine/ejava' -require 'erubis/engine/escheme' -require 'erubis/engine/eperl' -require 'erubis/engine/ejavascript' - - -def help() - command = File.basename($0) - s = <<END -#{command} - retrieve embedded code from eRuby, PHP, and so on. -Usage: #{command} [-hvncu] [-l lang] [-p pattern] file.php ... - -h : help - -v : version - -n : show line number - -c : compact mode (delete empty lines) - -u : uniq mode (compress repeated empty lines to a line) - -l lang : ruby/php/perl/c/java/scheme/javascript - -p pattern : embedded pattern (default '<% %>' or '<\\?(?:php|=|\\s) \\?>') -END - return s -end - - -## Engine classes which include NoTextEnhancer -klass_table = {} -lang_list = %w[ruby php c java scheme perl javascript] -lang_list.each do |lang| - eval <<-END - class NoTextE#{lang} < Erubis::E#{lang} - include Erubis::NoTextEnhancer - end - END - klass_table[lang] = Object.const_get("NoTextE#{lang}") -end - - -## parse command-line options -options = {} -properties = {} -while !ARGV.empty? && ARGV[0][0] == ?- - optstr = ARGV.shift - optstr = optstr.sub(/^-/, '') - while !optstr.empty? - optch = optstr[0] - optstr = optstr[1, optstr.length-1] - case optch - when ?h, ?v, ?n, ?c, ?u # help, version, linenum, compact, uniq - options[optch] = true - when ?l, ?p # lang, pattern - arg = !optstr.empty? ? optstr : ARGV.shift - unless arg - argnames = { ?l => 'lang name', ?p => 'pattern' } - $stderr.puts "-#{optch.chr}: #{argnames[optch]} required." - exit(1) - end - options[optch] = arg - else - $stderr.puts "-#{optch.chr}: unknown option." - exit(1) - end - end -end - -opt_help = options[?h] -opt_version = options[?v] -opt_linenum = options[?n] -opt_compact = options[?c] -opt_unique = options[?u] -opt_pattern = options[?p] -opt_lang = options[?l] - -if opt_lang - unless lang_list.include?(opt_lang) - $stderr.puts "-l #{opt_lang}: not supported." - exit(1) - end -end - - -## help message -if opt_help || opt_version - version = ('$Release: 0.0.0 $' =~ /[\.\d]+/) && $& - puts version if opt_version - puts help() if opt_help - exit(0) -end - - -## determine pattern -lang = opt_lang -unless lang - filename = ARGV[0] - if filename && filename =~ /\.(\w+)$/ - case suffix = $1 - when 'php', 'php5', 'inc' ; lang = 'php' - when 'ec' ; lang = 'c' - when 'ejava' ; lang = 'java' - when 'escheme', 'escm' ; lang = 'scheme' - when 'eperl' ; lang = 'perl' - when 'js', 'javascript' ; lang = 'javascript' - else ; lang = 'ruby' - end - else - lang = 'ruby' - end -end - - -## determine pattern -if opt_pattern - pattern = opt_pattern -else - case lang - when 'php' ; pattern = '<\?(?:php\b|(?==)|(?=\s)) \?>' - when 'perl' ; pattern = '<\?(?=\s|=) !>' - else ; pattern = '<% %>' - end -end - - -## read input and create engine -klass = klass_table[lang] -input = ARGF.read() -engine = klass.new(input, :pattern=>pattern, :trim=>false) - - -## print embedded code -n = 0 -prev_empty = false -engine.src.each_line do |line| - n += 1 - if line =~ /^\s*$/ - next if opt_compact || (opt_unique && prev_empty) - print opt_linenum && !opt_unique ? ("%3d: \n" % n) : "\n" - prev_empty = true - else - print opt_linenum ? ("%3d: %s" % [n, line]) : line - prev_empty = false - end -end diff --git a/doc/Rookbook.yaml b/doc/Rookbook.yaml index a404d52..5ae672c 100644 --- a/doc/Rookbook.yaml +++ b/doc/Rookbook.yaml @@ -74,6 +74,14 @@ recipes: sys "kwaser -t $(tagfile) #{@ingred} > #{@product}" rm "#{@byprod}" + - product: :test + ingreds: [ $(u).html ] + method*: | + currdir = Dir.pwd + chdir '../test' do + sys 'ruby test-users-guide.rb' + end + - product: notext.txt ingreds: [ ../test/test-notext.yaml, Rookbook.yaml ] desc: create 'notext.txt' from 'test-notext.yaml' diff --git a/doc/users-guide.html b/doc/users-guide.html index 72d031c..1a93a38 100644 --- a/doc/users-guide.html +++ b/doc/users-guide.html @@ -81,6 +81,8 @@ It has the following features. </li> <li><a href="#tut-pi">Processing Instruction (PI) Converter</a> </li> + <li><a href="#tut-notext">Retrieve Ruby Code</a> + </li> </ul> </li> <li><a href="#enhancer">Enhancer</a> @@ -145,10 +147,6 @@ It has the following features. </li> <li><a href="#topics-rails">Ruby on Rails Support</a> </li> - <li><a href="#topics-php">NoTextEnhancer and NoCodeEnhancer in PHP</a> - </li> - <li><a href="#topics-notext">Command <code>notext</code></a> - </li> <li><a href="#topics-benchmark">Benchmark</a> </li> </ul> @@ -967,6 +965,178 @@ example of Rails view template</div> <br> +<a name="tut-notext"></a> +<h3 class="section2">Retrieve Ruby Code</h3> +<p>Similar to '-x', ommand-line option '-X' shows converted Ruby source code. +The difference between '-x' and 'X' is that the former converts text part but the latter ignores it. +It means that you can retrieve Ruby code from eRuby script by '-X' option. +</p> +<p>For example, see the following eRuby script. +This is some complex, so it is difficult to grasp the program code. +</p> +<a name="example11.rhtml"></a> +<div class="program_caption"> +example11.rhtml</div> +<pre class="program"><?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <body> + <h3>List</h3> + <% if @list.nil? || @list.empty? %> + <p>not found.</p> + <% else %> + <table> + <tbody> + <% @list.each_with_index do |item, i| %> + <tr bgcolor="<%= i % 2 == 0 ? '#FCC' : '#CCF' %>"> + <td><%= item %></td> + </tr> + <% end %> + </tbody> + </table> + <% end %> + </body> +</html> +</pre> +<p>Command-line option '-X' extracts only the ruby code from eRuby script. +</p> +<a name="example11.result"></a> +<div class="terminal_caption"> +result</div> +<pre class="terminal">$ erubis <strong>-X</strong> example11.rhtml +_buf = ''; + + + + + + if @list.nil? || @list.empty? + + else + + + @list.each_with_index do |item, i| + _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + _buf << ( item ).to_s; + + end + + + end + + +_buf.to_s +</pre> +<p>Command-line option '-C' (<strong>c</strong>mpact) deletes empty lines. +</p> +<a name="example11_C.result"></a> +<div class="terminal_caption"> +result</div> +<pre class="terminal">$ erubis <strong>-XC</strong> example11.rhtml +_buf = ''; + if @list.nil? || @list.empty? + else + @list.each_with_index do |item, i| + _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + _buf << ( item ).to_s; + end + end +_buf.to_s +</pre> +<p>Option '-U' (<strong>u</strong>nique) converts empty lines into a line. +</p> +<a name="example11_U.result"></a> +<div class="terminal_caption"> +result</div> +<pre class="terminal">$ erubis <strong>-XU</strong> example11.rhtml +_buf = ''; + + if @list.nil? || @list.empty? + + else + + @list.each_with_index do |item, i| + _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + _buf << ( item ).to_s; + + end + + end + +_buf.to_s +</pre> +<p>Option '-N' (<strong>n</strong>umber) adds line number. +It is available with '-C' or '-U'. +</p> +<a name="example11_N.result"></a> +<div class="terminal_caption"> +result</div> +<pre class="terminal">$ erubis <strong>-XNU</strong> example11.rhtml + 1: _buf = ''; + + 7: if @list.nil? || @list.empty? + + 9: else + + 12: @list.each_with_index do |item, i| + 13: _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + 14: _buf << ( item ).to_s; + + 16: end + + 19: end + + 22: _buf.to_s +</pre> +<p>Command-line option '-X' is available with PHP script. +</p> +<a name="example11.php"></a> +<div class="program_caption"> +example11.php</div> +<pre class="program"><?xml version="1.0"?> +<html> + <body> + <h3>List</h3> + <?php if (!$list) { ?> + <p>not found.</p> + <?php } else { ?> + <table> + <tbody> + <?php $i = 0; ?> + <?php foreach ($list as $item) { ?> + <tr bgcolor="<?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?>"> + <td><?php echo $item; ?></td> + </tr> + <?php } ?> + </tbody> + </table> + <?php } ?> + </body> +</html> +</pre> +<a name="example11_php.result"></a> +<div class="terminal_caption"> +result</div> +<pre class="terminal">$ erubis -XNU <strong>-l php</strong> <strong>--pi=php</strong> --trim=false example11.php + + 5: <?php if (!$list) { ?> + + 7: <?php } else { ?> + + 10: <?php $i = 0; ?> + 11: <?php foreach ($list as $item) { ?> + 12: <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> + 13: <?php echo $item; ?> + + 15: <?php } ?> + + 18: <?php } ?> + +</pre> +<br> + + <br> @@ -2076,7 +2246,9 @@ document.write(_buf.join("")); <h2 class="section1">Other Topics</h2> <a name="topics-fasteruby"></a> <h3 class="section2">Class Erubis::FastEruby</h3> -<p>Erubis provides Erubis::FastEruby class which includes <a href="#interpolation-enhancer">InterpolationEnhancer</a> and works faster than Erubis::Eruby class. +<p>[experimental] +</p> +<p>Erubis provides Erubis::FastEruby class which includes <a href="#interpolation-enhancer">InterpolationEnhancer</a> and <a href="#topics-benchmark">works faster than Erubis::Eruby class</a>. If you desire more speed, try Erubis::FastEruby class. </p> <a name="fasteruby.rhtml"></a> @@ -2117,6 +2289,43 @@ print output <div class="terminal_caption"> output</div> <pre class="terminal">$ ruby fasteruby.rb +---------- script source --- +_buf = ''; _buf << <strong>%Q`</strong><html> + <body> + <h1><strong>#{Erubis::XmlHelper.escape_xml( @title )}</strong></h1> + <table>\n<strong>`</strong> + i = 0 + for item in @list + i += 1 + _buf << <strong>%Q`</strong> <tr> + <td><strong>#{ i }</strong></td> + <td><strong>#{Erubis::XmlHelper.escape_xml( item )}</strong></td> + </tr>\n<strong>`</strong> + end + _buf << <strong>%Q`</strong> </table> + </body> +</html>\n<strong>`</strong> +_buf.to_s +---------- result ---------- +<html> + <body> + <h1>Example</h1> + <table> + <tr> + <td>1</td> + <td>aaa</td> + </tr> + <tr> + <td>2</td> + <td>bbb</td> + </tr> + <tr> + <td>3</td> + <td>ccc</td> + </tr> + </table> + </body> +</html> </pre> <br> @@ -2231,189 +2440,6 @@ It is useful for debugging. <br> -<a name="topics-php"></a> -<h3 class="section2">NoTextEnhancer and NoCodeEnhancer in PHP</h3> -<p>NoTextEnhancer and NoCodEnahncer are quite useful not only for eRuby but also for PHP. -The former "drops" HTML text and show up embedded Ruby/PHP code -and the latter drops embedded Ruby/PHP code and leave HTML text. -</p> -<p>For example, see the following PHP script. -</p> -<a name="notext-example.php"></a> -<div class="program_caption"> -notext-example.php</div> -<pre class="program"><html> - <body> - <h3>List</h3> - <?php if (!$list || count($list) == 0) { ?> - <p>not found.</p> - <?php } else { ?> - <table> - <tbody> - <?php $i = 0; ?> - <?php foreach ($list as $item) { ?> - <tr bgcolor="<?php echo ++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'; ?>"> - <td><?php echo $item; ?></td> - </tr> - <?php } ?> - </tbody> - </table> - <?php } ?> - </body> -</html> -</pre> -<p>This is complex because PHP code and HTML document are mixed. -NoTextEnhancer can separate PHP code from HTML document. -</p> -<div class="terminal_caption"> -example of using NoTextEnhancer with PHP file</div> -<pre class="terminal">$ erubis -l php -E NoText -p '<\?php \?>' --trim=false notext-example.php | cat -n - 1 - 2 - 3 - 4 <?php if (!$list || count($list) == 0) { ?> - 5 - 6 <?php } else { ?> - 7 - 8 - 9 <?php $i = 0; ?> - 10 <?php foreach ($list as $item) { ?> - 11 <?php echo ++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'; ?> - 12 <?php echo $item; ?> - 13 - 14 <?php } ?> - 15 - 16 - 17 <?php } ?> - 18 - 19 -</pre> -<p>In the same way, NoCodeEnhancer can extract HTML tags. -</p> -<div class="terminal_caption"> -example of using NoCodeEnhancer with PHP file</div> -<pre class="terminal">$ erubis -l php -E NoCode -p '<\?php \?>' notext-example.php | cat -n - 1 <html> - 2 <body> - 3 <h3>List</h3> - 4 - 5 <p>not found.</p> - 6 - 7 <table> - 8 <tbody> - 9 - 10 - 11 <tr bgcolor=""> - 12 <td></td> - 13 </tr> - 14 - 15 </tbody> - 16 </table> - 17 - 18 </body> - 19 </html> -</pre> -<br> - - -<a name="topics-notext"></a> -<h3 class="section2">Command <code>notext</code></h3> -<p>Command 'notext' removes text part from eRuby script and leaves only embedded Ruby code. -This is very useful when debugging eRuby script. -</p> -<div class="program_caption"> -notext-ex.rhtml</div> -<pre class="program"><html> - <head> - <title>notext example</title> - </head> - <body> - <table> -<% @list.each_with_index do |item, i| %> -<% klass = i % 2 == 0 ? 'odd' : 'even' %> - <tr class="<%= klass %>"> - <td><%== item %></td> - </tr> -<% end %> - </table> - </body> -</html> -</pre> -<div class="terminal_caption"> -command line example</div> -<pre class="terminal">$ notext notext-ex.rhtml -_buf = ''; - - - - - - @list.each_with_index do |item, i| ; - klass = i % 2 == 0 ? 'odd' : 'even' ; - _buf << ( klass ).to_s; - _buf << Erubis::XmlHelper.escape_xml( item ); - - end ; - - -_buf.to_s -</pre> -<p>Command-line option '-u' deletes continuous empty lines to one empty line. -</p> -<div class="terminal_caption"> -command-line example</div> -<pre class="terminal">$ notext <strong>-u</strong> notext-ex.rhtml -_buf = ''; - - @list.each_with_index do |item, i| ; - klass = i % 2 == 0 ? 'odd' : 'even' ; - _buf << ( klass ).to_s; - _buf << Erubis::XmlHelper.escape_xml( item ); - - end ; - -_buf.to_s -</pre> -<p>Command-line option '-c' deletes all empty lines. -</p> -<div class="terminal_caption"> -command-line example</div> -<pre class="terminal">$ notext <strong>-c</strong> notext-ex.rhtml -_buf = ''; - @list.each_with_index do |item, i| ; - klass = i % 2 == 0 ? 'odd' : 'even' ; - _buf << ( klass ).to_s; - _buf << Erubis::XmlHelper.escape_xml( item ); - end ; -_buf.to_s -</pre> -<p>Command-line option '-n' shows line numbers. It can work with '-c' or '-u'. -</p> -<pre class="terminal">$ notext <strong>-nu</strong> example2.rhtml - 1: _buf = ''; - - 7: @list.each_with_index do |item, i| ; - 8: klass = i % 2 == 0 ? 'odd' : 'even' ; - 9: _buf << ( klass ).to_s; - 10: _buf << Erubis::XmlHelper.escape_xml( item ); - - 12: end ; - - 16: _buf.to_s -$ notext <strong>-nc</strong> example2.rhtml - 1: _buf = ''; - 7: @list.each_with_index do |item, i| ; - 8: klass = i % 2 == 0 ? 'odd' : 'even' ; - 9: _buf << ( klass ).to_s; - 10: _buf << Erubis::XmlHelper.escape_xml( item ); - 12: end ; - 16: _buf.to_s -</pre> -<p>Command 'notext' supports '-l <em>lang</em>' options. For example, command-line option '-l php' retrieves embedded PHP code from PHP file. -</p> -<br> - - <a name="topics-benchmark"></a> <h3 class="section2">Benchmark</h3> <p>A benchmark script is included in Erubis package at 'erubis-X.X.X/benchark/' directory. @@ -2421,20 +2447,21 @@ Here is an example result of benchmark. </p> <div class="terminal_caption"> MacOS X 10.4 Tiger, Intel CoreDuo 1.83GHz, Ruby1.8.5, eruby1.0.5, gcc4.0.1</div> -<pre class="terminal">$ cd erubis-2.2.0/benchmark/ -$ ruby erubybench.rb -n 10000 -m execute -## execute +<pre class="terminal">$ cd erubis-$Release$/benchmark/ +$ ruby bench.rb -n 10000 -m execute +*** ntimes=10000, testmode=execute user system total real -eruby 12.870000 0.290000 <strong>13.160000</strong> ( 14.020219) -ERB 37.090000 0.460000 <strong>37.550000</strong> ( 39.639027) -Erubis::Eruby 11.420000 0.330000 <strong>11.750000</strong> ( 12.385562) -Erubis::Eruby(cached) 7.580000 0.440000 <strong>8.020000</strong> ( 8.536019) -Erubis::ArrayBufferEruby 11.550000 0.340000 11.890000 ( 12.597665) -Erubis::SimplifiedEruby 10.410000 0.320000 10.730000 ( 11.406730) -Erubis::StdoutEruby 12.170000 0.340000 12.510000 ( 13.252177) -Erubis::PrintOutEruby 12.070000 0.330000 12.400000 ( 13.142734) -Erubis::TinyEruby 9.710000 0.320000 10.030000 ( 10.771446) -Erubis::PI::Eruby 12.010000 0.340000 12.350000 ( 13.104801) +ERuby 14.220000 0.270000 <strong>14.490000</strong> ( 14.498195) +ERB 39.960000 0.420000 <strong>40.380000</strong> ( 40.445606) +ERB(cached) 13.600000 0.470000 <strong>14.070000</strong> ( 14.087191) +Erubis::Eruby 11.970000 0.320000 <strong>12.290000</strong> ( 12.305445) +Erubis::Eruby(cached) 8.090000 0.430000 <strong>8.520000</strong> ( 8.541349) +Erubis::FastEruby 11.430000 0.320000 <strong>11.750000</strong> ( 11.754823) +Erubis::FastEruby(cached) 7.390000 0.430000 <strong>7.820000</strong> ( 7.828517) +Erubis::TinyEruby 10.340000 0.310000 10.650000 ( 10.659101) +Erubis::ArrayBufferEruby 12.150000 0.320000 12.470000 ( 12.497017) +Erubis::PrintOutEruby 12.750000 0.320000 13.070000 ( 13.099295) +Erubis::StdoutEruby 12.710000 0.320000 13.030000 ( 13.042235) </pre> <p>This shows that... </p> @@ -2445,6 +2472,8 @@ Erubis::PI::Eruby 12.010000 0.340000 12.350000 ( 13.104801) </li> <li>Caching (by Erubis::Eruby.load_file()) makes Erubis about 40-50 percent faster. </li> +<li>Erubis::FastEruby is a litte faster than Erubis::Eruby. +</li> <li>Array buffer (ArrayBufferEnhancer) is a little slower than string buffer (StringBufferEnhancer which Erubis::Eruby includes) </li> <li>$stdout and print() make Erubis a little slower. @@ -2458,19 +2487,19 @@ The following shows that Erubis runs more than 30 percent faster than eruby if H </p> <div class="terminal_caption"> When escaping HTML characters with option '-e'</div> -<pre class="terminal">$ ruby erubybench.rb -n 10000 -m execute -e -## execute +<pre class="terminal">$ ruby bench.rb -n 10000 -m execute -ep +*** ntimes=10000, testmode=execute user system total real -eruby 22.730000 0.350000 <strong>23.080000</strong> ( 24.815081) -ERB 46.590000 0.520000 <strong>47.110000</strong> ( 50.360891) -Erubis::Eruby 16.750000 0.360000 <strong>17.110000</strong> ( 18.253436) -Erubis::Eruby(cached) 12.540000 0.450000 <strong>12.990000</strong> ( 13.935044) -Erubis::ArrayBufferEruby 16.860000 0.370000 17.230000 ( 18.373771) -Erubis::SimplifiedEruby 15.750000 0.350000 16.100000 ( 17.344105) -Erubis::StdoutEruby 17.650000 0.360000 18.010000 ( 19.194326) -Erubis::PrintOutEruby 17.560000 0.360000 17.920000 ( 19.293728) -Erubis::TinyEruby 16.300000 0.350000 16.650000 ( 17.887278) -Erubis::PI::Eruby 17.210000 0.360000 17.570000 ( 18.836510) +eruby 21.500000 0.320000 <strong>21.820000</strong> ( 21.930308) +ERB 45.280000 0.500000 <strong>45.780000</strong> ( 46.101839) +ERB(cached) 20.230000 0.520000 <strong>20.750000</strong> ( 20.913674) +Erubis::Eruby 15.070000 0.340000 <strong>15.410000</strong> ( 15.541843) +Erubis::Eruby(cached) 11.260000 0.450000 <strong>11.710000</strong> ( 11.774822) +Erubis::FastEruby 15.100000 0.340000 15.440000 ( 15.532790) +Erubis::FastEruby(cached) 11.160000 0.460000 11.620000 ( 11.704288) +Erubis::ArrayBufferEruby 15.260000 0.350000 15.610000 ( 15.785612) +Erubis::PrintOutEruby 15.960000 0.330000 16.290000 ( 16.392182) +Erubis::StdoutEruby 16.030000 0.340000 16.370000 ( 16.461998) </pre> <br> @@ -2506,17 +2535,38 @@ Erubis::PI::Eruby 17.210000 0.360000 17.570000 ( 18.836510) Show compiled source. </dd> <dt class="dt3"><b> --z </b></dt> +-X </b></dt> <dd class="dd3"> - Syntax checking. + Show compiled source but only Ruby code. + This is equivarent to '-E NoText'. + </dd> + <dt class="dt3"><b> +-N </b></dt> + <dd class="dd3"> + Numbering: add line numbers. (for '-x/-X') + </dd> + <dt class="dt3"><b> +-U </b></dt> + <dd class="dd3"> + Unique mode: zip empty lines into a line. (for '-x/-X') + </dd> + <dt class="dt3"><b> +-C </b></dt> + <dd class="dd3"> + Compact: remove empty lines. (for '-x/-X') </dd> <dt class="dt3"><b> -b </b></dt> <dd class="dd3"> - Body only (no preamble nor postamble). + Body only: no preamble nor postamble. (for '-x/-X') This is equivarent to '--preamble=false --postamble=false'. </dd> <dt class="dt3"><b> +-z </b></dt> + <dd class="dd3"> + Syntax checking. + </dd> + <dt class="dt3"><b> -e </b></dt> <dd class="dd3"> Escape. This is equivarent to '-E Escape'. diff --git a/doc/users-guide.txt b/doc/users-guide.txt index 984c78c..16a5c12 100644 --- a/doc/users-guide.txt +++ b/doc/users-guide.txt @@ -853,6 +853,229 @@ _buf.to_s +.$$ Retrieve Ruby Code | tut-notext + +Similar to '-x', ommand-line option '-X' shows converted Ruby source code. +The difference between '-x' and 'X' is that the former converts text part but the latter ignores it. +It means that you can retrieve Ruby code from eRuby script by '-X' option. + +.#Command 'notext' is a utility to extract only program code from eRuby/PHP/ePerl script. +.#It is an application of NoTextEnhancer. + +For example, see the following eRuby script. +This is some complex, so it is difficult to grasp the program code. + +.? example11.rhtml +.-------------------- example11.rhtml +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <body> + <h3>List</h3> + <% if @list.nil? || @list.empty? %> + <p>not found.</p> + <% else %> + <table> + <tbody> + <% @list.each_with_index do |item, i| %> + <tr bgcolor="<%= i % 2 == 0 ? '#FCC' : '#CCF' %>"> + <td><%= item %></td> + </tr> + <% end %> + </tbody> + </table> + <% end %> + </body> +</html> +.-------------------- + +Command-line option '-X' extracts only the ruby code from eRuby script. + +.? result +.==================== example11.result +$ erubis {{*-X*}} example11.rhtml +_buf = ''; + + + + + + if @list.nil? || @list.empty? + + else + + + @list.each_with_index do |item, i| + _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + _buf << ( item ).to_s; + + end + + + end + + +_buf.to_s +.==================== + +Command-line option '-C' ({{*c*}}mpact) deletes empty lines. + +.? result +.==================== example11_C.result +$ erubis {{*-XC*}} example11.rhtml +_buf = ''; + if @list.nil? || @list.empty? + else + @list.each_with_index do |item, i| + _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + _buf << ( item ).to_s; + end + end +_buf.to_s +.==================== + +Option '-U' ({{*u*}}nique) converts empty lines into a line. + +.? result +.==================== example11_U.result +$ erubis {{*-XU*}} example11.rhtml +_buf = ''; + + if @list.nil? || @list.empty? + + else + + @list.each_with_index do |item, i| + _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + _buf << ( item ).to_s; + + end + + end + +_buf.to_s +.==================== + +Option '-N' ({{*n*}}umber) adds line number. +It is available with '-C' or '-U'. + +.? result +.==================== example11_N.result +$ erubis {{*-XNU*}} example11.rhtml + 1: _buf = ''; + + 7: if @list.nil? || @list.empty? + + 9: else + + 12: @list.each_with_index do |item, i| + 13: _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; + 14: _buf << ( item ).to_s; + + 16: end + + 19: end + + 22: _buf.to_s +.==================== + +Command-line option '-X' is available with PHP script. +.#Language is automatically detected by suffix of filename. +.#And you can specify language with option '-l' ({{*l*}}anguage). + +.? example11.php +.-------------------- example11.php +<?xml version="1.0"?> +<html> + <body> + <h3>List</h3> + <?php if (!$list) { ?> + <p>not found.</p> + <?php } else { ?> + <table> + <tbody> + <?php $i = 0; ?> + <?php foreach ($list as $item) { ?> + <tr bgcolor="<?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?>"> + <td><?php echo $item; ?></td> + </tr> + <?php } ?> + </tbody> + </table> + <?php } ?> + </body> +</html> +.-------------------- + +.? result +.==================== example11_php.result +$ erubis -XNU {{*-l php*}} {{*--pi=php*}} --trim=false example11.php + + 5: <?php if (!$list) { ?> + + 7: <?php } else { ?> + + 10: <?php $i = 0; ?> + 11: <?php foreach ($list as $item) { ?> + 12: <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> + 13: <?php echo $item; ?> + + 15: <?php } ?> + + 18: <?php } ?> + +.==================== + +.# +.#.? example11.eperl +.#.-------------------- example11.eperl +.#<?xml version="1.0"?> +.#<html> +.# <body> +.# <h3>List</h3> +.# <? if (!@list) { !> +.# <p>not found.</p> +.# <? } else { !> +.# <table> +.# <tbody> +.# <? $i = 0; !> +.# <? foreach ($item in @list) { !> +.# <tr bgcolor="<?= ++$i % 2 == 1 ? '#FCC' : '#CCF' !>"> +.# <td><?= $item !></td> +.# </tr> +.# <? } !> +.# </tbody> +.# </table> +.# <? } !> +.# </body> +.#</html> +.#.chomp +.#.-------------------- +.# +.#.? result +.#.==================== example11_eperl.result +.#$ erubis -XNU -l perl example11.eperl +.# 1: use HTML::Entities; +.# +.# 5: if (!@list) { +.# +.# 7: } else { +.# +.# 10: $i = 0; +.# 11: foreach ($item in @list) { +.# 12: print(++$i % 2 == 1 ? '#FCC' : '#CCF'); +.# 13: print($item); +.# +.# 15: } +.# +.# 18: } +.# +.#.==================== +.# + + + .$ Enhancer | enhancer Enhancer is a module to add a certain feature into Erubis::Eruby class. @@ -2322,191 +2545,20 @@ It is useful for debugging. -.$$ NoTextEnhancer and NoCodeEnhancer in PHP | topics-php - -NoTextEnhancer and NoCodEnahncer are quite useful not only for eRuby but also for PHP. -The former "drops" HTML text and show up embedded Ruby/PHP code -and the latter drops embedded Ruby/PHP code and leave HTML text. - -For example, see the following PHP script. - -.? notext-example.php -.-------------------- notext-example.php -<html> - <body> - <h3>List</h3> - <?php if (!$list || count($list) == 0) { ?> - <p>not found.</p> - <?php } else { ?> - <table> - <tbody> - <?php $i = 0; ?> - <?php foreach ($list as $item) { ?> - <tr bgcolor="<?php echo ++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'; ?>"> - <td><?php echo $item; ?></td> - </tr> - <?php } ?> - </tbody> - </table> - <?php } ?> - </body> -</html> -.-------------------- - -This is complex because PHP code and HTML document are mixed. -NoTextEnhancer can separate PHP code from HTML document. - -.? example of using NoTextEnhancer with PHP file -.==================== -$ erubis -l php -E NoText -p '<\?php \?>' --trim=false notext-example.php | cat -n -.<<<:! erubis -l php -E NoText -p '<\?php \?>' --trim=false guide.d/notext-example.php | cat -n -.==================== - -In the same way, NoCodeEnhancer can extract HTML tags. - -.? example of using NoCodeEnhancer with PHP file -.==================== -$ erubis -l php -E NoCode -p '<\?php \?>' notext-example.php | cat -n -.<<<:! erubis -l php -E NoCode -p '<\?php \?>' guide.d/notext-example.php | cat -n -.==================== - - - -.# -.#.$$ Command 'notext' | cmd-notext +.#.$$ NoTextEnhancer and NoCodeEnhancer in PHP | topics-php .# -.#Command 'notext' is a utility to extract only program code from eRuby/PHP/ePerl script. -.#It is an application of NoTextEnhancer. -.# -.#For example, see the following eRuby script. -.#This is some complex, so it is difficult to grasp the program code. -.# -.#.? ex-notext.rhtml -.#.-------------------- ex-notext.rhtml -.#<?xml version="1.0" encoding="UTF-8"?> -.#<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" -.# "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -.#<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -.# <body> -.# <h3>List</h3> -.# <% if @list.nil? || @list.empty? %> -.# <p>not found.</p> -.# <% else %> -.# <table> -.# <tbody> -.# <% @list.each_with_index do |item, i| %> -.# <tr bgcolor="<%= i % 2 == 0 ? '#FCC' : '#CCF' %>"> -.# <td><%= item %></td> -.# </tr> -.# <% end %> -.# </tbody> -.# </table> -.# <% end %> -.# </body> -.#</html> -.#.-------------------- -.# -.#Command 'notext' extracts the ruby code from eRuby script. -.# -.#.? result -.#.==================== notext_eruby.output -.#$ notext ex-notext.rhtml -.#_buf = ''; -.# -.# -.# -.# -.# -.# if @list.nil? || @list.empty? ; -.# -.# else ; -.# -.# -.# @list.each_with_index do |item, i| ; -.# _buf << ( i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' ).to_s; -.# _buf << ( item ).to_s; -.# -.# end ; -.# -.# -.# end ; -.# -.# -.#_buf.to_s -.#.==================== +.#NoTextEnhancer and NoCodEnahncer are quite useful not only for eRuby but also for PHP. +.#The former "drops" HTML text and show up embedded Ruby/PHP code +.#and the latter drops embedded Ruby/PHP code and leave HTML text. .# -.#Option '-c' ({{*c*}}ompact) deletes empty lines. +.#For example, see the following PHP script. .# -.#.? result -.#.==================== notext_eruby_c.output -.#$ notext -c ex-notext.rhtml -.#_buf = ''; -.# if @list.nil? || @list.empty? ; -.# else ; -.# @list.each_with_index do |item, i| ; -.# _buf << ( i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' ).to_s; -.# _buf << ( item ).to_s; -.# end ; -.# end ; -.#_buf.to_s -.#.==================== -.# -.#Option '-u' ({{*u*}}nique) replace some empty lines with a empty line. -.# -.#.? result -.#.==================== notext_eruby_u.output -.#$ notext -u ex-notext.rhtml -.#_buf = ''; -.# -.# if @list.nil? || @list.empty? ; -.# -.# else ; -.# -.# @list.each_with_index do |item, i| ; -.# _buf << ( i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' ).to_s; -.# _buf << ( item ).to_s; -.# -.# end ; -.# -.# end ; -.# -.#_buf.to_s -.#.==================== -.# -.#Option '-n' ({{*n*}}umber) adds line number. -.#It is available with '-c' or '-n'. -.# -.#.? result -.#.==================== notext_eruby_nu.output -.#$ notext -nu ex-notext.rhtml -.# 1: _buf = ''; -.# -.# 10: if @list.nil? || @list.empty? ; -.# -.# 12: else ; -.# -.# 15: @list.each_with_index do |item, i| ; -.# 16: _buf << ( i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' ).to_s; -.# 17: _buf << ( item ).to_s; -.# -.# 19: end ; -.# -.# 22: end ; -.# -.# 25: _buf.to_s -.#.==================== -.# -.#'notext' is available with PHP or ePerl script. -.#Language is automatically detected by suffix of filename. -.#And you can specify language with option '-l' ({{*l*}}anguage). -.# -.#.? ex-notext.php -.#.-------------------- notext_php.input -.#<?xml version="1.0"?> +.#.? notext-example.php +.#.-------------------- notext-example.php .#<html> .# <body> .# <h3>List</h3> -.# <?php if (!$list) { ?> +.# <?php if (!$list || count($list) == 0) { ?> .# <p>not found.</p> .# <?php } else { ?> .# <table> @@ -2524,172 +2576,22 @@ $ erubis -l php -E NoCode -p '<\?php \?>' notext-example.php | cat -n .#</html> .#.-------------------- .# -.#.? result -.#.==================== notext_php_nu.output -.#$ notext -nu ex-notext.php -.# -.# 5: <?php if (!$list) { ?> -.# -.# 7: <?php } else { ?> -.# -.# 10: <?php $i = 0; ?> -.# 11: <?php foreach ($list as $item) { ?> -.# 12: <?php echo ++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'; ?> -.# 13: <?php echo $item; ?> -.# -.# 15: <?php } ?> -.# -.# 18: <?php } ?> +.#This is complex because PHP code and HTML document are mixed. +.#NoTextEnhancer can separate PHP code from HTML document. .# +.#.? example of using NoTextEnhancer with PHP file +.#.==================== +.#$ erubis -l php -E NoText -p '<\?php \?>' --trim=false notext-example.php | cat -n +.#.<<<:! erubis -l php -E NoText -p '<\?php \?>' --trim=false guide.d/notext-example.php | cat -n .#.==================== .# -.#.? ex-notext.eperl -.#.-------------------- notext_eperl.input -.#<?xml version="1.0"?> -.#<html> -.# <body> -.# <h3>List</h3> -.# <? if (!@list) { !> -.# <p>not found.</p> -.# <? } else { !> -.# <table> -.# <tbody> -.# <? $i = 0; !> -.# <? foreach ($item in @list) { !> -.# <tr bgcolor="<?= ++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF' !>"> -.# <td><?= $item !></td> -.# </tr> -.# <? } !> -.# </tbody> -.# </table> -.# <? } !> -.# </body> -.#</html> -.#.chomp -.#.-------------------- -.# -.#.? result -.#.==================== notext_eperl_nu.output -.#$ notext -nul eperl ex-notext.eperl -.# 1: use HTML::Entities; -.# -.# 5: if (!@list) { -.# -.# 7: } else { -.# -.# 10: $i = 0; -.# 11: foreach ($item in @list) { -.# 12: print(++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'); -.# 13: print($item); -.# -.# 15: } -.# -.# 18: } +.#In the same way, NoCodeEnhancer can extract HTML tags. .# +.#.? example of using NoCodeEnhancer with PHP file +.#.==================== +.#$ erubis -l php -E NoCode -p '<\?php \?>' notext-example.php | cat -n +.#.<<<:! erubis -l php -E NoCode -p '<\?php \?>' guide.d/notext-example.php | cat -n .#.==================== -.# - - -.$$ Command {{,notext,}} | topics-notext - -Command 'notext' removes text part from eRuby script and leaves only embedded Ruby code. -This is very useful when debugging eRuby script. - -.? notext-ex.rhtml -.-------------------- -<html> - <head> - <title>notext example</title> - </head> - <body> - <table> -<% @list.each_with_index do |item, i| %> -<% klass = i % 2 == 0 ? 'odd' : 'even' %> - <tr class="<%= klass %>"> - <td><%== item %></td> - </tr> -<% end %> - </table> - </body> -</html> -.-------------------- - -.? command line example -.==================== -$ notext notext-ex.rhtml -_buf = ''; - - - - - - @list.each_with_index do |item, i| ; - klass = i % 2 == 0 ? 'odd' : 'even' ; - _buf << ( klass ).to_s; - _buf << Erubis::XmlHelper.escape_xml( item ); - - end ; - - -_buf.to_s -.==================== - -Command-line option '-u' deletes continuous empty lines to one empty line. - -.? command-line example -.==================== -$ notext {{*-u*}} notext-ex.rhtml -_buf = ''; - - @list.each_with_index do |item, i| ; - klass = i % 2 == 0 ? 'odd' : 'even' ; - _buf << ( klass ).to_s; - _buf << Erubis::XmlHelper.escape_xml( item ); - - end ; - -_buf.to_s -.==================== - -Command-line option '-c' deletes all empty lines. - -.? command-line example -.==================== -$ notext {{*-c*}} notext-ex.rhtml -_buf = ''; - @list.each_with_index do |item, i| ; - klass = i % 2 == 0 ? 'odd' : 'even' ; - _buf << ( klass ).to_s; - _buf << Erubis::XmlHelper.escape_xml( item ); - end ; -_buf.to_s -.==================== - -Command-line option '-n' shows line numbers. It can work with '-c' or '-u'. - -.==================== -$ notext {{*-nu*}} example2.rhtml - 1: _buf = ''; - - 7: @list.each_with_index do |item, i| ; - 8: klass = i % 2 == 0 ? 'odd' : 'even' ; - 9: _buf << ( klass ).to_s; - 10: _buf << Erubis::XmlHelper.escape_xml( item ); - - 12: end ; - - 16: _buf.to_s -$ notext {{*-nc*}} example2.rhtml - 1: _buf = ''; - 7: @list.each_with_index do |item, i| ; - 8: klass = i % 2 == 0 ? 'odd' : 'even' ; - 9: _buf << ( klass ).to_s; - 10: _buf << Erubis::XmlHelper.escape_xml( item ); - 12: end ; - 16: _buf.to_s -.==================== - -Command 'notext' supports '-l {{/lang/}}' options. For example, command-line option '-l php' retrieves embedded PHP code from PHP file. @@ -2849,11 +2751,16 @@ erubis [..options..] [{{/file/}} ...] .[ -h, --help ] Help. .[ -v ] Release version. .[ -x ] Show compiled source. + .[ -X ] Show compiled source but only Ruby code. + This is equivarent to '-E NoText'. + .[ -N ] Numbering: add line numbers. (for '-x/-X') + .[ -U ] Unique mode: zip empty lines into a line. (for '-x/-X') + .[ -C ] Compact: remove empty lines. (for '-x/-X') + .[ -b ] Body only: no preamble nor postamble. (for '-x/-X') + This is equivarent to '--preamble=false --postamble=false'. .[ -z ] Syntax checking. .# .[ -T ] No trimming spaces around '<% %>'. .# This is equivarent to '--trim=false'. - .[ -b ] Body only (no preamble nor postamble). - This is equivarent to '--preamble=false --postamble=false'. .[ -e ] Escape. This is equivarent to '-E Escape'. .[ -p pattern ] Embedded pattern (default '<% %>'). This is equivarent to '--pattern={{/pattern/}}'. diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb index 942f110..c7e125c 100644 --- a/lib/erubis/enhancer.rb +++ b/lib/erubis/enhancer.rb @@ -562,14 +562,14 @@ module Erubis ## - ## convert "<h1><%= title %></h1>" into "_buf << %Q`<h1>#{ title }</h1>`" + ## convert "<h1><%=title%></h1>" into "_buf << %Q`<h1>#{title}</h1>`" ## ## this is only for Eruby. ## module InterpolationEnhancer def self.desc # :nodoc: - "convert '<p><%= text %></p>' into '_buf << %Q`<p>\#{text}</p>`'" + "convert '<p><%=text%></p>' into '_buf << %Q`<p>\#{text}</p>`'" end def convert_input(src, input) diff --git a/lib/erubis/main.rb b/lib/erubis/main.rb index 9f1e554..a0c601a 100644 --- a/lib/erubis/main.rb +++ b/lib/erubis/main.rb @@ -49,8 +49,8 @@ module Erubis end def initialize - @single_options = "hvxztSbeB" - @arg_options = "pcrfKIlaEC" + @single_options = "hvxztSbeBXNUC" + @arg_options = "pcrfKIlaE" #C @option_names = { ?h => :help, ?v => :version, @@ -63,7 +63,7 @@ module Erubis ?B => :binding, ?p => :pattern, ?c => :context, - ?C => :class, + #?C => :class, ?e => :escape, ?r => :requires, ?f => :datafiles, @@ -72,6 +72,10 @@ module Erubis ?l => :lang, ?a => :action, ?E => :enhancers, + ?X => :notext, + ?N => :linenum, + ?U => :unique, + ?C => :compact, } assert unless @single_options.length + @arg_options.length == @option_names.length (@single_options + @arg_options).each_byte do |ch| @@ -115,14 +119,15 @@ module Erubis ## action action = opts.action action ||= 'syntax' if opts.syntax - action ||= 'convert' if opts.source + action ||= 'convert' if opts.source || opts.notext ## lang lang = opts.lang || 'ruby' action ||= 'convert' if opts.lang ## class name of Eruby - classname = opts.class + #classname = opts.class + classname = nil klass = get_classobj(classname, lang, properties[:pi]) ## kanji code @@ -153,6 +158,9 @@ module Erubis engine.bipattern = properties[:bipattern] if enhancer == Erubis::BiPatternEnhancer end + ## no-text + engine.extend(Erubis::NoTextEnhancer) if opts.notext + ## convert and execute val = nil msg = "Syntax OK\n" @@ -179,7 +187,7 @@ module Erubis def do_action(action, engine, context, filename, opts) case action when 'convert' - s = engine.src + s = manipulate_src(engine.src, opts) when nil, 'exec', 'execute' s = opts.binding ? engine.result(context.to_hash) : engine.evaluate(context) when 'syntax' @@ -191,6 +199,22 @@ module Erubis return s end + def manipulate_src(source, opts) + flag_linenum = opts.linenum + flag_unique = opts.unique + flag_compact = opts.compact + if flag_linenum + n = 0 + source.gsub!(/^/) { n += 1; "%5d: " % n } + source.gsub!(/^ *\d+:\s+?\n/, '') if flag_compact + source.gsub!(/(^ *\d+:\s+?\n)+/, "\n") if flag_unique + else + source.gsub!(/^\s*?\n/, '') if flag_compact + source.gsub!(/(^\s*?\n)+/, "\n") if flag_unique + end + return source + end + def usage command = File.basename($0) s = <<END @@ -199,8 +223,12 @@ Usage: #{command} [..options..] [file ...] -h, --help : help -v : version -x : show converted code + -X : show converted code, only ruby code and no text part + -N : numbering: add line numbers (for '-x/-X') + -U : unique: zip empty lines to a line (for '-x/-X') + -C : compact: remove empty lines (for '-x/-X') + -b : body only: no preamble nor postamble (for '-x/-X') -z : syntax checking - -b : body only (no preamble nor postamble) -e : escape (equal to '--E Escape') -p pattern : embedded pattern (default '<% %>') -l lang : convert but no execute (ruby/php/c/java/scheme/perl/js) @@ -209,7 +237,7 @@ Usage: #{command} [..options..] [file ...] -K kanji : kanji code (euc/sjis/utf8) (default none) -c context : context data string (yaml inline style or ruby code) -f datafile : context data file ('*.yaml', '*.yml', or '*.rb') - -t : expand tab character in YAML file + -t : expand tab characters in YAML file -S : convert mapping key from string to symbol in YAML file -B : invoke 'result(binding)' instead of 'evaluate(context)' --pi=name : parse '<?name ... ?>' instead of '<% ... %>' diff --git a/test/test-main.rb b/test/test-main.rb index a918287..d3b672e 100644 --- a/test/test-main.rb +++ b/test/test-main.rb @@ -264,12 +264,12 @@ END end - def test_class1 # -C - @input = INPUT - @expected = OUTPUT.gsub(/<aaa>/, '<aaa>').gsub(/b&b/, 'b&b').gsub(/"ccc"/, '"ccc"') - @options = "-C XmlEruby" - _test() - end +# def test_class1 # -C +# @input = INPUT +# @expected = OUTPUT.gsub(/<aaa>/, '<aaa>').gsub(/b&b/, 'b&b').gsub(/"ccc"/, '"ccc"') +# @options = "-C XmlEruby" +# _test() +# end def test_notrim1 # --trim=false diff --git a/test/test-notext.rb b/test/test-notext.rb deleted file mode 100644 index 05ed2a1..0000000 --- a/test/test-notext.rb +++ /dev/null @@ -1,27 +0,0 @@ -## -## $Rev$ -## $Release$ -## $Copyright$ -## - -require File.dirname(__FILE__) + '/test' - - -class NoTextTest < Test::Unit::TestCase - - filename = __FILE__.sub(/\.\w+$/, '.yaml') - testdata_list = load_yaml_datafile(filename) - define_testmethods(testdata_list) - - def _test - File.open(@filename, 'w') { |f| f.write(@input) } - begin - result = `notext #{@options} #{@filename}` - expected = @output.gsub(/^\./, '') - assert_text_equal(expected, result) - ensure - File.unlink @filename if test(?f, @filename) - end - end - -end diff --git a/test/test-notext.yaml b/test/test-notext.yaml deleted file mode 100644 index c9e5dcf..0000000 --- a/test/test-notext.yaml +++ /dev/null @@ -1,504 +0,0 @@ ---- -- name: notext_eruby - options: '' - filename: ex-notext.rhtml - document: | - - .$$ Command 'notext' | cmd-notext - - Command 'notext' is a utility to extract only program code from eRuby/PHP/ePerl script. - It is an application of NoTextEnhancer. - - For example, see the following eRuby script. - This is some complex, so it is difficult to grasp the program code. - - .? ex-notext.rhtml - .-------------------- ex-notext.rhtml - [%= ydoc['notext_eruby']['input'].chomp %] - .-------------------- - - Command 'notext' extracts the ruby code from eRuby script. - - .? result - .==================== notext_eruby.output - $ notext ex-notext.rhtml - [%= ydoc['notext_eruby']['output'].chomp %] - .==================== - - Option '-c' ({{*c*}}ompact) deletes empty lines. - - .? result - .==================== notext_eruby_c.output - $ notext -c ex-notext.rhtml - [%= ydoc['notext_eruby_c']['output'].chomp %] - .==================== - - Option '-u' ({{*u*}}nique) replace some empty lines with a empty line. - - .? result - .==================== notext_eruby_u.output - $ notext -u ex-notext.rhtml - [%= ydoc['notext_eruby_u']['output'].chomp %] - .==================== - - Option '-n' ({{*n*}}umber) adds line number. - It is available with '-c' or '-n'. - - .? result - .==================== notext_eruby_nu.output - $ notext -nu ex-notext.rhtml - [%= ydoc['notext_eruby_nu']['output'].chomp %] - .==================== - - 'notext' is available with PHP or ePerl script. - Language is automatically detected by suffix of filename. - And you can specify language with option '-l' ({{*l*}}anguage). - - .? ex-notext.php - .-------------------- notext_php.input - [%= ydoc['notext_php']['input'].chomp %] - .-------------------- - - .? result - .==================== notext_php_nu.output - $ notext -nu ex-notext.php - [%= ydoc['notext_php_nu']['output'].chomp %] - .==================== - - .? ex-notext.eperl - .-------------------- notext_eperl.input - [%= ydoc['notext_eperl']['input'] %].chomp - .-------------------- - - .? result - .==================== notext_eperl_nu.output - $ notext -nul eperl ex-notext.eperl - [%= ydoc['notext_eperl_nu']['output'].chomp %] - .==================== - - input: &input_eruby | - <?xml version="1.0" encoding="UTF-8"?> - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <body> - <h3>List</h3> - <% if @list.nil? || @list.empty? %> - <p>not found.</p> - <% else %> - <table> - <tbody> - <% @list.each_with_index do |item, i| %> - <tr bgcolor="<%= i % 2 == 0 ? '#FCC' : '#CCF' %>"> - <td><%= item %></td> - </tr> - <% end %> - </tbody> - </table> - <% end %> - </body> - </html> - output: | - ._buf = ''; - . - . - . - . - . - . if @list.nil? || @list.empty? ; - . - . else ; - . - . - . @list.each_with_index do |item, i| ; - . _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; - . _buf << ( item ).to_s; - . - . end ; - . - . - . end ; - . - . - ._buf.to_s - -## -- name: notext_eruby_n - options: '-n' - filename: ex-notext.rhtml - input: *input_eruby - output: | - . 1: _buf = ''; - . 2: - . 3: - . 4: - . 5: - . 6: - . 7: if @list.nil? || @list.empty? ; - . 8: - . 9: else ; - . 10: - . 11: - . 12: @list.each_with_index do |item, i| ; - . 13: _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; - . 14: _buf << ( item ).to_s; - . 15: - . 16: end ; - . 17: - . 18: - . 19: end ; - . 20: - . 21: - . 22: _buf.to_s - -## -- name: notext_eruby_c - options: '-c' - filename: ex-notext.rhtml - input: *input_eruby - output: | - ._buf = ''; - . if @list.nil? || @list.empty? ; - . else ; - . @list.each_with_index do |item, i| ; - . _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; - . _buf << ( item ).to_s; - . end ; - . end ; - ._buf.to_s - -## -- name: notext_eruby_u - options: '-u' - filename: ex-notext.rhtml - input: &input_eruby | - <?xml version="1.0" encoding="UTF-8"?> - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <body> - <h3>List</h3> - <% if @list.nil? || @list.empty? %> - <p>not found.</p> - <% else %> - <table> - <tbody> - <% @list.each_with_index do |item, i| %> - <tr bgcolor="<%= i % 2 == 0 ? '#FCC' : '#CCF' %>"> - <td><%= item %></td> - </tr> - <% end %> - </tbody> - </table> - <% end %> - </body> - </html> - output: | - ._buf = ''; - . - . if @list.nil? || @list.empty? ; - . - . else ; - . - . @list.each_with_index do |item, i| ; - . _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; - . _buf << ( item ).to_s; - . - . end ; - . - . end ; - . - ._buf.to_s - -## -- name: notext_eruby_nc - options: '-nc' - filename: ex-notext.rhtml - input: *input_eruby - output: | - . 1: _buf = ''; - . 7: if @list.nil? || @list.empty? ; - . 9: else ; - . 12: @list.each_with_index do |item, i| ; - . 13: _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; - . 14: _buf << ( item ).to_s; - . 16: end ; - . 19: end ; - . 22: _buf.to_s - -## -- name: notext_eruby_nu - options: '-un' - filename: ex-notext.rhtml - input: *input_eruby - output: | - . 1: _buf = ''; - . - . 7: if @list.nil? || @list.empty? ; - . - . 9: else ; - . - . 12: @list.each_with_index do |item, i| ; - . 13: _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s; - . 14: _buf << ( item ).to_s; - . - . 16: end ; - . - . 19: end ; - . - . 22: _buf.to_s -## ---- -- name: notext_php - options: '' - filename: ex-notext.php - input: &input_php | - <?xml version="1.0"?> - <html> - <body> - <h3>List</h3> - <?php if (!$list) { ?> - <p>not found.</p> - <?php } else { ?> - <table> - <tbody> - <?php $i = 0; ?> - <?php foreach ($list as $item) { ?> - <tr bgcolor="<?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?>"> - <td><?php echo $item; ?></td> - </tr> - <?php } ?> - </tbody> - </table> - <?php } ?> - </body> - </html> - output: &output_php | - . - . - . - . - . <?php if (!$list) { ?> - . - . <?php } else { ?> - . - . - . <?php $i = 0; ?> - . <?php foreach ($list as $item) { ?> - . <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> - . <?php echo $item; ?> - . - . <?php } ?> - . - . - . <?php } ?> - . - . - -## -- name: notext_php_n - options: '-n' - filename: ex-notext.php - input: *input_php - output: &output_php | - . 1: - . 2: - . 3: - . 4: - . 5: <?php if (!$list) { ?> - . 6: - . 7: <?php } else { ?> - . 8: - . 9: - . 10: <?php $i = 0; ?> - . 11: <?php foreach ($list as $item) { ?> - . 12: <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> - . 13: <?php echo $item; ?> - . 14: - . 15: <?php } ?> - . 16: - . 17: - . 18: <?php } ?> - . 19: - . 20: - -## -- name: notext_php_c - options: '-c' - filename: ex-notext.php - input: *input_php - output: &output_php | - . <?php if (!$list) { ?> - . <?php } else { ?> - . <?php $i = 0; ?> - . <?php foreach ($list as $item) { ?> - . <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> - . <?php echo $item; ?> - . <?php } ?> - . <?php } ?> - -## -- name: notext_php_u - options: '-u' - filename: ex-notext.php - input: *input_php - output: &output_php | - . - . <?php if (!$list) { ?> - . - . <?php } else { ?> - . - . <?php $i = 0; ?> - . <?php foreach ($list as $item) { ?> - . <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> - . <?php echo $item; ?> - . - . <?php } ?> - . - . <?php } ?> - . - -## -- name: notext_php_nc - options: '-nc' - filename: ex-notext.php - input: *input_php - output: &output_php | - . 5: <?php if (!$list) { ?> - . 7: <?php } else { ?> - . 10: <?php $i = 0; ?> - . 11: <?php foreach ($list as $item) { ?> - . 12: <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> - . 13: <?php echo $item; ?> - . 15: <?php } ?> - . 18: <?php } ?> - -## -- name: notext_php_nu - options: '-nu' - filename: ex-notext.php - input: *input_php - output: &output_php | - . - . 5: <?php if (!$list) { ?> - . - . 7: <?php } else { ?> - . - . 10: <?php $i = 0; ?> - . 11: <?php foreach ($list as $item) { ?> - . 12: <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> - . 13: <?php echo $item; ?> - . - . 15: <?php } ?> - . - . 18: <?php } ?> - . - -## -- name: notext_php_shortnotation - options: '' - filename: ex-short-notation.php - input: | - . <table> - . <? $i = 0; ?> - . <? foreach ($list as $item) { ?> - . <tr bgcolor="<?= ++$i % 2 == 1 ? '#FCC' : '#CCF' ?>"> - . <td><?= $item ?></td> - . </tr> - . <? } ?> - . </table> - output: | - . - . <?php $i = 0; ?> - . <?php foreach ($list as $item) { ?> - . <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?> - . <?php echo $item; ?> - . - . <?php } ?> - . - -## ---- -- name: notext_eperl - options: '' - filename: ex-notext.eperl - input: &input_eperl | - <?xml version="1.0"?> - <html> - <body> - <h3>List</h3> - <? if (!@list) { !> - <p>not found.</p> - <? } else { !> - <table> - <tbody> - <? $i = 0; !> - <? foreach ($item in @list) { !> - <tr bgcolor="<?= ++$i % 2 == 1 ? '#FCC' : '#CCF' !>"> - <td><?= $item !></td> - </tr> - <? } !> - </tbody> - </table> - <? } !> - </body> - </html> - output: | - .use HTML::Entities; - . - . - . - . if (!@list) { - . - . } else { - . - . - . $i = 0; - . foreach ($item in @list) { - . print(++$i % 2 == 1 ? '#FCC' : '#CCF'); - . print($item); - . - . } - . - . - . } - . - . - -## -- name: notext_eperl_nc - options: '-nc' - filename: ex-notext.eperl - input: *input_eperl - output: | - . 1: use HTML::Entities; - . 5: if (!@list) { - . 7: } else { - . 10: $i = 0; - . 11: foreach ($item in @list) { - . 12: print(++$i % 2 == 1 ? '#FCC' : '#CCF'); - . 13: print($item); - . 15: } - . 18: } - -## -- name: notext_eperl_nu - options: '-nu' - filename: ex-notext.eperl - input: *input_eperl - output: | - . 1: use HTML::Entities; - . - . 5: if (!@list) { - . - . 7: } else { - . - . 10: $i = 0; - . 11: foreach ($item in @list) { - . 12: print(++$i % 2 == 1 ? '#FCC' : '#CCF'); - . 13: print($item); - . - . 15: } - . - . 18: } - . diff --git a/test/test.rb b/test/test.rb index 3e41995..18590cb 100644 --- a/test/test.rb +++ b/test/test.rb @@ -26,6 +26,5 @@ if $0 == __FILE__ require "#{TESTDIR}/test-engines.rb" require "#{TESTDIR}/test-enhancers.rb" require "#{TESTDIR}/test-main.rb" - require "#{TESTDIR}/test-notext.rb" require "#{TESTDIR}/test-users-guide.rb" end |