diff options
-rw-r--r-- | ChangeLog | 59 | ||||
-rw-r--r-- | ChangeLog.txt | 12 | ||||
-rw-r--r-- | README | 63 | ||||
-rw-r--r-- | README.txt | 80 | ||||
-rw-r--r-- | ReleaseNote.txt | 60 | ||||
-rw-r--r-- | Rookbook.yaml | 28 | ||||
-rw-r--r-- | benchmark/erubybench-lib.rb | 28 | ||||
-rw-r--r-- | benchmark/erubybench.rb | 4 | ||||
-rw-r--r-- | doc/Rookbook.yaml | 8 | ||||
-rw-r--r-- | doc/users-guide.html | 363 | ||||
-rw-r--r-- | doc/users-guide.txt | 202 | ||||
-rw-r--r-- | erubis.gemspec | 20 | ||||
-rw-r--r-- | examples/example.ejava | 4 | ||||
-rw-r--r-- | lib/erubis.rb | 10 | ||||
-rw-r--r-- | lib/erubis/engine.rb | 30 | ||||
-rw-r--r-- | lib/erubis/engine/ec.rb | 2 | ||||
-rw-r--r-- | lib/erubis/engine/ejava.rb | 18 | ||||
-rw-r--r-- | lib/erubis/engine/ejavascript.rb | 16 | ||||
-rw-r--r-- | lib/erubis/engine/eruby.rb | 10 | ||||
-rw-r--r-- | lib/erubis/engine/escheme.rb | 10 | ||||
-rw-r--r-- | lib/erubis/engine/optimized.rb | 10 | ||||
-rw-r--r-- | lib/erubis/enhancer.rb | 44 | ||||
-rw-r--r-- | lib/erubis/helper.rb | 35 | ||||
-rw-r--r-- | lib/erubis/main.rb | 128 | ||||
-rw-r--r-- | lib/erubis/tiny.rb | 10 | ||||
-rw-r--r-- | test/test-bin.rb | 99 | ||||
-rw-r--r-- | test/test-engines.rb | 36 | ||||
-rw-r--r-- | test/test-erubis.rb | 274 | ||||
-rw-r--r-- | website/Rookbook.rb | 14 | ||||
-rw-r--r-- | website/index.txt | 27 | ||||
-rw-r--r-- | website/index.xhtml | 57 |
31 files changed, 1000 insertions, 761 deletions
@@ -2,24 +2,51 @@ # $Release$ # $Copyright$ -- release: 1.1 - date: 205-03-05 - desc: - - tag: enhance - text: '<%# ... %>' is supported - - tag: enhance - text: PrintEnhancer, PrintEruby, and PrintXmlEruby added +- release: 2.0.0 + date: 2006-05-20 + changes: + - module 'PrintEnhancer' is renamed to 'PrintEnabledEnahncer' + - module 'FastEnhancer' and class 'FastEruby' is obsolete because they are integrated into Eruby class + - Eruby#evaluate() calls instance_eval() instead of eval() + - XmlEruby.escape_xml() is moved to XmlHelper.escape_xml() + enhances: + - multi programming language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript) + - class Eruby runs very fast because FastEnhancer module is integrated into Eruby by default + - TinyEruby class (tiny.rb) is added + - module ArrayBufferEnhancer added + - module ArrayEnhancer added + - module BiPatternEnhancer added + - module EscapeEnhancer added + - module HeaderFooterEnhancer added + - module NoTextEnhancer added + - module PercentLineEnhancer added + - module PrintEnabledEnhancer added + - module PrintOutEnhancer added + - module SimplifyEnhancer added + - module StringBufferEnhancer added + - module StringIOEnhancer added + - command-line option '-b' (body only) added + - command-line option '-e' (escape) added + - command-line option '-l' (lang) added + - command-line option '-E' (enhancer) added + - command-line option '-I' (require path) added + - command-line option '-K' (kanji code) added + - command-line option '-S' (string to symbol) added + - command-line option '-B' (call result(binding())) added + +- release: 1.1.0 + date: 2006-03-05 + enhances: + - '<%# ... %>' is supported + - PrintEnhancer, PrintEruby, and PrintXmlEruby added - release: 1.0.1 - date: 2005-02-01 - desc: - - tag: bugfix - text: bin/erubis is available with RubyGems + date: 2006-02-01 + bugfixes: + - bin/erubis is available with RubyGems - release: 1.0.0 - date: 2005-02-01 - desc: - - tag: note - text: first release - + date: 2006-02-01 + bugfixes: + - first release diff --git a/ChangeLog.txt b/ChangeLog.txt index d19aac1..2abc548 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,16 @@ -.=title: ChangeLog +.=document: ChangeLog .?lastupdate: $Date$ .?version: $Rev$ +.: Rev.21 (2005-05-19) + .- [change] '_out' is changed to '_buf' + .- [change] option '-s' is obsolete + .- [change] option '-E' is obsolete + .- [change] option '-e' is renamed to '-E' + .- [change] use command-line option object in Main class + .- [refact] Helper#escape_xml() is changed to call String#gsub a time + .- [change] test-bin.rb invoke Main.new.execute(), not 'ruby $script' + .: Rev.20 (2005-05-18) .- [bugfix] test/test-erubis.rb fixed @@ -135,3 +144,4 @@ .: Rev.1 (2005-01-29) .- initial commit +.-document: @@ -1,63 +0,0 @@ -= README - -release:: $Release$ -copyright:: $Copyright$ - - - -== About Erubis - -Erubis is an implementation of eRuby. It has the following features. -* Very fast (about three times faster than ERB and almost as fast as eruby) -* Auto trimming spaces around '<% %>' -* Auto escape (sanitizing) -* Changeable embedded pattern (default '<% %>') -* Context object available -* Easy to expand and customize in subclass -* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript) - -Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher. - -See doc/users-guide.html for details. - - - -== Installation - -* If you have installed RubyGems, just type {{,gem install --remote erubis,}}. - - $ sudo gem install --remote erubis - -* Or if you can be root user, download erubis-X.X.X.tar.bz2 and install by setup.rb. - - $ tar xjf erubis-X.X.X.tar.bz2 - $ cd erubis-X.X.X/ - $ ruby setup.rb config - $ ruby setup.rb setup - $ sudo ruby setup.rb install - -* Else you should copy 'lib/erubis.rb' and 'bin/erubis' into proper directory manually. - - $ tar xjf erubis-X.X.X.tar.bz2 - $ cd erubis-X.X.X/ - $ cp lib/erubis.rb /usr/local/lib/ruby/site_ruby/1.8 - $ cp bin/erubis /usr/local/bin - - - -== Benchmark - -'benchmark/erubybenchmark.rb' is a benchmark script of Erubis. -Try 'ruby erubybenchmark.rb' in benchmark directory. - - - -== License - -GPL ver.2 - - - -== Author - -makoto kuwata <kwa(at)kuwata-lab.com> diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..61c6dbd --- /dev/null +++ b/README.txt @@ -0,0 +1,80 @@ += README + +release:: $Release$ +copyright:: $Copyright$ + + + +== About Erubis + +Erubis is an implementation of eRuby. It has the following features. +* Very fast (about three times faster than ERB and almost as fast as eruby) +* Auto trimming spaces around '<% %>' +* Auto escape (sanitizing) +* Changeable embedded pattern (default '<% %>') +* Context object available +* Easy to expand and customize in subclass +* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript) + +Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher. + +See doc/users-guide.html for details. + + + +== Installation + +* If you have installed RubyGems, just type <tt>gem install --remote erubis</tt>. + + $ sudo gem install --remote erubis + +* Else install abstract[http://rubyforge.org/projects/abstract/] at first, + and download erubis_X.X.X.tar.bz2 and install it by setup.rb. + + $ tar xjf abstract_X.X.X.tar.bz2 + $ cd abstract_X.X.X/ + $ sudo ruby setup.rb + $ cd .. + $ tar xjf erubis_X.X.X.tar.bz2 + $ cd erubis_X.X.X/ + $ sudo ruby setup.rb + +* (Optional) It is able to merge 'lib/**/*.rb' into 'bin/erubis' by + 'contrib/inline-require' script. + + $ tar xjf erubis_X.X.X.tar.bz2 + $ cd erubis_X.X.X/ + $ cp /tmp/abstract_X.X.X/lib/abstract.rb lib + $ unset RUBYLIB + $ contrib/inline-require -I lib bin/erubis > contrib/erubis + + + +== Exploring Guide + +If you are exploring Eruby, see the following class at first. +* Erubis::TinyEruby (erubis/tiny.rb) -- + the most simple eRuby implementation. +* Erubis::Engine (erubis/engine.rb) -- + base class of Eruby, Ephp, Ejava, and so on. +* Erubis::Eruby (erubis/engine/eruby.rb) -- + engine class for eRuby. + + + +== Benchmark + +'benchmark/erubybenchmark.rb' is a benchmark script of Erubis. +Try 'ruby erubybenchmark.rb' in benchmark directory. + + + +== License + +GPL ver.2 + + + +== Author + +makoto kuwata <kwa(at)kuwata-lab.com> diff --git a/ReleaseNote.txt b/ReleaseNote.txt index 3e37eb9..d951d85 100644 --- a/ReleaseNote.txt +++ b/ReleaseNote.txt @@ -1,4 +1,64 @@ +$ [ANN] Erubis 2.0.0 release - a fast eRuby implementation + +I have released Erubis 2.0.0. +http://rubyforge.org/projects/erubis/ + +Erubis is a pure ruby implementation of eRuby. + +Features: + * Very fast, almost three times faster than ERB and + even as fast as eruby (implemented in C) + * Support multi-language + (Ruby,PHP,C,Java,Scheme,Perl,Javascript) + * Auto escaping support + * Auto trimming spaces around '<% %>' + * Embedded pattern changeable (default '<% %>') + * Context object available and easy to combine eRuby + template with YAML datafile + * Print statement available + * Easy to extend in subclass + +See users' guide (erubis_2.0.0/doc/users-guide.html) +for details. + + +Changes from 1.1: + * module 'PrintEnhancer' is renamed to 'PrintEnabledEnahncer' + * module 'FastEnhancer' and class 'FastEruby' is obsolete + (these are integrated with Eruby class) + * Eruby#evaluate() calls instance_eval() instead of eval() + * XmlEruby.escape_xml() is moved to XmlHelper.escape_xml() + * and so on + +Enhancements from 1.1: + * multi programming language support + (Ruby,PHP,C,Java,Scheme,Perl,Javascript) + * many enhancer modules are added (see users' guide for details) + * class Eruby runs very fast because FastEnhancer module is + integrated into Eruby by default + * TinyEruby class (tiny.rb) is added + * and so on + + +If you are interested in Eruby internal, see the following classes +at first. + * Erubis::TinyEruby (erubis/tiny.rb) -- + the most simple eRuby implementation. + * Erubis::Engine (erubis/engine.rb) -- + base class of Eruby, Ephp, Ejava, and so on. + * Erubis::Eruby (erubis/engine/eruby.rb) -- + engine class for eRuby. + + +-- +regards, +kwatch + + + + + $ Release 1.1.1 (2006-03-06) I have released Erubis 1.1.0. diff --git a/Rookbook.yaml b/Rookbook.yaml index b392c5d..f45beed 100644 --- a/Rookbook.yaml +++ b/Rookbook.yaml @@ -11,12 +11,14 @@ properties: variables: - project : erubis - copyright : copyright(c) 2006 kuwata-lab all rights reserved. - - text_files : [ChangeLog, README, COPYING, setup.rb, erubis.gemspec] + - text_files : [ChangeLog, README.txt, COPYING, setup.rb, erubis.gemspec] - guide : doc/users-guide.html - doc_files : [$(guide), doc/docstyle.css] - apidocdir : doc-api - home* : ENV['HOME'] - inline_require_script : $(home)/src/inline-require/trunk/bin/inline-require + - abstract_rb : $(home)/src/abstract/trunk/lib/abstract.rb + - benchmark_files* : Dir.glob('benchmark/erubybench{-lib.rb,.rb,.rhtml,.yaml}') - base : $(project)_$(release) - base2 : $(project)-$(release) - libfiles* : Dir.glob("lib/**/*") @@ -40,7 +42,7 @@ recipes: - product: :clear method: | - rm_rf '$(project)_*.*', '$(project)-*.gem' + rm_rf '$(project)_*.*', '$(project)-*.gem', apidocdir - product: :apidoc desc: create api document by RDoc @@ -50,10 +52,10 @@ recipes: ingreds: [ $(libfiles) ] method: | rm_rf '$(apidocdir)' - opts = "-o ../$(apidocdir) -S -m ../README" + opts = "-o ../$(apidocdir) -S -m ../README.txt" opts << exclude_libs.collect { |f| " -x erubis/#{f}" }.join(" ") chdir 'lib' do - sys "rdoc #{opts} ../README *" + sys "rdoc #{opts} ../README.txt *" end - product: :chmod @@ -113,22 +115,34 @@ recipes: base = File.basename(f) !exclude_libs.include?(base) end + # + store 'benchmark/erubybench.{rb,rhtml,yaml}', 'benchmark/erubybench-lib.rb', dir + # chdir 'examples' do sys 'make clean' end store 'examples/**/*', dir store '$(apidocdir)/**/*', dir # - mkdir_p "#{dir}/contrib" - cp_r '$(inline_require_script)', "#{dir}/contrib" - # chdir 'doc' do sys 'rook :all' end mkdir_p "#{dir}/doc" cp_r doc_files, "#{dir}/doc" # + mkdir_p "#{dir}/contrib" + cp_r '$(inline_require_script)', "#{dir}/contrib" + # edit "#{dir}/**/*" do |content| content.gsub!(/\$Release.*?\$/, "$Release: $(1) $") content.gsub!(/\$Copyright.*?\$/, '$(copyright)') end # + begin + cp abstract_rb, "#{dir}/lib" + chdir dir do + sys "RUBYLIB= ruby $(inline_require_script) -I lib bin/erubis > contrib/erubis" + end + ensure + rm "#{dir}/lib/abstract.rb" + end + # chmod 0644, "#{dir}/**/*", :filetype=>'file' chmod 0755, "#{dir}/{bin,contrib}/*", :filetype=>'file' diff --git a/benchmark/erubybench-lib.rb b/benchmark/erubybench-lib.rb index 32ca299..881ad35 100644 --- a/benchmark/erubybench-lib.rb +++ b/benchmark/erubybench-lib.rb @@ -3,8 +3,8 @@ module Erubis class Eruby2 < Eruby def finalize_src(src) - #src << "\nprint _out.join; nil\n" - src << "\n_out.join; ''\n" + #src << "\nprint _buf.join; nil\n" + src << "\n_buf.join; ''\n" end end @@ -32,20 +32,20 @@ module Erubis EMBEDDED_PATTERN = /(.*?)<%(=+|\#)?(.*?)-?%>/m def compile(input) - src = "_out = $stdout;" # preamble + src = "_buf = $stdout;" # preamble input.scan(EMBEDDED_PATTERN) do |text, indicator, code| - src << " _out << '" << escape_text(text) << "';" + src << " _buf << '" << escape_text(text) << "';" if !indicator # <% %> src << code << ";" elsif indicator[0] == ?\# # <%# %> n = code.count("\n") add_stmt(src, "\n" * n) else # <%= %> - src << " _out << (" << code << ").to_s;" + src << " _buf << (" << code << ").to_s;" end end rest = $' || input - src << " _out << '" << escape_text(rest) << "';" + src << " _buf << '" << escape_text(rest) << "';" src << "\nnil\n" # postamble return src end @@ -127,7 +127,7 @@ module Erubis #def switch_to_expr(src) # return if @prev_is_expr # @prev_is_expr = true - # src << ' _out' + # src << ' _buf' #end #def switch_to_stmt(src) @@ -146,9 +146,9 @@ module Erubis if @initialized #switch_to_expr(src) #src << " << '" << escape_text(text) << "'" - src << "_out << '" << escape_text(text) << "';" + src << "_buf << '" << escape_text(text) << "';" else - src << "_out = '" << escape_text(text) << "';" + src << "_buf = '" << escape_text(text) << "';" @initialized = true end end @@ -160,17 +160,17 @@ module Erubis end def add_expr_literal(src, code) - unless @initialized; src << "_out = ''"; @initialized = true; end + unless @initialized; src << "_buf = ''"; @initialized = true; end #switch_to_expr(src) #src << " << (" << code << ").to_s" - src << " _out << (" << code << ").to_s;" + src << " _buf << (" << code << ").to_s;" end def add_expr_escaped(src, code) - unless @initialized; src << "_out = ''"; @initialized = true; end + unless @initialized; src << "_buf = ''"; @initialized = true; end #switch_to_expr(src) #src << " << " << escaped_expr(code) - src << " _out << " << escaped_expr(code) << ';' + src << " _buf << " << escaped_expr(code) << ';' end def add_expr_debug(src, code) @@ -181,7 +181,7 @@ module Erubis def add_postamble(src) #super if @initialized - src << "\n_out\n" if @initialized + src << "\n_buf\n" if @initialized end end diff --git a/benchmark/erubybench.rb b/benchmark/erubybench.rb index ae0def4..a87dea6 100644 --- a/benchmark/erubybench.rb +++ b/benchmark/erubybench.rb @@ -103,7 +103,7 @@ testdefs_str = <<END return: str - name: ErubisEruby2 - desc: print _out #, no binding() + desc: print _buf #, no binding() class: Erubis::Eruby2 code: | #Erubis::Eruby2.new(File.read(filename)).result() @@ -215,7 +215,7 @@ end # str.gsub!(/\bdata\b/, '$data') # hash = testdefs.find { |h| h['name'] == compiler_name } # code = eval hash['compile'] -# code.sub!(/_out\s*\z/, 'print \&') +# code.sub!(/_buf\s*\z/, 'print \&') # File.open($load_filename, 'w') { |f| f.write(code) } # at_exit do # File.unlink $load_filename if test(?f, $load_filename) diff --git a/doc/Rookbook.yaml b/doc/Rookbook.yaml index 4cb0434..dd74a17 100644 --- a/doc/Rookbook.yaml +++ b/doc/Rookbook.yaml @@ -11,6 +11,14 @@ recipes: - product: :default ingreds: [ :all ] + - product: :clear + method: | + rm_rf 'guide.d', '*.html' + + - product: :clean + method: | + rm_rf 'guide.d', '*.toc.html' + - product: :all ingreds: [ $(all) ] diff --git a/doc/users-guide.html b/doc/users-guide.html index 8f678ea..2c55081 100644 --- a/doc/users-guide.html +++ b/doc/users-guide.html @@ -151,25 +151,21 @@ It has the following features. </li> </ul> <ul type="disc"> -<li>Or if you can be root user, download erubis-X.X.X.tar.bz2 and install by setup.rb. -<pre class="terminal">$ tar xjf erubis-X.X.X.tar.bz2 +<li>Else install <a href="http://rubyforge.org/projects/erubis/">abstract</a> at first, + and download erubis_X.X.X.tar.bz2 and install it by setup.rb. +<pre class="terminal">$ tar xjf abstract_X.X.X.tar.bz2 +$ cd abstract_X.X.X/ +$ sudo ruby setup.rb +$ cd .. +$ tar xjf erubis_X.X.X.tar.bz2 $ cd erubis_X.X.X/ -$ ruby setup.rb +$ sudo ruby setup.rb </pre> </li> </ul> <ul type="disc"> -<li>Else you should copy 'lib/erubis.rb', 'lib/erubis/', and 'bin/erubis' into proper directory manually. -<pre class="terminal">$ tar xjf erubis-X.X.X.tar.bz2 -$ cd erubis_X.X.X/ -$ cp -r lib/erubis.rb lib/erubis /usr/local/lib/ruby/site_ruby/1.8 -$ cp bin/erubis /usr/local/bin -</pre> -</li> -</ul> -<ul type="disc"> -<li>(Optional) 'contrib/inline-require' enables you to merge 'lib/erubis.rb' into 'bin/erubis'. -<pre class="terminal">$ tar xjf erubis-X.X.X.tar.bz2 +<li>(Optional) 'contrib/inline-require' enables you to merge 'lib/**/*.rb' into 'bin/erubis'. +<pre class="terminal">$ tar xjf erubis_X.X.X.tar.bz2 $ cd erubis_X.X.X/ $ unset RUBYLIB $ contrib/inline-require -I lib bin/erubis > contrib/erubis @@ -213,14 +209,14 @@ puts <b>eruby.result(binding())</b> # get result output</div> <pre class="terminal">$ ruby example1.rb ---------- script source --- -_out = []; _out << '<ul> +_buf = []; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; -_out.join +_buf.join ---------- result ---------- <ul> <li>aaa</li> @@ -228,19 +224,19 @@ _out.join <li>ccc</li> </ul> </pre> -<p>Erubis has command 'erubis'. Command-line option '-s' shows the compiled source code of eRuby script. +<p>Erubis has command 'erubis'. Command-line option '-x' shows the compiled source code of eRuby script. </p> <div class="terminal_caption"> -example of command-line option '-s'</div> -<pre class="terminal">$ erubis <b>-s</b> example1.eruby -_out = []; _out << '<ul> +example of command-line option '-x'</div> +<pre class="terminal">$ erubis <b>-x</b> example1.eruby +_buf = []; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; -_out.join +_buf.join </pre> <br> @@ -262,31 +258,31 @@ example2.eruby</div> </pre> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -s example2.eruby -_out = []; _out << '<ul> +<pre class="terminal">$ erubis -x example2.eruby +_buf = []; _buf << '<ul> '; for item in list - _out << ' <li> -'; _out << ' '; _out << ( item ).to_s; _out << ' -'; _out << ' </li> + _buf << ' <li> +'; _buf << ' '; _buf << ( item ).to_s; _buf << ' +'; _buf << ' </li> '; end - _out << '</ul> + _buf << '</ul> '; -_out.join +_buf.join </pre> <p>If you want leave spaces around '<% %>', add command-line option '-T'. </p> <div class="terminal_caption"> compiled source code with command-line option '-T'</div> -<pre class="terminal">$ erubis -s <b>-T</b> example2.eruby -_out = []; _out << '<ul> -'; _out << ' '; for item in list ; _out << ' -'; _out << ' <li> -'; _out << ' '; _out << ( item ).to_s; _out << ' -'; _out << ' </li> -'; _out << ' '; end ; _out << ' -'; _out << '</ul> +<pre class="terminal">$ erubis -x <b>-T</b> example2.eruby +_buf = []; _buf << '<ul> +'; _buf << ' '; for item in list ; _buf << ' +'; _buf << ' <li> +'; _buf << ' '; _buf << ( item ).to_s; _buf << ' +'; _buf << ' </li> +'; _buf << ' '; end ; _buf << ' +'; _buf << '</ul> '; -_out.join +_buf.join </pre> <p>Or add option <code>:trim=>false</code> to Erubis::Eruby.new(). </p> @@ -308,15 +304,15 @@ puts eruby.result(binding()) # get result output</div> <pre class="terminal">$ ruby example2.rb ---------- script source --- -_out = []; _out << '<ul> -'; _out << ' '; for item in list ; _out << ' -'; _out << ' <li> -'; _out << ' '; _out << ( item ).to_s; _out << ' -'; _out << ' </li> -'; _out << ' '; end ; _out << ' -'; _out << '</ul> +_buf = []; _buf << '<ul> +'; _buf << ' '; for item in list ; _buf << ' +'; _buf << ' <li> +'; _buf << ' '; _buf << ( item ).to_s; _buf << ' +'; _buf << ' </li> +'; _buf << ' '; end ; _buf << ' +'; _buf << '</ul> '; -_out.join +_buf.join ---------- result ---------- <ul> @@ -384,13 +380,13 @@ puts eruby.result(binding()) # get result output</div> <pre class="terminal">$ ruby example3.rb 2> stderr.log ---------- script source --- -_out = []; for item in list - _out << ' <p>'; <b>_out << Erubis::XmlHelper.escape_xml( item );</b> _out << '</p> - <p>'; <b>_out << ( item ).to_s;</b> _out << '</p> - <p>'; <b>$stderr.puts("*** debug: item=#{(item).inspect}");</b> _out << '</p> +_buf = []; for item in list + _buf << ' <p>'; <b>_buf << Erubis::XmlHelper.escape_xml( item );</b> _buf << '</p> + <p>'; <b>_buf << ( item ).to_s;</b> _buf << '</p> + <p>'; <b>$stderr.puts("*** debug: item=#{(item).inspect}");</b> _buf << '</p> '; end -_out.join +_buf.join ---------- result ---------- <p>&lt;aaa&gt;</p> <p><aaa></p> @@ -409,17 +405,17 @@ $ cat stderr.log *** debug: item="b&b" *** debug: item="\"ccc\"" </pre> -<p>The command-line option '-e Escape' will do the same action as Erubis::EscapedEruby. -This is available in any language. +<p>The command-line option '-e'<sup>(<a href="#fnref:2" name="fnlink:2">*2</a>)</sup> will do the same action as Erubis::EscapedEruby. +This option is available for any language. </p> -<pre class="terminal">$ erubis -l ruby <b>-e Escape</b> example3.eruby -_out = []; for item in list - _out << ' <p>'; _out << Erubis::XmlHelper.escape_xml( item ); _out << '</p> - <p>'; _out << ( item ).to_s; _out << '</p> - <p>'; $stderr.puts("*** debug: item=#{(item).inspect}"); _out << '</p> +<pre class="terminal">$ erubis -l ruby <b>-e</b> example3.eruby +_buf = []; for item in list + _buf << ' <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p> + <p>'; _buf << ( item ).to_s; _buf << '</p> + <p>'; $stderr.puts("*** debug: item=#{(item).inspect}"); _buf << '</p> '; end -_out.join +_buf.join </pre> <p>Escaping function (default 'Erubis::XmlHelper.escape_xml()') can be changed by command-line property '--escape=xxx' or by overriding Erubis::Eruby#escaped_expr() in subclass. </p> @@ -442,6 +438,8 @@ end <dl compact> <dt>(<a name="fnref:1" href="#fnlink:1">*1</a>)</dt> <dd>Erubis::EscapedEruby class includes Erubis::EscapeEnhancer which swtches the action of '<%= %>' and '<%== %>'.</dd> + <dt>(<a name="fnref:2" href="#fnlink:2">*2</a>)</dt> + <dd>Command-line option '-e' is equivarent to '-E Escape'.</dd> </dl> </div> <br> @@ -460,11 +458,11 @@ example4.eruby</div> </pre> <div class="terminal_caption"> compiled source code with command-line option '-p'</div> -<pre class="terminal">$ erubis -s <b>-p '<!--% %-->'</b> example4.eruby -_out = []; for item in list - _out << ' <p>'; _out << ( item ).to_s; _out << '</p> +<pre class="terminal">$ erubis -x <b>-p '<!--% %-->'</b> example4.eruby +_buf = []; for item in list + _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p> '; end -_out.join +_buf.join </pre> <a name="example4.rb"></a> <div class="program_caption"> @@ -485,10 +483,10 @@ puts eruby.result(binding()) # get result output</div> <pre class="terminal">$ ruby example4.rb ---------- script source --- -_out = []; for item in list - _out << ' <p>'; _out << ( item ).to_s; _out << '</p> +_buf = []; for item in list + _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p> '; end -_out.join +_buf.join ---------- result ---------- <p>aaa</p> <p>bbb</p> @@ -691,8 +689,8 @@ Command-line option '-B' invokes 'Erubis::Eruby#result(binding())' instead of 'E <a name="tut-preamble"></a> <h3 class="section2">Preamble and Postamble</h3> -<p>The first line ('_out = [];') in the compiled source code is called preamble -and the last line ('_out.join') is called postamble. +<p>The first line ('_buf = [];') in the compiled source code is called preamble +and the last line ('_buf.join') is called postamble. </p> <p>Command-line option '-b' skips the output of preamble and postamble. </p> @@ -706,15 +704,16 @@ example8.eruby</div> <p>compiled source code with and without command-line option '-b' </p> <pre class="terminal">## without '-b' -$ erubis -s example8.eruby -<b>_out = [];</b> for item in @list - _out << ' <b>'; _out << ( item ).to_s; _out << '</b> +$ erubis -x example8.eruby +<b>_buf = [];</b> for item in @list + _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b> '; end -<b>_out.join</b> +<b>_buf.join</b> + ## with '-b' -$ erubis -s <b>-b</b> example8.eruby +$ erubis -x <b>-b</b> example8.eruby for item in @list - _out << ' <b>'; _out << ( item ).to_s; _out << '</b> + _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b> '; end </pre> <p>Erubis::Eruby.new option '<code>:preamble=>false</code>' and '<code>:postamble=>false</code>' also suppress output of preamble or postamle. @@ -734,13 +733,13 @@ puts eruby2.src # don't print preamble and postamble <div class="terminal_caption"> output</div> <pre class="terminal">$ ruby example8.rb -_out = []; for item in @list - _out << ' <b>'; _out << ( item ).to_s; _out << '</b> +_buf = []; for item in @list + _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b> '; end -_out.join +_buf.join -------------- for item in @list - _out << ' <b>'; _out << ( item ).to_s; _out << '</b> + _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b> '; end </pre> <br> @@ -752,7 +751,7 @@ _out.join <a name="enhancer"></a> <h2 class="section1">Enhancer</h2> <p>Enhancer is a module to add a certain feature into Erubis::Eruby class. -Enhancer may be language-independent or only for Eruby. +Enhancer may be language-independent or only for Erubis::Eruby class. </p> <p>To use enhancers, define subclass and include them. The folloing is an example to use <a href="#escape-enhancer">EscapeEnhancer</a>, <a href="#percentline-enhancer">PercentLineEnhancer</a>, and <a href="#bipattern-enhancer">BiPatternEnhancer</a>. @@ -763,10 +762,10 @@ The folloing is an example to use <a href="#escape-enhancer">EscapeEnhancer</a>, include BiPatternEnhancer end </pre> -<p>You can specify enhancers in command-line with option '-e'. +<p>You can specify enhancers in command-line with option '-E'. The following is an example to use some enhancers in command-line. </p> -<pre class="terminal">$ erubis -se Escape,PercentLine,BiPattern example.eruby +<pre class="terminal">$ erubis -xE Escape,PercentLine,BiPattern example.eruby </pre> <p>The following is the list of enhancers. </p> @@ -784,7 +783,7 @@ The following is an example to use some enhancers in command-line. <dt class="dt1"> <a href="#printout-enhancer">PrintOutEnhancer</a> (only for Eruby)</dt> <dd class="dd1"> - Use "print(...)" statement insead of "_out << ...". + Use "print(...)" statement insead of "_buf << ...". </dd> <dt class="dt1"> <a href="#printenabled-enhancer">PrintEnabledEnhancer</a> (only for Eruby)</dt> @@ -851,15 +850,15 @@ example.eruby</div> </pre> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se Escape example.eruby -_out = []; _out << '<div> +<pre class="terminal">$ erubis -xE Escape example.eruby +_buf = []; _buf << '<div> '; for item in list - _out << ' <p>'; <b>_out << Erubis::XmlHelper.escape_xml( item );</b> _out << '</p> - <p>'; <b>_out << ( item ).to_s;</b> _out << '</p> + _buf << ' <p>'; <b>_buf << Erubis::XmlHelper.escape_xml( item );</b> _buf << '</p> + <p>'; <b>_buf << ( item ).to_s;</b> _buf << '</p> '; end - _out << '</div> + _buf << '</div> '; -_out.join +_buf.join </pre> <p>EscapeEnhancer is language-independent. </p> @@ -873,13 +872,13 @@ Therefore, you can use 'print' statement in embedded ruby code. </p> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se Stdout example.eruby -<b>_out = $stdout;</b> _out << '<div> +<pre class="terminal">$ erubis -xE Stdout example.eruby +<b>_buf = $stdout;</b> _buf << '<div> '; for item in list - _out << ' <p>'; _out << ( item ).to_s; _out << '</p> - <p>'; _out << Erubis::XmlHelper.escape_xml( item ); _out << '</p> + _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p> + <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p> '; end - _out << '</div> + _buf << '</div> '; '' </pre> @@ -890,11 +889,11 @@ compiled source code</div> <a name="printout-enhancer"></a> <h3 class="section2">PrintOutEnhancer</h3> -<p>PrintOutEnhancer makes compiled source code to use 'print(...)' instead of '_out << ...'. +<p>PrintOutEnhancer makes compiled source code to use 'print(...)' instead of '_buf << ...'. </p> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se PrintOut example.eruby +<pre class="terminal">$ erubis -xE PrintOut example.eruby <b>print</b> '<div> '; for item in list <b>print</b> ' <p>'; <b>print</b>(( item ).to_s); <b>print</b> '</p> @@ -952,14 +951,14 @@ because print() method in '<% ... %>' invokes not Kernel#print() but Print </p> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal"><b>_out = [];</b> _out << '<div> +<pre class="terminal"><b>_buf = [];</b> _buf << '<div> '; for item in list - _out << ' <p>'; _out << ( item ).to_s; _out << '</p> - <p>'; _out << Erubis::XmlHelper.escape_xml( item ); _out << '</p> + _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p> + <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p> '; end - _out << '</div> + _buf << '</div> '; -<b>_out</b> +<b>_buf</b> </pre> <p>ArrayEnhancer is only for Eruby. </p> @@ -981,15 +980,15 @@ Erubis::Eruby includes this enhancer by default. <h3 class="section2">StringBufferEnhancer</h3> <p>StringBufferEnhancer makes Eruby to use string buffer. </p> -<pre class="terminal">$ erubis -se StringBuffer example.eruby -<b>_out = '';</b> _out << '<div> +<pre class="terminal">$ erubis -xE StringBuffer example.eruby +<b>_buf = '';</b> _buf << '<div> '; for item in list - _out << ' <p>'; _out << ( item ).to_s; _out << '</p> - <p>'; _out << Erubis::XmlHelper.escape_xml( item ); _out << '</p> + _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p> + <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p> '; end - _out << '</div> + _buf << '</div> '; -<b>_out</b> +<b>_buf</b> </pre> <p>StringBufferEnhancer is only for Eruby. </p> @@ -1021,22 +1020,22 @@ notext-example.eruby</div> </pre> <div class="terminal_caption"> output example of NoTextEnhancer</div> -<pre class="terminal">$ erubis -Tse NoText notext-example.eruby -_out = []; +<pre class="terminal">$ erubis -TxE NoText notext-example.eruby +_buf = []; if !@list || @list.empty? ; else ; @list.each_with_index do |item, i| ; - _out << ( i%2 == 0 ? '#FFCCCC' : '#CCCCFF' ).to_s; - _out << ( item ).to_s; + _buf << ( i%2 == 0 ? '#FFCCCC' : '#CCCCFF' ).to_s; + _buf << ( item ).to_s; end ; end ; -_out.join +_buf.join </pre> <p>NoTextEnhancer is language-independent. It is useful even if you are PHP user, see <a href="#topics-php">this section</a>. </p> @@ -1049,15 +1048,15 @@ _out.join </p> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se Simplify example.euby -_out = []; _out << '<div> -'; for item in list ; _out << ' - <p>'; _out << ( item ).to_s; _out << '</p> - <p>'; _out << Erubis::XmlHelper.escape_xml( item ); _out << '</p> -'; end ; _out << ' +<pre class="terminal">$ erubis -xE Simplify example.euby +_buf = []; _buf << '<div> +'; for item in list ; _buf << ' + <p>'; _buf << ( item ).to_s; _buf << '</p> + <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p> +'; end ; _buf << ' </div> '; -_out.join +_buf.join </pre> <p>SimplifyEnhancer is language-independent. </p> @@ -1080,12 +1079,12 @@ bipattern-example.rhtml</div> </pre> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se BiPattern bipattern-example.rhtml -_out = []; for item in list - _out << ' <b>'; <b>_out << ( item ).to_s;</b> _out << '</b> - <b>'; <b>_out << Erubis::XmlHelper.escape_xml( item );</b> _out << '</b> +<pre class="terminal">$ erubis -xE BiPattern bipattern-example.rhtml +_buf = []; for item in list + _buf << ' <b>'; <b>_buf << ( item ).to_s;</b> _buf << '</b> + <b>'; <b>_buf << Erubis::XmlHelper.escape_xml( item );</b> _buf << '</b> '; end -_out.join +_buf.join </pre> <p>BiPatternEnhancer is language-independent. </p> @@ -1107,13 +1106,13 @@ percentline-example.rhtml</div> </pre> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se PercentLine percentline-example.rhtml -_out = []; <b>for item in list</b> - _out << ' <b>'; _out << ( item ).to_s; _out << '</b> +<pre class="terminal">$ erubis -xE PercentLine percentline-example.rhtml +_buf = []; <b>for item in list</b> + _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b> '; <b>end</b> - _out << '% lines with \'%%\' + _buf << '% lines with \'%%\' '; -_out.join +_buf.join </pre> <p>PercentLineEnhancer is language-independent. </p> @@ -1141,14 +1140,14 @@ headerfooter-example.eruby</div> </pre> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se HeaderFooter headerfooter-example.eruby +<pre class="terminal">$ erubis -xE HeaderFooter headerfooter-example.eruby <b>def list_items(items)</b> -_out = []; for item in items - _out << ' <b>'; _out << ( item ).to_s; _out << '</b> +_buf = []; for item in items + _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b> '; end -_out.join +_buf.join <b>end</b> @@ -1170,17 +1169,17 @@ normal-eruby-test.eruby</div> </pre> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -s normal-eruby-test.eruby -_out = []; +<pre class="terminal">$ erubis -x normal-eruby-test.eruby +_buf = []; <b>def list_items(items)</b> for item in items - _out << '<li>'; _out << ( item ).to_s; _out << '</li> + _buf << '<li>'; _buf << ( item ).to_s; _buf << '</li> '; end <b>end</b> -_out.join +_buf.join </pre> <p>Header and footer can be in any position in eRuby script, that is, header is no need to be in the head of eRuby script. @@ -1201,16 +1200,16 @@ headerfooter-example2.rhtml</div> </pre> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal">$ erubis -se HeaderFooter headerfooter-example2.rhtml +<pre class="terminal">$ erubis -xE HeaderFooter headerfooter-example2.rhtml <b>def page(list)</b> -_out = []; _out << '<?xml version="1.0"?> +_buf = []; _buf << '<?xml version="1.0"?> <html> -'; _out << ' : -'; _out << '</html> +'; _buf << ' : +'; _buf << '</html> '; -_out.join +_buf.join <b>end</b> @@ -1377,7 +1376,7 @@ public class Example { } public String view() { - StringBuffer _out = new StringBuffer(); + StringBuffer _buf = new StringBuffer(); %></b> <html> <body> @@ -1395,7 +1394,7 @@ public class Example { <body> </html> <b><% - return _out.toString(); + return _buf.toString(); } public static void main(String[] args) { @@ -1424,7 +1423,7 @@ public class Example { <div class="terminal_caption"> compiled source code</div> <pre class="terminal">$ erubis -b -l java example.ejava -StringBuffer _out = new StringBuffer(); +StringBuffer _buf = new StringBuffer(); import java.util.*; public class Example { @@ -1436,25 +1435,25 @@ public class Example { } public String view() { - StringBuffer _out = new StringBuffer(); + StringBuffer _buf = new StringBuffer(); -_out.append("<html>\n" +_buf.append("<html>\n" + " <body>\n" - + " <p>Hello "); _out.append(user); _out.append("!</p>\n" + + " <p>Hello "); _buf.append(user); _buf.append("!</p>\n" + " <table>\n" + " <tbody>\n"); for (int i = 0; i < list.length; i++) { -_out.append(" <tr bgcolor=\""); _out.append(i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _out.append("\">\n" - + " <td>"); _out.append(i + 1); _out.append("</td>\n" - + " <td>"); _out.append(escape(list[i])); _out.append("</td>\n" +_buf.append(" <tr bgcolor=\""); _buf.append(i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _buf.append("\">\n" + + " <td>"); _buf.append(i + 1); _buf.append("</td>\n" + + " <td>"); _buf.append(escape(list[i])); _buf.append("</td>\n" + " </tr>\n"); } -_out.append(" </tbody>\n" +_buf.append(" </tbody>\n" + " </table>\n" + " <body>\n" + "</html>\n"); - return _out.toString(); + return _buf.toString(); } public static void main(String[] args) { @@ -1479,7 +1478,7 @@ _out.append(" </tbody>\n" } } -return _out.toString(); +return _buf.toString(); </pre> <br> @@ -1521,7 +1520,7 @@ example.escheme</div> <div class="terminal_caption"> compiled source code</div> <pre class="terminal">$ erubis -l scheme example.escheme -(let ((_out '())) (define (_add x) (set! _out (cons x _out))) (_add "<html> +(let ((_buf '())) (define (_add x) (set! _buf (cons x _buf))) (_add "<html> <body>\n") (let ((user "Erubis") @@ -1549,7 +1548,7 @@ compiled source code</div> (_add " </body> </html>\n") - (reverse _out)) + (reverse _buf)) </pre> <div class="terminal_caption"> compiled source code (with --func=display property)</div> @@ -1665,27 +1664,27 @@ print(' </table> <div class="terminal_caption"> compiled source code</div> <pre class="terminal">$ erubis -l js example.ejs -var _out = []; +var _buf = []; var user = 'Erubis'; var list = ['<aaa>', 'b&b', '"ccc"']; -_out.push("<html>\n\ +_buf.push("<html>\n\ <body>\n\ - <p>Hello "); _out.push(user); _out.push("!</p>\n\ + <p>Hello "); _buf.push(user); _buf.push("!</p>\n\ <table>\n\ <tbody>\n"); var i; for (i = 0; i < list.length; i++) { -_out.push(" <tr bgcolor=\""); _out.push(i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _out.push("\">\n\ - <td>"); _out.push(i + 1); _out.push("</td>\n\ - <td>"); _out.push(list[i]); _out.push("</td>\n\ +_buf.push(" <tr bgcolor=\""); _buf.push(i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _buf.push("\">\n\ + <td>"); _buf.push(i + 1); _buf.push("</td>\n\ + <td>"); _buf.push(list[i]); _buf.push("</td>\n\ </tr>\n"); } -_out.push(" </tbody>\n\ +_buf.push(" </tbody>\n\ </table>\n\ </body>\n\ </html>\n"); -document.write(_out.join("")); +document.write(_buf.join("")); </pre> <br> @@ -1739,7 +1738,7 @@ 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 -T -l php -e NoText -p '<\?php \?>' notext-example.php | uniq +<pre class="terminal">$ erubis -T -l php -E NoText -p '<\?php \?>' notext-example.php | uniq <?php if (!$list || count($list) == 0) { ?> @@ -1815,7 +1814,7 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978) <h2 class="section1">Command Reference</h2> <a name="command-usage"></a> <h3 class="section2">Usage</h3> -<p>erubis [-hvsT] [-p <i>pattern</i>] [-c <i>class</i>] [-K <i>kanji</i>] [-f <i>file.yaml</i>] [<i>file</i> ...] +<p>erubis [..options..] [<i>file</i> ...] </p> <br> @@ -1834,14 +1833,9 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978) Release version. </dd> <dt class="dt3"><b> --s </b></dt> - <dd class="dd3"> - Show script source. - </dd> - <dt class="dt3"><b> -x </b></dt> <dd class="dd3"> - Show script source, removing the last '_out' line. + Show compiled source. </dd> <dt class="dt3"><b> -T </b></dt> @@ -1856,6 +1850,11 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978) This is equivarent to '--preamble=false --postamble=false'. </dd> <dt class="dt3"><b> +-e </b></dt> + <dd class="dd3"> + Escape. This is equivarent to '-E Escape'. + </dd> + <dt class="dt3"><b> -p pattern </b></dt> <dd class="dd3"> Embedded pattern (default '<% %>'). @@ -1868,23 +1867,13 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978) This option makes erubis command to compile script but no execute. </dd> <dt class="dt3"><b> --c class </b></dt> - <dd class="dd3"> - Class name (Eruby, XmlEruby, ...) to compile. (default Eruby). - </dd> - <dt class="dt3"><b> --e enhacers </b></dt> +-E enhacers </b></dt> <dd class="dd3"> Enhancer name (Escape, PercentLine, ...). It is able to specify several enhancer name separating with ',' (ex. -f Escape,PercentLine,HeaderFooter). </dd> <dt class="dt3"><b> --E </b></dt> - <dd class="dd3"> - Show all enhancers. - </dd> - <dt class="dt3"><b> -I path </b></dt> <dd class="dd3"> Require library path ($:). @@ -1906,7 +1895,7 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978) <dt class="dt3"><b> -t </b></dt> <dd class="dd3"> - Expand tab character in YAML file. + Expand tab characters in YAML file. </dd> <dt class="dt3"><b> -S </b></dt> @@ -1926,7 +1915,7 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978) <h3 class="section2">Properties</h3> <p>Some Eruby classes can take optional properties to change it's compile option. For example, property '--indent=" "' may change indentation of compiled source code. -Try 'eruby -h' for details. +Try 'erubis -h' for details. </p> <br> diff --git a/doc/users-guide.txt b/doc/users-guide.txt index 30911c3..620f361 100644 --- a/doc/users-guide.txt +++ b/doc/users-guide.txt @@ -35,27 +35,39 @@ Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher. $ sudo gem install --remote erubis .==================== -.* Or if you can be root user, download erubis-X.X.X.tar.bz2 and install by setup.rb. +.* Else install {{<abstract|http://rubyforge.org/projects/erubis/>}} at first, + and download erubis_X.X.X.tar.bz2 and install it by setup.rb. .==================== - $ tar xjf erubis-X.X.X.tar.bz2 + $ tar xjf abstract_X.X.X.tar.bz2 + $ cd abstract_X.X.X/ + $ sudo ruby setup.rb + $ cd .. + $ tar xjf erubis_X.X.X.tar.bz2 $ cd erubis_X.X.X/ - $ ruby setup.rb - .#$ ruby setup.rb config - .#$ ruby setup.rb setup - .#$ sudo ruby setup.rb install + $ sudo ruby setup.rb .==================== -.* Else you should copy 'lib/erubis.rb', 'lib/erubis/', and 'bin/erubis' into proper directory manually. - .==================== - $ tar xjf erubis-X.X.X.tar.bz2 - $ cd erubis_X.X.X/ - $ cp -r lib/erubis.rb lib/erubis /usr/local/lib/ruby/site_ruby/1.8 - $ cp bin/erubis /usr/local/bin - .==================== - -.* (Optional) 'contrib/inline-require' enables you to merge 'lib/erubis.rb' into 'bin/erubis'. +.#.* Or if you can be root user, download erubis_X.X.X.tar.bz2 and install by setup.rb. +.# .==================== +.# $ tar xjf erubis-X.X.X.tar.bz2 +.# $ cd erubis_X.X.X/ +.# $ ruby setup.rb +.# .#$ ruby setup.rb config +.# .#$ ruby setup.rb setup +.# .#$ sudo ruby setup.rb install +.# .==================== +.# +.#.* Else you should copy 'lib/erubis.rb', 'lib/erubis/', and 'bin/erubis' into proper directory manually. +.# .==================== +.# $ tar xjf erubis-X.X.X.tar.bz2 +.# $ cd erubis_X.X.X/ +.# $ cp -r lib/erubis.rb lib/erubis /usr/local/lib/ruby/site_ruby/1.8 +.# $ cp bin/erubis /usr/local/bin +.# .==================== + +.* (Optional) 'contrib/inline-require' enables you to merge 'lib/**/*.rb' into 'bin/erubis'. .==================== - $ tar xjf erubis-X.X.X.tar.bz2 + $ tar xjf erubis_X.X.X.tar.bz2 $ cd erubis_X.X.X/ $ unset RUBYLIB $ contrib/inline-require -I lib bin/erubis > contrib/erubis @@ -101,12 +113,12 @@ $ ruby example1.rb .<<<:! (cd guide.d; ruby example1.rb) .==================== -Erubis has command 'erubis'. Command-line option '-s' shows the compiled source code of eRuby script. +Erubis has command 'erubis'. Command-line option '-x' shows the compiled source code of eRuby script. -.? example of command-line option '-s' +.? example of command-line option '-x' .==================== -$ erubis {{*-s*}} example1.eruby -.<<<:! (cd guide.d; erubis -s example1.eruby) +$ erubis {{*-x*}} example1.eruby +.<<<:! (cd guide.d; erubis -x example1.eruby) .==================== @@ -128,16 +140,16 @@ Erubis deletes spaces around '<% %>' automatically, while it leaves spaces aroun .? compiled source code .==================== -$ erubis -s example2.eruby -.<<<:! (ruby -pi.bak -e 'sub! /\s*\#.*$/, ""' guide.d/example2.eruby; erubis -s guide.d/example2.eruby) +$ erubis -x example2.eruby +.<<<:! (ruby -pi.bak -e 'sub! /\s*\#.*$/, ""' guide.d/example2.eruby; erubis -x guide.d/example2.eruby) .==================== If you want leave spaces around '<% %>', add command-line option '-T'. .? compiled source code with command-line option '-T' .==================== -$ erubis -s {{*-T*}} example2.eruby -.<<<:! erubis -s -T guide.d/example2.eruby +$ erubis -x {{*-T*}} example2.eruby +.<<<:! erubis -x -T guide.d/example2.eruby .==================== Or add option {{,:trim=>false,}} to Erubis::Eruby.new(). @@ -161,14 +173,14 @@ puts eruby.result(binding()) # get result $ ruby example2.rb .<<<:! (cd guide.d; ruby example2.rb) .#--- script source --- -.#_out = ''; _out << "<ul>\n" -.#{{*_out << " ";*}} for item in list {{*; _out << "\n"*}} -.#_out << " <li>\n" -.#_out << " "; _out << ( item ).to_s; _out << "\n" -.#_out << " </li>\n" -.#{{*_out << " ";*}} end {{*; _out << "\n"*}} -.#_out << "</ul>\n" -.#_out +.#_buf = ''; _buf << "<ul>\n" +.#{{*_buf << " ";*}} for item in list {{*; _buf << "\n"*}} +.#_buf << " <li>\n" +.#_buf << " "; _buf << ( item ).to_s; _buf << "\n" +.#_buf << " </li>\n" +.#{{*_buf << " ";*}} end {{*; _buf << "\n"*}} +.#_buf << "</ul>\n" +.#_buf .#--- result --- .#<ul> .# @@ -229,17 +241,17 @@ puts eruby.result(binding()) # get result .? output .==================== $ ruby example3.rb 2> stderr.log -.<<<:! (cd guide.d; ruby example3.rb 2> stderr.log) | ruby -pe 'sub! /_out << [E(].*?;|\$stderr.*?;/, "{{*\\&*}}"' +.<<<:! (cd guide.d; ruby example3.rb 2> stderr.log) | ruby -pe 'sub! /_buf << [E(].*?;|\$stderr.*?;/, "{{*\\&*}}"' .#--- script source --- -.#_out = ''; _out << "<ul>\n" +.#_buf = ''; _buf << "<ul>\n" .# for item in list -.#_out << " <li>"; {{*_out << Erubis::XmlEruby.escape( item )*}}; _out << "</li>\n" -.#_out << " <li>"; _out << ( item ).to_s; _out << "</li>\n" -.#_out << " <li>"; {{*$stderr.puts("** erubis: item = #{(item).inspect}")*}}; _out << "</li>\n" -.#_out << "\n" +.#_buf << " <li>"; {{*_buf << Erubis::XmlEruby.escape( item )*}}; _buf << "</li>\n" +.#_buf << " <li>"; _buf << ( item ).to_s; _buf << "</li>\n" +.#_buf << " <li>"; {{*$stderr.puts("** erubis: item = #{(item).inspect}")*}}; _buf << "</li>\n" +.#_buf << "\n" .# end -.#_out << "</ul>\n" -.#_out +.#_buf << "</ul>\n" +.#_buf .#--- result --- .#<ul> .# <li>{{*<aaa>*}}</li> @@ -262,12 +274,12 @@ $ cat stderr.log .#** erubis: item = "\"ccc\"" .==================== -The command-line option '-e Escape' will do the same action as Erubis::EscapedEruby. -This is available in any language. +The command-line option '-e'{{(Command-line option '-e' is equivarent to '-E Escape'.)}} will do the same action as Erubis::EscapedEruby. +This option is available for any language. .==================== -$ erubis -l ruby {{*-e Escape*}} example3.eruby -.<<<:! (cd guide.d; erubis -e Escape -l ruby example3.eruby) +$ erubis -l ruby {{*-e*}} example3.eruby +.<<<:! (cd guide.d; erubis -e -l ruby example3.eruby) .==================== Escaping function (default 'Erubis::XmlHelper.escape_xml()') can be changed by command-line property '--escape=xxx' or by overriding Erubis::Eruby#escaped_expr() in subclass. @@ -303,8 +315,8 @@ You can change embedded pattern '{{,<% %>,}}' to another with command-line optio .? compiled source code with command-line option '-p' .==================== -$ erubis -s {{*-p '<!--% %-->'*}} example4.eruby -.<<<:! erubis -s -p '<!--% %-->' guide.d/example4.eruby +$ erubis -x {{*-p '<!--% %-->'*}} example4.eruby +.<<<:! erubis -x -p '<!--% %-->' guide.d/example4.eruby .==================== .? example4.rb @@ -495,8 +507,8 @@ Command-line option '-B' invokes 'Erubis::Eruby#result(binding())' instead of 'E .$$ Preamble and Postamble | tut-preamble -The first line ('_out = [];') in the compiled source code is called preamble -and the last line ('_out.join') is called postamble. +The first line ('_buf = [];') in the compiled source code is called preamble +and the last line ('_buf.join') is called postamble. Command-line option '-b' skips the output of preamble and postamble. @@ -510,11 +522,12 @@ Command-line option '-b' skips the output of preamble and postamble. compiled source code with and without command-line option '-b' .==================== ## without '-b' -$ erubis -s example8.eruby -.<<<:! erubis -s guide.d/example8.eruby | ruby -pe 'sub! /^_out.*?(;|$)/, "{{*\\&*}}"' +$ erubis -x example8.eruby +.<<<:! erubis -x guide.d/example8.eruby | ruby -pe 'sub! /^_buf.*?(;|$)/, "{{*\\&*}}"' + ## with '-b' -$ erubis -s {{*-b*}} example8.eruby -.<<<:! erubis -s -b guide.d/example8.eruby +$ erubis -x {{*-b*}} example8.eruby +.<<<:! erubis -x -b guide.d/example8.eruby .==================== Erubis::Eruby.new option '{{,:preamble=>false,}}' and '{{,:postamble=>false,}}' also suppress output of preamble or postamle. @@ -544,7 +557,7 @@ $ ruby example8.rb .$ Enhancer | enhancer Enhancer is a module to add a certain feature into Erubis::Eruby class. -Enhancer may be language-independent or only for Eruby. +Enhancer may be language-independent or only for Erubis::Eruby class. To use enhancers, define subclass and include them. The folloing is an example to use {{<EscapeEnhancer|#escape-enhancer>}}, {{<PercentLineEnhancer|#percentline-enhancer>}}, and {{<BiPatternEnhancer|#bipattern-enhancer>}}. @@ -556,10 +569,10 @@ class MyEruby < Erubis::Eruby end .-------------------- -You can specify enhancers in command-line with option '-e'. +You can specify enhancers in command-line with option '-E'. The following is an example to use some enhancers in command-line. .==================== -$ erubis -se Escape,PercentLine,BiPattern example.eruby +$ erubis -xE Escape,PercentLine,BiPattern example.eruby .==================== The following is the list of enhancers. @@ -569,7 +582,7 @@ The following is the list of enhancers. .: {{<StdoutEnhancer|#stdout-enhancer>}} (only for Eruby) Use $stdout instead of array buffer. .: {{<PrintOutEnhancer|#printout-enhancer>}} (only for Eruby) - Use "print(...)" statement insead of "_out << ...". + Use "print(...)" statement insead of "_buf << ...". .: {{<PrintEnabledEnhancer|#printenabled-enhancer>}} (only for Eruby) Enable to use print() in '<% ... %>'. .: {{<ArrayEnhancer|#array-enhancer>}} (only for Eruby) @@ -637,8 +650,8 @@ EscapeEnhancer switches '<%= ... %>' to escaped and '<%== ... %>' to unescaped. .? compiled source code .==================== -$ erubis -se Escape example.eruby -.<<<:! erubis -se Escape guide.d/example.eruby | ruby -pe 'sub! /_out << [E(].*?;/, "{{*\\&*}}"' +$ erubis -xE Escape example.eruby +.<<<:! erubis -xE Escape guide.d/example.eruby | ruby -pe 'sub! /_buf << [E(].*?;/, "{{*\\&*}}"' .==================== EscapeEnhancer is language-independent. @@ -668,8 +681,8 @@ Therefore, you can use 'print' statement in embedded ruby code. .? compiled source code .==================== -$ erubis -se Stdout example.eruby -.<<<:! erubis -se Stdout guide.d/example.eruby | ruby -pe 'sub! /^_out = .*;/, "{{*\\&*}}"' +$ erubis -xE Stdout example.eruby +.<<<:! erubis -xE Stdout guide.d/example.eruby | ruby -pe 'sub! /^_buf = .*;/, "{{*\\&*}}"' .==================== StdoutEnhancer is only for Eruby. @@ -678,7 +691,7 @@ StdoutEnhancer is only for Eruby. .$$ PrintOutEnhancer | printout-enhancer -PrintOutEnhancer makes compiled source code to use 'print(...)' instead of '_out << ...'. +PrintOutEnhancer makes compiled source code to use 'print(...)' instead of '_buf << ...'. .#.? printstatement-example.rb .#.-------------------- printstatement-example.rb @@ -698,8 +711,8 @@ PrintOutEnhancer makes compiled source code to use 'print(...)' instead of '_out .? compiled source code .==================== -$ erubis -se PrintOut example.eruby -.<<<:! erubis -se PrintOut guide.d/example.eruby | ruby -pe 'gsub! /print/, "{{*\\&*}}"' +$ erubis -xE PrintOut example.eruby +.<<<:! erubis -xE PrintOut guide.d/example.eruby | ruby -pe 'gsub! /print/, "{{*\\&*}}"' .==================== PrintOutEnhancer is only for Eruby. @@ -764,7 +777,7 @@ ArrayEnhancer makes Eruby to return an array of strings. .? compiled source code .==================== -.<<<:! erubis -se Array guide.d/example.eruby | ruby -pe 'sub! /^_out( = \[\];)?/, "{{*\\&*}}"' +.<<<:! erubis -xE Array guide.d/example.eruby | ruby -pe 'sub! /^_buf( = \[\];)?/, "{{*\\&*}}"' .==================== ArrayEnhancer is only for Eruby. @@ -802,15 +815,10 @@ StringBufferEnhancer makes Eruby to use string buffer. .#.==================== .==================== -$ erubis -se StringBuffer example.eruby -.<<<:! erubis -se StringBuffer guide.d/example.eruby | ruby -pe 'sub!(/^_out( = ..;)?/,"{{*\\&*}}")' +$ erubis -xE StringBuffer example.eruby +.<<<:! erubis -xE StringBuffer guide.d/example.eruby | ruby -pe 'sub!(/^_buf( = ..;)?/,"{{*\\&*}}")' .==================== -.#+++ -.--------- printen -.--------- -.#--- - StringBufferEnhancer is only for Eruby. @@ -842,8 +850,8 @@ This is useful especially when debugging a complex eRuby script. .? output example of NoTextEnhancer .==================== -$ erubis -Tse NoText notext-example.eruby -.<<<:! (cd guide.d; erubis -Tse NoText notext-example.eruby) +$ erubis -TxE NoText notext-example.eruby +.<<<:! (cd guide.d; erubis -TxE NoText notext-example.eruby) .==================== NoTextEnhancer is language-independent. It is useful even if you are PHP user, see {{<this section|#topics-php>}}. @@ -872,8 +880,8 @@ SimplifyEnhancer makes compiling a little faster but don't trim spaces around '< .? compiled source code .==================== -$ erubis -se Simplify example.euby -.<<<:! erubis -se Simplify guide.d/example.eruby +$ erubis -xE Simplify example.euby +.<<<:! erubis -xE Simplify guide.d/example.eruby .==================== SimplifyEnhancer is language-independent. @@ -914,8 +922,8 @@ You can specify pattern by :bipattern property. .? compiled source code .==================== -$ erubis -se BiPattern bipattern-example.rhtml -.<<<:! erubis -se BiPattern guide.d/bipattern-example.rhtml | ruby -pe 'sub! /_out << [E(].*;/, "{{*\\&*}}"' +$ erubis -xE BiPattern bipattern-example.rhtml +.<<<:! erubis -xE BiPattern guide.d/bipattern-example.rhtml | ruby -pe 'sub! /_buf << [E(].*;/, "{{*\\&*}}"' .==================== BiPatternEnhancer is language-independent. @@ -955,8 +963,8 @@ This is for compatibility with eruby and ERB. .? compiled source code .==================== -$ erubis -se PercentLine percentline-example.rhtml -.<<<:! erubis -se PercentLine guide.d/percentline-example.rhtml | ruby -pe 'sub! /for.*?list|end/, "{{*\\&*}}"' +$ erubis -xE PercentLine percentline-example.rhtml +.<<<:! erubis -xE PercentLine guide.d/percentline-example.rhtml | ruby -pe 'sub! /for.*?list|end/, "{{*\\&*}}"' .==================== PercentLineEnhancer is language-independent. @@ -1002,8 +1010,8 @@ HeaderFooterEnhancer enables you to add header and footer in eRuby script. .? compiled source code .==================== -$ erubis -se HeaderFooter headerfooter-example.eruby -.<<<:! erubis -se HeaderFooter guide.d/headerfooter-example.eruby | ruby -pe 'sub! /^(def|end).*$/, "{{*\\&*}}"' +$ erubis -xE HeaderFooter headerfooter-example.eruby +.<<<:! erubis -xE HeaderFooter guide.d/headerfooter-example.eruby | ruby -pe 'sub! /^(def|end).*$/, "{{*\\&*}}"' .==================== Compare to the following: @@ -1023,8 +1031,8 @@ Compare to the following: .? compiled source code .==================== -$ erubis -s normal-eruby-test.eruby -.<<<:! erubis -s guide.d/normal-eruby-test.eruby | ruby -pe 'sub! /^(def|end).*$/, "{{*\\&*}}"' +$ erubis -x normal-eruby-test.eruby +.<<<:! erubis -x guide.d/normal-eruby-test.eruby | ruby -pe 'sub! /^(def|end).*$/, "{{*\\&*}}"' .==================== Header and footer can be in any position in eRuby script, @@ -1065,8 +1073,8 @@ print eruby.src .? compiled source code .==================== -$ erubis -se HeaderFooter headerfooter-example2.rhtml -.<<<:! erubis -se HeaderFooter guide.d/headerfooter-example2.rhtml | ruby -pe 'sub! /^(def|end).*$/, "{{*\\&*}}"' +$ erubis -xE HeaderFooter headerfooter-example2.rhtml +.<<<:! erubis -xE HeaderFooter guide.d/headerfooter-example2.rhtml | ruby -pe 'sub! /^(def|end).*$/, "{{*\\&*}}"' .==================== HeaderFooterEnhancer is experimental and is language-independent. @@ -1176,7 +1184,7 @@ public class Example { } public String view() { - StringBuffer _out = new StringBuffer(); + StringBuffer _buf = new StringBuffer(); %>*}} <html> <body> @@ -1194,7 +1202,7 @@ public class Example { <body> </html> {{*<% - return _out.toString(); + return _buf.toString(); } public static void main(String[] args) { @@ -1390,8 +1398,8 @@ NoTextEnhancer can separate PHP code from HTML document. .? example of using NoTextEnhancer with PHP file .==================== -$ erubis -T -l php -e NoText -p '<\?php \?>' notext-example.php | uniq -.<<<:! erubis -T -l php -e NoText -p '<\?php \?>' guide.d/notext-example.php | uniq +$ erubis -T -l php -E NoText -p '<\?php \?>' notext-example.php | uniq +.<<<:! erubis -T -l php -E NoText -p '<\?php \?>' guide.d/notext-example.php | uniq .==================== @@ -1451,7 +1459,7 @@ This shows that: .$$ Usage | command-usage -erubis [-hvsT] [-p {{/pattern/}}] [-c {{/class/}}] [-K {{/kanji/}}] [-f {{/file.yaml/}}] [{{/file/}} ...] +erubis [..options..] [{{/file/}} ...] @@ -1459,21 +1467,20 @@ erubis [-hvsT] [-p {{/pattern/}}] [-c {{/class/}}] [-K {{/kanji/}}] [-f {{/file. .[ -h, --help ] Help. .[ -v ] Release version. - .[ -s ] Show script source. - .[ -x ] Show script source, removing the last '_out' line. + .[ -x ] Show compiled source. .[ -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/}}'. .[ -l lang ] Language name. This option makes erubis command to compile script but no execute. - .[ -c class ] Class name (Eruby, XmlEruby, ...) to compile. (default Eruby). - .[ -e enhacers ] Enhancer name (Escape, PercentLine, ...). +.# .[ -c class ] Class name (Eruby, XmlEruby, ...) to compile. (default Eruby). + .[ -E enhacers ] Enhancer name (Escape, PercentLine, ...). It is able to specify several enhancer name separating with ',' (ex. -f Escape,PercentLine,HeaderFooter). - .[ -E ] Show all enhancers. .[ -I path ] Require library path ($:). It is able to specify several paths separating with ',' (ex. -f path1,path2,path3). @@ -1481,14 +1488,15 @@ erubis [-hvsT] [-p {{/pattern/}}] [-c {{/class/}}] [-K {{/kanji/}}] [-f {{/file. .[ -f file.yaml ] YAML file for context values (read stdin if filename is '-'). It is able to specify several filenames separating with ',' (ex. -f file1,file2,file3). - .[ -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 Eruby#result() instead of Eruby#evaluate() + .$$ Properties | command-props Some Eruby classes can take optional properties to change it's compile option. For example, property '--indent=" "' may change indentation of compiled source code. -Try 'eruby -h' for details. +Try 'erubis -h' for details. diff --git a/erubis.gemspec b/erubis.gemspec index 6d327ab..72b1899 100644 --- a/erubis.gemspec +++ b/erubis.gemspec @@ -19,28 +19,30 @@ spec = Gem::Specification.new do |s| s.description = <<-'END' Erubis is an implementation of eRuby and has the following features: * Very fast (about three times faster than ERB) + * Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript) * Auto trimming spaces around '<% %>' * Auto sanitizing * Change embedded pattern (default '<% %>') * Context object available * Easy to expand in subclass - * Able to output multi-language (Ruby/PHP/C/Java/Scheme/Perl) END - + ## files files = [] files += Dir.glob('lib/**/*') files += Dir.glob('bin/*') files += Dir.glob('examples/**/*') - files += Dir.glob('test/test-*.rb') - #files += Dir.glob('man/**/*') - files += [ "doc/users-guide.html", "doc/docstyle.css", ] - files += %w[README ChangeLog COPYING setup.rb] - #s.files = files.delete_if { |path| path =~ /\.svn/ } + files += Dir.glob('test/*.rb') + files += %w[doc/users-guide.html doc/docstyle.css] + files += %w[README.txt ChangeLog COPYING setup.rb] + files += Dir.glob('contrib/*') + files += Dir.glob('benchmark/*') + files += Dir.glob('doc-api/**/*') s.files = files - s.executables = ["erubis"] - s.bindir = "bin" + s.executables = ['erubis'] + s.bindir = 'bin' s.test_file = 'test/test.rb' + s.add_dependency('abstract', ['>= 1.0.0']) end # Quick fix for Ruby 1.8.3 / YAML bug (thanks to Ross Bamford) diff --git a/examples/example.ejava b/examples/example.ejava index 21dd155..38f87dd 100644 --- a/examples/example.ejava +++ b/examples/example.ejava @@ -6,7 +6,7 @@ public class example { public static void main(String[] args) { String user = "Erubis"; String[] list = { "<aaa>", "b&b", "\"ccc\"" }; - StringBuffer _out = new StringBuffer(); + StringBuffer _buf = new StringBuffer(); %> <p>Hello <%= user %>!</p> <table> @@ -20,7 +20,7 @@ public class example { </tbody> </table> <% - System.out.print(_out.toString()); + System.out.print(_buf.toString()); } public static String escape(String s) { diff --git a/lib/erubis.rb b/lib/erubis.rb index b026dc9..d313f65 100644 --- a/lib/erubis.rb +++ b/lib/erubis.rb @@ -33,13 +33,13 @@ ## ## result: ## --- source --- -## _out = ""; _out << " <ul>\n" +## _buf = ""; _buf << " <ul>\n" ## for item in list -## _out << " <li>"; _out << ( item ).to_s; _out << "\n" -## _out << " "; _out << Erubis::XmlEruby.escape( item ); _out << "</li>\n" +## _buf << " <li>"; _buf << ( item ).to_s; _buf << "\n" +## _buf << " "; _buf << Erubis::XmlEruby.escape( item ); _buf << "</li>\n" ## end -## _out << " </ul>\n" -## _out +## _buf << " </ul>\n" +## _buf ## --- result --- ## <ul> ## <li><aaa> diff --git a/lib/erubis/engine.rb b/lib/erubis/engine.rb index 4f4a0e5..497db80 100644 --- a/lib/erubis/engine.rb +++ b/lib/erubis/engine.rb @@ -4,6 +4,8 @@ ## $Copyright$ ## +require 'abstract' + module Erubis @@ -16,7 +18,7 @@ module Erubis ## - ## context object for Engine#evaluate + ## .[abstract] context object for Engine#evaluate ## ## ex. ## template = <<'END' @@ -59,7 +61,7 @@ module Erubis ## - ## base engine class + ## [abstract] base engine class ## class Engine @@ -87,6 +89,7 @@ module Erubis attr_reader :src attr_accessor :filename + ## load file and create engine object def self.load_file(filename, properties={}) input = File.open(filename, 'rb') { |f| f.read } input.untaint # is it ok? @@ -95,6 +98,7 @@ module Erubis return engine end + ## eval(@src) with binding def result(_binding_or_hash=TOPLEVEL_BINDING) _arg = _binding_or_hash if _arg.is_a?(Hash) @@ -105,6 +109,7 @@ module Erubis return eval(@src, _arg, (@filename || '(erubis)')) end + ## call context.instance_eval(@src) def evaluate(context=Context.new) context = Context.new(context) if context.is_a?(Hash) return context.instance_eval(@src, (@filename || '(erubis)')) @@ -112,6 +117,7 @@ module Erubis DEFAULT_REGEXP = /(.*?)(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m + ## return regexp of pattern to parse eRuby script def pattern_regexp(pattern=@pattern) if pattern == '<% %>' return DEFAULT_REGEXP @@ -120,7 +126,9 @@ module Erubis return /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m end end + protected :pattern_regexp + ## compile input string into target language def compile(input) src = "" @preamble.nil? ? add_preamble(src) : (@preamble && (src << @preamble)) @@ -181,30 +189,40 @@ module Erubis return src end + ## compile input string and set it to @src def compile!(input) @src = compile(input) end protected + ## escape text string def escape_text(text) return text end + ## return escaped expression code def escaped_expr(code) @escape ||= 'escape' return "#{@escape}(#{code.strip})" end + ## .[empty] add @preamble to src def add_preamble(src) + # empty end + ## .[abstract] add text string to src def add_text(src, text) + not_implemented end + ## .[abstract] add statement code to src def add_stmt(src, code) + not_implemented end + ## add expression code to src def add_expr(src, code, indicator) case indicator when '=' @@ -216,16 +234,24 @@ module Erubis end end + ## .[abstract] add expression literal code to src. this is called by add_expr(). def add_expr_literal(src, code) + not_implemented end + ## .[abstract] add escaped expression code to src. this is called by add_expr(). def add_expr_escaped(src, code) + not_implemented end + ## .[empty] add expression code to src for debug. this is called by add_expr(). def add_expr_debug(src, code) + # empty end + ## .[empty] add @postamble to src def add_postamble(src) + # empty end end # end of class Engine diff --git a/lib/erubis/engine/ec.rb b/lib/erubis/engine/ec.rb index 8149dba..98b0267 100644 --- a/lib/erubis/engine/ec.rb +++ b/lib/erubis/engine/ec.rb @@ -19,7 +19,7 @@ module Erubis def self.supported_properties() # :nodoc: list = super list << [:indent, '', "indent spaces (ex. ' ')"] - list << [:out, 'stdout', "output stream name"] + list << [:out, 'stdout', "output file pointer name"] return list end diff --git a/lib/erubis/engine/ejava.rb b/lib/erubis/engine/ejava.rb index 9d21bd0..e5083d2 100644 --- a/lib/erubis/engine/ejava.rb +++ b/lib/erubis/engine/ejava.rb @@ -19,20 +19,20 @@ module Erubis def self.supported_properties() # :nodoc: list = super list << [:indent, '', "indent spaces (ex. ' ')"] - list << [:out, '_out', "output buffer name"] - list << [:outclass, 'StringBuffer', "output buffer class (ex. 'StringBuilder')"] + list << [:buf, '_buf', "output buffer name"] + list << [:bufclass, 'StringBuffer', "output buffer class (ex. 'StringBuilder')"] return list end def initialize(input, properties={}) @indent = properties[:indent] || '' - @out = properties[:out] || '_out' - @outclass = properties[:outclass] || 'StringBuffer' + @buf = properties[:buf] || '_buf' + @bufclass = properties[:bufclass] || 'StringBuffer' super end def add_preamble(src) - src << "#{@indent}#{@outclass} #{@out} = new #{@outclass}();" + src << "#{@indent}#{@bufclass} #{@buf} = new #{@bufclass}();" end def escape_text(text) @@ -50,7 +50,7 @@ module Erubis def add_text(src, text) return if text.empty? src << (src.empty? || src[-1] == ?\n ? @indent : ' ') - src << @out << ".append(" + src << @buf << ".append(" i = 0 text.each_line do |line| src << "\n" << @indent << ' + ' if i > 0 @@ -66,12 +66,12 @@ module Erubis def add_expr_literal(src, code) src << @indent if src.empty? || src[-1] == ?\n - src << ' ' << @out << '.append(' << code.strip << ');' + src << ' ' << @buf << '.append(' << code.strip << ');' end def add_expr_escaped(src, code) src << @indent if src.empty? || src[-1] == ?\n - src << ' ' << @out << '.append(' << escaped_expr(code) << ');' + src << ' ' << @buf << '.append(' << escaped_expr(code) << ');' end def add_expr_debug(src, code) @@ -82,7 +82,7 @@ module Erubis def add_postamble(src) src << "\n" if src[-1] == ?; - src << @indent << "return " << @out << ".toString();\n" + src << @indent << "return " << @buf << ".toString();\n" end end diff --git a/lib/erubis/engine/ejavascript.rb b/lib/erubis/engine/ejavascript.rb index b5958b2..5825481 100644 --- a/lib/erubis/engine/ejavascript.rb +++ b/lib/erubis/engine/ejavascript.rb @@ -19,19 +19,19 @@ module Erubis def self.supported_properties() # :nodoc: list = super #list << [:indent, '', "indent spaces (ex. ' ')"] - #list << [:out, '_out', "output buffer name"] + #list << [:buf, '_buf', "output buffer name"] return list end def initialize(input, properties={}) @indent = properties[:indent] || '' - @out = properties[:out] || '_out' - #@outclass = properties[:outclass] || 'StringBuffer' + @buf = properties[:out] || '_buf' + #@bufclass = properties[:outclass] || 'StringBuffer' super end def add_preamble(src) - src << "#{@indent}var #{@out} = [];" + src << "#{@indent}var #{@buf} = [];" end def escape_text(text) @@ -53,7 +53,7 @@ module Erubis def add_text(src, text) return if text.empty? add_indent(src, @indent) - src << @out << '.push("' + src << @buf << '.push("' s = escape_text(text) if s[-1] == ?\n s[-2, 2] = '' @@ -69,12 +69,12 @@ module Erubis def add_expr_literal(src, code) add_indent(src, @indent) - src << @out << '.push(' << code.strip << ');' + src << @buf << '.push(' << code.strip << ');' end def add_expr_escaped(src, code) add_indent(src, @indent) - src << @out << '.push(' << escaped_expr(code) << ');' + src << @buf << '.push(' << escaped_expr(code) << ');' end def add_expr_debug(src, code) @@ -85,7 +85,7 @@ module Erubis def add_postamble(src) src << "\n" if src[-1] == ?; - src << @indent << 'document.write(' << @out << ".join(\"\"));\n" + src << @indent << 'document.write(' << @buf << ".join(\"\"));\n" end end diff --git a/lib/erubis/engine/eruby.rb b/lib/erubis/engine/eruby.rb index 6a93175..9e26875 100644 --- a/lib/erubis/engine/eruby.rb +++ b/lib/erubis/engine/eruby.rb @@ -33,12 +33,12 @@ module Erubis #-- #def add_preamble(src) - # src << "_out = [];" + # src << "_buf = [];" #end #++ def add_text(src, text) - src << " _out << '" << escape_text(text) << "';" unless text.empty? + src << " _buf << '" << escape_text(text) << "';" unless text.empty? end def add_stmt(src, code) @@ -48,11 +48,11 @@ module Erubis end def add_expr_literal(src, code) - src << ' _out << (' << code << ').to_s;' + src << ' _buf << (' << code << ').to_s;' end def add_expr_escaped(src, code) - src << ' _out << ' << escaped_expr(code) << ';' + src << ' _buf << ' << escaped_expr(code) << ';' end def add_expr_debug(src, code) @@ -63,7 +63,7 @@ module Erubis #-- #def add_postamble(src) - # src << "\n_out.join\n" + # src << "\n_buf.join\n" #end #++ diff --git a/lib/erubis/engine/escheme.rb b/lib/erubis/engine/escheme.rb index d11497c..331fec8 100644 --- a/lib/erubis/engine/escheme.rb +++ b/lib/erubis/engine/escheme.rb @@ -29,10 +29,10 @@ module Erubis def add_preamble(src) return unless @func == '_add' - src << "(let ((_out '())) " + \ - "(define (_add x) (set! _out (cons x _out))) " - #src << "(let* ((_out '())" + \ - # " (_add (lambda (x) (set! _out (cons x _out))))) " + src << "(let ((_buf '())) " + \ + "(define (_add x) (set! _buf (cons x _buf))) " + #src << "(let* ((_buf '())" + \ + # " (_add (lambda (x) (set! _buf (cons x _buf))))) " end def escape_text(text) @@ -77,7 +77,7 @@ module Erubis def add_postamble(src) return unless @func == '_add' src << "\n" unless src[-1] == ?\n - src << " (reverse _out))\n" + src << " (reverse _buf))\n" end end diff --git a/lib/erubis/engine/optimized.rb b/lib/erubis/engine/optimized.rb index b544794..33d29a2 100644 --- a/lib/erubis/engine/optimized.rb +++ b/lib/erubis/engine/optimized.rb @@ -40,7 +40,7 @@ module Erubis def switch_to_expr(src) return if @prev_is_expr @prev_is_expr = true - src << ' _out' + src << ' _buf' end def switch_to_stmt(src) @@ -60,7 +60,7 @@ module Erubis switch_to_expr(src) src << " << '" << escape_text(text) << "'" else - src << "_out = '" << escape_text(text) << "';" + src << "_buf = '" << escape_text(text) << "';" @initialized = true end end @@ -73,13 +73,13 @@ module Erubis end def add_expr_literal(src, code) - unless @initialized; src << "_out = ''"; @initialized = true; end + unless @initialized; src << "_buf = ''"; @initialized = true; end switch_to_expr(src) src << " << (" << code << ").to_s" end def add_expr_escaped(src, code) - unless @initialized; src << "_out = ''"; @initialized = true; end + unless @initialized; src << "_buf = ''"; @initialized = true; end switch_to_expr(src) src << " << " << escaped_expr(code) end @@ -92,7 +92,7 @@ module Erubis def add_postamble(src) #super if @initialized - src << "\n_out\n" if @initialized + src << "\n_buf\n" if @initialized end end # end of class OptimizedEruby diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb index f2fa0b9..f27a450 100644 --- a/lib/erubis/enhancer.rb +++ b/lib/erubis/enhancer.rb @@ -73,7 +73,7 @@ module Erubis end def add_preamble(src) - src << "_out = $stdout;" + src << "_buf = $stdout;" end def add_postamble(src) @@ -84,14 +84,14 @@ module Erubis ## - ## use print statement instead of '_out << ...' + ## use print statement instead of '_buf << ...' ## ## this is only for Eruby. ## module PrintOutEnhancer def self.desc # :nodoc: - "use print statement instead of '_out << ...'" + "use print statement instead of '_buf << ...'" end def add_preamble(src) @@ -131,13 +131,13 @@ module Erubis end def add_preamble(src) - src << "@_out = " + src << "@_buf = " super end def print(*args) args.each do |arg| - @_out << arg.to_s + @_buf << arg.to_s end end @@ -168,35 +168,35 @@ module Erubis end def add_preamble(src) - src << "_out = [];" + src << "_buf = [];" end def add_postamble(src) src << "\n" unless src[-1] == ?\n - src << "_out\n" + src << "_buf\n" end end ## - ## use an Array object for buffering (included in Eruby by default) + ## use an Array object as buffer (included in Eruby by default) ## ## this is only for Eruby. ## module ArrayBufferEnhancer def self.desc # :nodoc: - "use an Array object for buffering (included in Eruby by default)" + "use an Array object for buffering (included in Eruby class)" end def add_preamble(src) - src << "_out = [];" + src << "_buf = [];" end def add_postamble(src) src << "\n" unless src[-1] == ?\n - src << "_out.join\n" + src << "_buf.join\n" end end @@ -214,12 +214,12 @@ module Erubis end def add_preamble(src) - src << "_out = '';" + src << "_buf = '';" end def add_postamble(src) src << "\n" unless src[-1] == ?\n - src << "_out\n" + src << "_buf\n" end end @@ -237,12 +237,12 @@ module Erubis end def add_preamble(src) - src << "_out = StringIO.new;" + src << "_buf = StringIO.new;" end def add_postamble(src) src << "\n" unless src[-1] == ?\n - src << "_out.string\n" + src << "_buf.string\n" end end @@ -417,13 +417,13 @@ module Erubis ## <% end %> ## ## $ erubis -s ex1.eruby - ## _out = []; def list_items(list) + ## _buf = []; def list_items(list) ## ; for item in list - ## ; _out << '<li>'; _out << ( item ).to_s; _out << '</li> + ## ; _buf << '<li>'; _buf << ( item ).to_s; _buf << '</li> ## '; end ## ; end ## ; - ## _out.join + ## _buf.join ## ## ## with header and footer ## $ cat ex2.eruby @@ -440,13 +440,13 @@ module Erubis ## $ erubis -s -c HeaderFooterEruby ex4.eruby ## ## def list_items(list) - ## _out = []; _out << ' + ## _buf = []; _buf << ' ## '; for item in list - ## ; _out << '<li>'; _out << ( item ).to_s; _out << '</li> + ## ; _buf << '<li>'; _buf << ( item ).to_s; _buf << '</li> ## '; end - ## ; _out << ' + ## ; _buf << ' ## '; - ## _out.join + ## _buf.join ## end ## ## ==================== diff --git a/lib/erubis/helper.rb b/lib/erubis/helper.rb index 45e6837..cd46fa5 100644 --- a/lib/erubis/helper.rb +++ b/lib/erubis/helper.rb @@ -14,17 +14,36 @@ module Erubis module_function + ESCAPE_TABLE = { + '&' => '&', + '<' => '<', + '>' => '>', + '"' => '"', + "'" => ''', + } + def escape_xml(obj) - str = obj.to_s.dup - #str = obj.to_s - #str = str.dup if obj.__id__ == str.__id__ - str.gsub!(/&/, '&') - str.gsub!(/</, '<') - str.gsub!(/>/, '>') - str.gsub!(/"/, '"') #" - return str + #table = ESCAPE_TABLE + #obj.to_s.gsub(/[&<>"]/) { |s| table[s] } # or /[&<>"']/ + obj.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] } # or /[&<>"']/ + #obj.to_s.gsub(SCAN_REGEXP) { |s| ESCAPE_TABLE[s] } + #obj.to_s.gsub(/[&<>"]/) { ESCAPE_TABLE[$&] } end + #-- + #def escape_xml(obj) + # str = obj.to_s.dup + # #str = obj.to_s + # #str = str.dup if obj.__id__ == str.__id__ + # str.gsub!(/&/, '&') + # str.gsub!(/</, '<') + # str.gsub!(/>/, '>') + # str.gsub!(/"/, '"') + # str.gsub!(/'/, ''') + # return str + #end + #++ + alias h escape_xml alias html_escape escape_xml diff --git a/lib/erubis/main.rb b/lib/erubis/main.rb index 843d31c..7a1278e 100644 --- a/lib/erubis/main.rb +++ b/lib/erubis/main.rb @@ -48,59 +48,96 @@ module Erubis exit(status) end + def initialize + @single_options = "hvxTtSbeB" + @arg_options = "pcrfKIlaE" + @option_names = { + ?h => :help, + ?v => :version, + ?x => :source, + ?T => :notrim, + ?t => :untabify, + ?S => :intern, + ?b => :bodyonly, + ?B => :binding, + ?p => :pattern, + ?c => :class, + ?e => :escape, + ?r => :requires, + ?f => :yamlfiles, + ?K => :kanji, + ?I => :includes, + ?l => :lang, + ?a => :action, + ?E => :enhancers, + } + assert unless @single_options.length + @arg_options.length == @option_names.length + (@single_options + @arg_options).each_byte do |ch| + assert unless @option_names.key?(ch) + end + end + + def execute(argv=ARGV) ## parse command-line options - options, properties = parse_argv(argv, "hvsxTtSbEB", "pcrfKIlae") + options, properties = parse_argv(argv, @single_options, @arg_options) filenames = argv options[?h] = true if properties[:help] + opts = Object.new + arr = @option_names.collect { |ch, name| "def #{name}; @#{name}; end\n" } + opts.instance_eval arr.join + options.each do |ch, val| + name = @option_names[ch] + opts.instance_variable_set("@#{name}", val) + end ## help, version, enhancer list - if options[?h] || options[?v] || options[?E] - puts version() if options[?v] - puts usage() if options[?h] - puts show_properties() if options[?h] - puts show_enhancers() if options[?E] + if opts.help || opts.version + puts version() if opts.version + puts usage() if opts.help + puts show_properties() if opts.help + puts show_enhancers() if opts.help return end ## include path - options[?I].split(/,/).each do |path| + opts.includes.split(/,/).each do |path| $: << path - end if options[?I] + end if opts.includes ## require library - options[?r].split(/,/).each do |library| + opts.requires.split(/,/).each do |library| require library - end if options[?r] + end if opts.requires ## action - action = options[?a] - action ||= 'compile' if options[?x] - action ||= 'compile' if options[?s] + action = opts.action + action ||= 'compile' if opts.source ## lang - lang = options[?l] || 'ruby' - action ||= 'compile' if options[?l] + lang = opts.lang || 'ruby' + action ||= 'compile' if opts.lang ## class name of Eruby - classname = options[?c] + classname = opts.class klass = get_classobj(classname, lang) ## kanji code - $KCODE = options[?K] if options[?K] + $KCODE = opts.kanji if opts.kanji ## read context values from yaml file - yamlfiles = options[?f] - context = load_yamlfiles(yamlfiles, options) + yamlfiles = opts.yamlfiles + context = load_yamlfiles(yamlfiles, opts) ## properties for engine - properties[:pattern] = options[?p] if options[?p] - properties[:trim] = false if options[?T] - properties[:preamble] = properties[:postamble] = false if options[?b] + properties[:pattern] = opts.pattern if opts.pattern + properties[:trim] = false if opts.notrim + properties[:preamble] = properties[:postamble] = false if opts.bodyonly ## create engine and extend enhancers engine = klass.new(nil, properties) - enhancers = get_enhancers(options[?e]) + enhancers = get_enhancers(opts.enhancers) + enhancers.push(Erubis::EscapeEnhancer) if opts.escape enhancers.each do |enhancer| engine.extend(enhancer) engine.bipattern = properties[:bipattern] if enhancer == Erubis::BiPatternEnhancer @@ -113,57 +150,53 @@ module Erubis test(?f, filename) or raise CommandOptionError.new("#{filename}: file not found.") engine.filename = filename engine.compile!(File.read(filename)) - print val if val = do_action(action, engine, context, options) + print val if val = do_action(action, engine, context, opts) end else engine.filename = '(stdin)' engine.compile!($stdin.read()) - print val if val = do_action(action, engine, context, options) + print val if val = do_action(action, engine, context, opts) end end private - def do_action(action, engine, context, options) + def do_action(action, engine, context, opts) case action when 'compile' s = engine.src - s.sub!(/^\s*[\w]+\s*\z/, '') if options[?x] when nil, 'exec', 'execute' - if options[?B] - s = engine.result(context) - else - s = engine.evaluate(context) - end + s = opts.binding ? engine.result(context) : engine.evaluate(context) + else + raise "*** internal error" end return s end def usage command = File.basename($0) - s = <<END + s = <<'END' erubis - embedded program compiler for multi-language Usage: #{command} [..options..] [file ...] -h, --help : help -v : version - -s : script source - -x : script source (removed the last '_out' line) + -x : compiled code -T : don't trim spaces around '<% %>' -b : body only (no preamble nor postamble) + -e : escape (equal to '--E Escape') -p pattern : embedded pattern (default '<% %>') -l lang : compile but no execute (ruby/php/c/java/scheme/perl/js) - -c class : class name (XmlEruby/PrintStatementEruby/...) (default Eruby) - -e enhancer,... : enhancer name (Escaped, PercentLine, BiPattern, ...) - -E : show all enhancers + -E enhancer,... : enhancer name (Escape, PercentLine, BiPattern, ...) -I path : library include path -K kanji : kanji code (euc/sjis/utf8) (default none) -f file.yaml : YAML file for context values (read stdin if filename is '-') -t : expand tab character in YAML file -S : convert mapping key from string to symbol in YAML file - -B : invoke result(binding()) instead of evaluate(context) + -B : invoke 'result(binding)' instead of 'evaluate(context)' END + # -c class : class name (XmlEruby/PercentLineEruby/...) (default Eruby) # -r library : require library # -a : action (compile/execute) return s @@ -179,7 +212,7 @@ END end s << " * #{lang}\n" list.each do |name, default_val, desc| - s << (" --%-25s : %s\n" % ["#{name}=#{default_val.inspect}", desc]) + s << (" --%-23s : %s\n" % ["#{name}=#{default_val.inspect}", desc]) end end s << "\n" @@ -187,14 +220,14 @@ END end def show_enhancers - s = '' + s = "enhancers:\n" list = [] ObjectSpace.each_object(Module) do |m| list << m end list.sort_by { |m| m.name }.each do |m| next unless m.name =~ /\AErubis::(.*)Enhancer\z/ name = $1 desc = m.desc - s << ("%-14s : %s\n" % [name, desc]) + s << (" %-13s : %s\n" % [name, desc]) end return s end @@ -229,7 +262,10 @@ END options[optchar] = true elsif arg_required.include?(optchar) arg = optstr.empty? ? argv.shift : optstr - raise CommandOptionError.new("-#{optchar.chr}: argument required.") unless arg + unless arg + mesg = "-#{optchar.chr}: #{@option_args[optchar]} required." + raise CommandOptionError.new(mesg) + end options[optchar] = arg optstr = nil elsif arg_optional.include?(optchar) @@ -290,7 +326,7 @@ END return enhancers end - def load_yamlfiles(yamlfiles, options) + def load_yamlfiles(yamlfiles, opts) hash = {} return hash unless yamlfiles yamlfiles.split(/,/).each do |yamlfile| @@ -301,12 +337,12 @@ END str = File.read(yamlfile) end str = yamlfile == '-' ? $stdin.read() : File.read(yamlfile) - str = untabify(str) if options[?t] + str = untabify(str) if opts.untabify ydoc = YAML.load(str) unless ydoc.is_a?(Hash) raise CommandOptionError.new("#{yamlfile}: root object is not a mapping.") end - convert_mapping_key_from_string_to_symbol(ydoc) if options[?S] + convert_mapping_key_from_string_to_symbol(ydoc) if opts.intern hash.update(ydoc) end context = hash diff --git a/lib/erubis/tiny.rb b/lib/erubis/tiny.rb index a6b229f..3ca6e5c 100644 --- a/lib/erubis/tiny.rb +++ b/lib/erubis/tiny.rb @@ -25,21 +25,21 @@ module Erubis EMBEDDED_PATTERN = /(.*?)<%(=+|\#)?(.*?)-?%>/m def compile(input) - src = "_out = [];" # preamble + src = "_buf = [];" # preamble input.scan(EMBEDDED_PATTERN) do |text, indicator, code| - src << " _out << '" << escape_text(text) << "';" + src << " _buf << '" << escape_text(text) << "';" if !indicator # <% %> src << code << ";" elsif indicator[0] == ?\# # <%# %> n = code.count("\n") add_stmt(src, "\n" * n) else # <%= %> - src << " _out << (" << code << ").to_s;" + src << " _buf << (" << code << ").to_s;" end end rest = $' || input - src << " _out << '" << escape_text(rest) << "';" - src << "\n_out.join\n" # postamble + src << " _buf << '" << escape_text(rest) << "';" + src << "\n_buf.join\n" # postamble return src end diff --git a/test/test-bin.rb b/test/test-bin.rb index 7453710..537ec07 100644 --- a/test/test-bin.rb +++ b/test/test-bin.rb @@ -21,6 +21,14 @@ require 'yaml' require 'tempfile' require 'erubis' +require 'erubis/main' + + +class StringWriter < String + def write(arg) + self << arg + end +end class BinTest < Test::Unit::TestCase @@ -36,23 +44,23 @@ END INPUT2 = INPUT.gsub(/\blist([^:])/, '@list\1').gsub(/\buser([^:])/, '@user\1') # SRC = <<'END' -#_out = ''; _out << "list:\n" +#_buf = ''; _buf << "list:\n" # list = ['<aaa>', 'b&b', '"ccc"'] # for item in list -#_out << " - "; _out << ( item ).to_s; _out << "\n" +#_buf << " - "; _buf << ( item ).to_s; _buf << "\n" # end -#_out << "user: "; _out << ( defined?(user) ? user : "(none)" ).to_s; _out << "\n" -#_out +#_buf << "user: "; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << "\n" +#_buf #END SRC = <<'END' -_out = []; _out << 'list: +_buf = []; _buf << 'list: '; list = ['<aaa>', 'b&b', '"ccc"'] for item in list - _out << ' - '; _out << ( item ).to_s; _out << ' + _buf << ' - '; _buf << ( item ).to_s; _buf << ' '; end - _out << 'user: '; _out << ( defined?(user) ? user : "(none)" ).to_s; _out << ' + _buf << 'user: '; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << ' '; -_out.join +_buf.join END # SRC2 = SRC.gsub(/\blist /, '@list ').gsub(/\buser /, '@user ') @@ -74,15 +82,31 @@ END def _test() + if $target + name = (caller()[0] =~ /in `test_(.*?)'/) && $1 + return unless name == $target + end if @filename == nil method = (caller[0] =~ /in `(.*)'/) && $1 #' @filename = "tmp.#{method}" end File.open(@filename, 'w') { |f| f.write(@input) } if @filename begin - command = "ruby #{$script} #{@options} #{@filename}" - output = `#{command}` + #if @options.is_a?(Array) + # command = "ruby #{$script} #{@options.join(' ')} #{@filename}" + #else + # command = "ruby #{$script} #{@options} #{@filename}" + #end + #output = `#{command}` + if @options.is_a?(Array) + argv = @options + [ @filename ] + else + argv = "#{@options} #{@filename}".split + end + $stdout = output = StringWriter.new + Erubis::Main.new.execute(argv) ensure + $stdout = STDOUT File.unlink(@filename) if @filename && test(?f, @filename) end assert_text_equal(@expected, output) @@ -105,17 +129,9 @@ END end - def test_source1 # -s + def test_source1 # -x @input = INPUT @expected = SRC - @options = '-s' - _test() - end - - - def test_source2 # -x - @input = INPUT - @expected = SRC.sub(/^_out\s*\z/, '') @options = '-x' _test() end @@ -124,7 +140,8 @@ END def test_pattern1 # -p @input = INPUT.gsub(/<%/, '<!--%').gsub(/%>/, '%-->') @expected = OUTPUT - @options = "-p '<!--% %-->'" + #@options = "-p '<!--% %-->'" + @options = ["-p", "<!--% %-->"] _test() end @@ -158,25 +175,25 @@ END def test_notrim2 # -T @input = INPUT # @expected = <<'END' -#_out = ''; _out << "list:\n" +#_buf = ''; _buf << "list:\n" # list = ['<aaa>', 'b&b', '"ccc"'] -# for item in list ; _out << "\n" -#_out << " - "; _out << ( item ).to_s; _out << "\n" -# end ; _out << "\n" -#_out << "user: "; _out << ( defined?(user) ? user : "(none)" ).to_s; _out << "\n" -#_out +# for item in list ; _buf << "\n" +#_buf << " - "; _buf << ( item ).to_s; _buf << "\n" +# end ; _buf << "\n" +#_buf << "user: "; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << "\n" +#_buf #END @expected = <<'END' -_out = []; _out << 'list: +_buf = []; _buf << 'list: '; list = ['<aaa>', 'b&b', '"ccc"'] - for item in list ; _out << ' -'; _out << ' - '; _out << ( item ).to_s; _out << ' -'; end ; _out << ' -'; _out << 'user: '; _out << ( defined?(user) ? user : "(none)" ).to_s; _out << ' + for item in list ; _buf << ' +'; _buf << ' - '; _buf << ( item ).to_s; _buf << ' +'; end ; _buf << ' +'; _buf << 'user: '; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << ' '; -_out.join +_buf.join END - @options = "-sT" + @options = "-xT" _test() end @@ -349,7 +366,7 @@ END end - def test_enhancers1 # -e + def test_enhancers1 # -E @input = <<END <% list = %w[<aaa> b&b "ccc"] %> % for item in list @@ -365,15 +382,23 @@ END - "ccc" : "ccc" - "ccc" : "ccc" END - @options = "-e Escape,PercentLine,HeaderFooter,BiPattern" + @options = "-E Escape,PercentLine,HeaderFooter,BiPattern" _test() end def test_bodyonly1 # -b @input = INPUT - @expected = SRC.sub(/\A_out = \[\];/,'').sub(/\n_out.join\n\z/,'') - @options = '-b -s' + @expected = SRC.sub(/\A_buf = \[\];/,'').sub(/\n_buf.join\n\z/,'') + @options = '-b -x' + _test() + end + + + def test_escape1 # -e + @input = INPUT + @expected = SRC.gsub(/<< \((.*?)\).to_s;/, '<< Erubis::XmlHelper.escape_xml(\1);') + @options = '-ex' _test() end diff --git a/test/test-engines.rb b/test/test-engines.rb index 4b274d7..7eea84f 100644 --- a/test/test-engines.rb +++ b/test/test-engines.rb @@ -51,20 +51,20 @@ __END__ </table> <%=== i+1 %> expected: | - _out = []; _out << '<table> + _buf = []; _buf << '<table> <tbody> '; i = 0 list.each_with_index do |item, i| - _out << ' <tr> - <td>'; _out << ( i+1 ).to_s; _out << '</td> - <td>'; _out << Erubis::XmlHelper.escape_xml( list ); _out << '</td> + _buf << ' <tr> + <td>'; _buf << ( i+1 ).to_s; _buf << '</td> + <td>'; _buf << Erubis::XmlHelper.escape_xml( list ); _buf << '</td> </tr> '; end - _out << ' </tbody> + _buf << ' </tbody> </table> - '; $stderr.puts("*** debug: i+1=#{(i+1).inspect}"); _out << ' + '; $stderr.puts("*** debug: i+1=#{(i+1).inspect}"); _buf << ' '; - _out.join + _buf.join ## - name: php1 lang: php @@ -140,7 +140,7 @@ __END__ - name: java1 lang: java class: Ejava - options: { :out: _buf, :outclass: StringBuilder, :indent: ' ' } + options: { :buf: _buf, :bufclass: StringBuilder, :indent: ' ' } input: | <table> <tbody> @@ -207,7 +207,7 @@ __END__ <%=== i %> <% ); let end %> expected: |4 - (let ((_out '())) (define (_add x) (set! _out (cons x _out))) (let ((i 0)) + (let ((_buf '())) (define (_add x) (set! _buf (cons x _buf))) (let ((i 0)) (_add "<table> <tbody>\n") @@ -227,7 +227,7 @@ __END__ </table>\n") (display "*** debug: i=")(display i)(display "\n")(_add "\n") ); let end - (reverse _out)) + (reverse _buf)) ## - name: scheme2 @@ -322,22 +322,22 @@ __END__ </table> <%=== i %> expected: |4 - var _out = []; + var _buf = []; var user = 'Erubis'; var list = ['<aaa>', 'b&b', '"ccc"']; - _out.push("<p>Hello "); _out.push(user); _out.push("!</p>\n\ + _buf.push("<p>Hello "); _buf.push(user); _buf.push("!</p>\n\ <table>\n\ <tbody>\n"); var i; for (i = 0; i < list.length; i++) { - _out.push(" <tr bgcolor="); _out.push(++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _out.push("\">\n\ - <td>"); _out.push(i); _out.push("</td>\n\ - <td>"); _out.push(list[i]); _out.push("</td>\n\ + _buf.push(" <tr bgcolor="); _buf.push(++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _buf.push("\">\n\ + <td>"); _buf.push(i); _buf.push("</td>\n\ + <td>"); _buf.push(list[i]); _buf.push("</td>\n\ </tr>\n"); } - _out.push(" </tbody>\n\ + _buf.push(" </tbody>\n\ </table>\n"); - alert("*** debug: i="+(i)); _out.push("\n"); - document.write(_out.join("")); + alert("*** debug: i="+(i)); _buf.push("\n"); + document.write(_buf.join("")); ## diff --git a/test/test-erubis.rb b/test/test-erubis.rb index d20903b..40f93b0 100644 --- a/test/test-erubis.rb +++ b/test/test-erubis.rb @@ -53,7 +53,7 @@ class ErubisTest < Test::Unit::TestCase end assert_text_equal(@src, eruby.src) - return if @testopt == 'skip_output' + return if @testopt == 'skip_bufput' list = ['<aaa>', 'b&b', '"ccc"'] context = @testopt == 'context' ? Erubis::Context.new : {} @@ -102,14 +102,14 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out.join - output: &basic1_output| + _buf.join + output: &basic1_bufput| <ul> <li><aaa></li> <li>b&b</li> @@ -127,17 +127,17 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> '; i = 0 for item in list i += 1 ^^^ - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out.join - output: *basic1_output + _buf.join + output: *basic1_bufput # <ul> # <li><aaa></li> # <li>b&b</li> @@ -151,12 +151,12 @@ __END__ i += 1 %><li><%= item %></li><% end %> </ul> src: | - _out = []; _out << '<ul>'; i = 0 + _buf = []; _buf << '<ul>'; i = 0 for item in list - i += 1 ; _out << '<li>'; _out << ( item ).to_s; _out << '</li>'; end ; _out << ' - '; _out << '</ul> + i += 1 ; _buf << '<li>'; _buf << ( item ).to_s; _buf << '</li>'; end ; _buf << ' + '; _buf << '</ul> '; - _out.join + _buf.join output: | <ul><li><aaa></li><li>b&b</li><li>"ccc"</li> </ul> @@ -170,14 +170,14 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> '; for item in @list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out.join - output: *basic1_output + _buf.join + output: *basic1_bufput ## - name: ignore1 input: | @@ -192,18 +192,18 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> '; for item in list - _out << ' <li> ';; _out << ' : '; _out << ( item ).to_s; _out << ' </li> + _buf << ' <li> ';; _buf << ' : '; _buf << ( item ).to_s; _buf << ' </li> '; end - _out << '</ul> + _buf << '</ul> '; - _out.join + _buf.join output: | <ul> <li> : <aaa> </li> @@ -219,11 +219,11 @@ __END__ b = "\"" c = '\'' src: | - _out = []; _out << 'a = "\'" + _buf = []; _buf << 'a = "\'" b = "\\"" c = \'\\\'\' '; - _out.join + _buf.join output: *quotation1_input ## - name: pattern1 @@ -236,14 +236,14 @@ __END__ [@ end @] </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out.join - output: *basic1_output + _buf.join + output: *basic1_bufput # <ul> # <li><aaa></li> # <li>b&b</li> @@ -260,14 +260,14 @@ __END__ <!--% end %--> </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out.join - output: *basic1_output + _buf.join + output: *basic1_bufput # <ul> # <li><aaa></li> # <li>b&b</li> @@ -284,13 +284,13 @@ __END__ # <% end %> # </ul> src: | - _out = []; _out << '<ul> - '; _out << ' '; for item in list ; _out << ' - '; _out << ' <li>'; _out << ( item ).to_s; _out << '</li> - '; _out << ' '; end ; _out << ' - '; _out << '</ul> + _buf = []; _buf << '<ul> + '; _buf << ' '; for item in list ; _buf << ' + '; _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> + '; _buf << ' '; end ; _buf << ' + '; _buf << '</ul> '; - _out.join + _buf.join output: | <ul> ^ @@ -303,15 +303,15 @@ __END__ </ul> ## - name: bodyonly1 - testopt: skip_output + testopt: skip_bufput options: { :preamble: no, :postamble: no } input: *basic1_input src: |4 - _out << '<ul> + _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; chomp: [src] expected: null @@ -327,14 +327,14 @@ __END__ input: "<ul>\r\n <% for item in list %>\r\n <li><%= item %></li>\r\n <% end %>\r\n</ul>\r\n" #src: | - # _out = ''; _out << "<ul>\n" + # _buf = ''; _buf << "<ul>\n" # for item in list - # _out << " <li>"; _out << ( item ).to_s; _out << "</li>\n" + # _buf << " <li>"; _buf << ( item ).to_s; _buf << "</li>\n" # end - # _out << "</ul>\n" - # _out + # _buf << "</ul>\n" + # _buf src: - "_out = []; _out << '<ul>\r\n'; for item in list \r\n _out << ' <li>'; _out << ( item ).to_s; _out << '</li>\r\n'; end \r\n _out << '</ul>\r\n';\n_out.join\n" + "_buf = []; _buf << '<ul>\r\n'; for item in list \r\n _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>\r\n'; end \r\n _buf << '</ul>\r\n';\n_buf.join\n" #output: | # <ul> # <li><aaa></li> @@ -352,11 +352,11 @@ __END__ <li>foo</li> </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> <li>foo</li> </ul> '; - _out.join + _buf.join output: *nomatch1 ## - name: xml1 @@ -369,14 +369,14 @@ __END__ <% end %> </pre> src: | - _out = []; _out << '<pre> + _buf = []; _buf << '<pre> '; for item in list - _out << ' '; _out << Erubis::XmlHelper.escape_xml( item ); _out << ' - '; _out << ' '; _out << ( item ).to_s; _out << ' + _buf << ' '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << ' + '; _buf << ' '; _buf << ( item ).to_s; _buf << ' '; end - _out << '</pre> + _buf << '</pre> '; - _out.join + _buf.join output: | <pre> <aaa> @@ -389,7 +389,7 @@ __END__ ## - name: xml2 class: XmlEruby - testopt: skip_output + testopt: skip_bufput input: | <% for item in list %> <%= item["var#{n}"] %> @@ -398,13 +398,13 @@ __END__ <%==== item["var#{n}"] %> <% end %> src: | - _out = []; for item in list - _out << ' '; _out << Erubis::XmlHelper.escape_xml( item["var#{n}"] ); _out << ' - '; _out << ' '; _out << ( item["var#{n}"] ).to_s; _out << ' - '; _out << ' '; $stderr.puts("*** debug: item[\"var\#{n}\"]=#{(item["var#{n}"]).inspect}"); _out << ' - '; _out << ' '; _out << ' + _buf = []; for item in list + _buf << ' '; _buf << Erubis::XmlHelper.escape_xml( item["var#{n}"] ); _buf << ' + '; _buf << ' '; _buf << ( item["var#{n}"] ).to_s; _buf << ' + '; _buf << ' '; $stderr.puts("*** debug: item[\"var\#{n}\"]=#{(item["var#{n}"]).inspect}"); _buf << ' + '; _buf << ' '; _buf << ' '; end - _out.join + _buf.join output: | ## - name: printout1 @@ -418,7 +418,7 @@ __END__ '; end print '</ul> '; - output: *basic1_output + output: *basic1_bufput ## - name: printenabled1 class: PrintEnabledEruby @@ -429,14 +429,14 @@ __END__ <% end %> </ul> src: | - @_out = _out = []; _out << '<ul> + @_buf = _buf = []; _buf << '<ul> '; for item in list - _out << ' <li>'; print item ; _out << '</li> + _buf << ' <li>'; print item ; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out.join - output: *basic1_output + _buf.join + output: *basic1_bufput # <ul> # <li><aaa></li> # <li>b&b</li> @@ -453,14 +453,14 @@ __END__ # <% end %> # </ul> src: | - _out = $stdout; _out << '<ul> + _buf = $stdout; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; '' - output: *basic1_output + output: *basic1_bufput # <ul> # <li><aaa></li> # <li>b&b</li> @@ -476,13 +476,13 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> + _buf = []; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out + _buf output: - "<ul>\n" - " <li>" @@ -505,14 +505,14 @@ __END__ # <% end %> # </ul> src: | - _out = ''; _out << '<ul> + _buf = ''; _buf << '<ul> '; for item in list - _out << ' <li>'; _out << ( item ).to_s; _out << '</li> + _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li> '; end - _out << '</ul> + _buf << '</ul> '; - _out - output: *basic1_output + _buf + output: *basic1_bufput # <ul> # <li><aaa></li> # <li>b&b</li> @@ -523,12 +523,12 @@ __END__ class: NoTextEruby input: *basic1_input src: | - _out = []; + _buf = []; for item in list - _out << ( item ).to_s; + _buf << ( item ).to_s; end - _out.join + _buf.join output: '<aaa>b&b"ccc"' ## - name: simplified @@ -542,15 +542,15 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> - '; for item in list ; _out << ' + _buf = []; _buf << '<ul> + '; for item in list ; _buf << ' <li> - '; _out << ( item ).to_s; _out << ' + '; _buf << ( item ).to_s; _buf << ' </li> - '; end ; _out << ' + '; end ; _buf << ' </ul> '; - _out.join + _buf.join output: | <ul> ^ @@ -577,11 +577,11 @@ __END__ [= item =] = [== item =] <% end %> src: | - _out = []; for item in list - _out << ' '; _out << ( item ).to_s; _out << ' % '; _out << Erubis::XmlHelper.escape_xml( item ); _out << ' - '; _out << ' '; _out << ( item ).to_s; _out << ' = '; _out << Erubis::XmlHelper.escape_xml( item ); _out << ' + _buf = []; for item in list + _buf << ' '; _buf << ( item ).to_s; _buf << ' % '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << ' + '; _buf << ' '; _buf << ( item ).to_s; _buf << ' = '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << ' '; end - _out.join + _buf.join output: |4 <aaa> % <aaa> <aaa> = <aaa> @@ -599,11 +599,11 @@ __END__ ${item} = ${=item} <% end %> src: | - _out = []; for item in list - _out << ' '; _out << (item).to_s; _out << ' % '; _out << Erubis::XmlHelper.escape_xml(item); _out << ' - '; _out << ' '; _out << (item).to_s; _out << ' = '; _out << Erubis::XmlHelper.escape_xml(item); _out << ' + _buf = []; for item in list + _buf << ' '; _buf << (item).to_s; _buf << ' % '; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' + '; _buf << ' '; _buf << (item).to_s; _buf << ' = '; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' '; end - _out.join + _buf.join output: |4 <aaa> % <aaa> <aaa> = <aaa> @@ -629,20 +629,20 @@ __END__ % spaced percent </pre> src: | - _out = []; _out << '<table> + _buf = []; _buf << '<table> '; for item in list - _out << ' <tr> - <td>'; _out << ( item ).to_s; _out << '</td> - <td>'; _out << Erubis::XmlHelper.escape_xml( item ); _out << '</td> + _buf << ' <tr> + <td>'; _buf << ( item ).to_s; _buf << '</td> + <td>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</td> </tr> '; end - _out << '</table> + _buf << '</table> <pre> - '; _out << '% double percent - '; _out << ' % spaced percent + '; _buf << '% double percent + '; _buf << ' % spaced percent </pre> '; - _out.join + _buf.join output: | <table> <tr> @@ -681,13 +681,13 @@ __END__ def ordered_list(list) - _out = []; _out << '<ol> + _buf = []; _buf << '<ol> '; for item in list - _out << ' <li>'; _out << Erubis::XmlHelper.escape_xml(item); _out << '</li> + _buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li> '; end - _out << '</ol> + _buf << '</ol> '; - _out.join + _buf.join end output: | <ol> @@ -709,17 +709,17 @@ __END__ </table> <ul><% for item in list %><li><%= item %></li><% end %></ul> src: | - _out = '<table> + _buf = '<table> '; for item in list - _out << ' <tr> + _buf << ' <tr> <td>' << ( item ).to_s << '</td> <td>' << Erubis::XmlHelper.escape_xml( item ) << '</td> </tr> '; end - _out << '</table> - <ul>'; for item in list ; _out << '<li>' << ( item ).to_s << '</li>'; end ; _out << '</ul> + _buf << '</table> + <ul>'; for item in list ; _buf << '<li>' << ( item ).to_s << '</li>'; end ; _buf << '</ul> ' - _out + _buf output: | <table> <tr> @@ -750,17 +750,17 @@ __END__ # </table> # <ul><% for item in list %><li><%= item %></li><% end %></ul> src: | - _out = '<table> + _buf = '<table> '; for item in list - _out << ' <tr> + _buf << ' <tr> <td>' << Erubis::XmlHelper.escape_xml( item ) << '</td> <td>' << ( item ).to_s << '</td> </tr> '; end - _out << '</table> - <ul>'; for item in list ; _out << '<li>' << Erubis::XmlHelper.escape_xml( item ) << '</li>'; end ; _out << '</ul> + _buf << '</table> + <ul>'; for item in list ; _buf << '<li>' << Erubis::XmlHelper.escape_xml( item ) << '</li>'; end ; _buf << '</ul> ' - _out + _buf output: | <table> <tr> @@ -787,12 +787,12 @@ __END__ <%= item %> <% end %> src: | - _out = 'user = '; _out << ( "Foo" ).to_s << ' + _buf = 'user = '; _buf << ( "Foo" ).to_s << ' '; for item in list - _out << ' ' << ( item ).to_s << ' + _buf << ' ' << ( item ).to_s << ' '; end - _out + _buf output: | user = Foo <aaa> @@ -807,11 +807,11 @@ __END__ b = "\"" c = '\'' src: | - _out = 'a = "\'" + _buf = 'a = "\'" b = "\\"" c = \'\\\'\' '; - _out + _buf output: *optimized4_input ## - name: tiny1 @@ -824,13 +824,13 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> - '; for item in list ; _out << ' - <li>'; _out << ( item ).to_s; _out << '</li> - '; end ; _out << ' + _buf = []; _buf << '<ul> + '; for item in list ; _buf << ' + <li>'; _buf << ( item ).to_s; _buf << '</li> + '; end ; _buf << ' </ul> '; - _out.join + _buf.join output: | <ul> ^ @@ -852,13 +852,13 @@ __END__ <% end %> </ul> src: | - _out = []; _out << '<ul> - '; for item in @list ; _out << ' - <li>'; _out << ( item ).to_s; _out << '</li> - '; end ; _out << ' + _buf = []; _buf << '<ul> + '; for item in @list ; _buf << ' + <li>'; _buf << ( item ).to_s; _buf << '</li> + '; end ; _buf << ' </ul> '; - _out.join + _buf.join output: | <ul> ^ diff --git a/website/Rookbook.rb b/website/Rookbook.rb index 46c9999..5c2ec71 100644 --- a/website/Rookbook.rb +++ b/website/Rookbook.rb @@ -10,14 +10,16 @@ material 'index.txt' ## recipes for kuwata-lab.com ## #all = %W[index.xhtml README.xhtml #{U}.01.xhtml ChangeLog.txt] -all = %W[index.xhtml #{U}.01.xhtml ChangeLog.txt] +all = %W[index.xhtml #{U}.01.xhtml ChangeLog] + +recipe :default , :all recipe :all , all recipe :clean do files = [] files.concat Dir.glob("README.*") - files.concat Dir.glob("ChangeLog.*") + files.concat Dir.glob("ChangeLog") files.concat Dir.glob("#{U}.*") files.concat(%w[m18n.rb guide.d index.xhtml]) rm_rf [files] @@ -40,13 +42,12 @@ recipe "#{U}.01.xhtml" , "#{U}.txt", :byprods=>["#{U}.toc.html"] do files << "#{U}.html" #p files files.each do |old| - new = old.sub(/\.html$/, '.xhtml') - File.rename(old, new) if old != new + new = old.sub(/\.html$/, '.xhtml') + File.rename(old, new) if old != new end rm_f @byprods end - #recipe 'README.xhtml' , '../README' do # tagfile = website_tagfile # sys "kwaser -t #{tagfile} -b #{@ingred} > #{@product}" @@ -65,7 +66,8 @@ recipe "index.xhtml" , "index.txt", # sys "kwaser -t #{tagfile} -b #{@ingred} > #{@product}" # end -recipe "ChangeLog.txt" , "../ChangeLog.txt" do +recipe "ChangeLog" , "../ChangeLog" do #copy r.ingreds[0], r.product cp @ingred, "." end + diff --git a/website/index.txt b/website/index.txt index 6577931..2053d4a 100644 --- a/website/index.txt +++ b/website/index.txt @@ -5,10 +5,8 @@ .$ News -.: 2006-05-05 - .- {{<erubis_2.0.0|download.cgi>}} released. -.: 2006-03-05 - .- {{<erubis_1.1.0|download.cgi>}} released. +.* [2006-05-??] {{<erubis_2.0.0|download.cgi>}} released. +.* [2006-03-05] {{<erubis_1.1.0|download.cgi>}} released. .$ Introduction @@ -39,7 +37,7 @@ .#</table> .#.+++++ -Erubis is an pure Ruby implementation of eRuby. +Erubis is a pure Ruby implementation of eRuby. It has the following features. .* Very fast, almost three times faster than ERB and even as fast as eruby (implemented in C) .* Auto escaping (sanitizing) support @@ -47,24 +45,27 @@ It has the following features. .* Embedded pattern changeable (default '<% %>') .* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript) .* Context object available and easy to combine eRuby template with YAML datafile -.* Print statement available -.* Easy to expand in subclass +.* Easy to expand in subclass, for example: + .- Print statement support + .- Lines starting with percent character ('%') support + .- Another embedded pattern support + .- etc... eRuby is "embedded Ruby" in documents. The following is an example of eRuby. '<% ... %>' means Ruby statement and '<%= ... %>' means Ruby expression. .? example.eruby .-------------------- example.eruby -Hello <%= user %>! -<% for item in list %> +Hello <%= @user %>! +<% for item in @list %> * <%= item %> <% end %> .-------------------- This will be compiled into Ruby program code. .==================== -$ erubis -l ruby example.eruby -.<<<:! erubis -l ruby example.eruby +$ erubis -x example.eruby +.<<<:! erubis -x example.eruby .==================== Or you can execute eRuby script directry. @@ -87,7 +88,7 @@ list: Erubis supports not only Ruby but also PHP, C, Java, Scheme, Perl, and Javascript. -You can embed these language code into your document and compile it to target program code. +You can embed these language code into your document and compile it into target program code. .$ Download @@ -97,7 +98,7 @@ You can embed these language code into your document and compile it to target pr .$ Documents .#.* {{<README|README.en.html>}} .* {{<Users' guide|users-guide.html>}} - .* {{<Changelog|ChangeLog.txt>}} + .* {{<Changelog|ChangeLog>}} .$ License .* {{<GNU General Public License ver.2|http://www.gnu.org/copyleft/gpl.html>}} diff --git a/website/index.xhtml b/website/index.xhtml index a9ca684..cf636d2 100644 --- a/website/index.xhtml +++ b/website/index.xhtml @@ -23,30 +23,18 @@ <h1 id="doc_title">Erubis</h1> <a name="News"></a> <h2 class="section">News</h2> -<dl class="dl1"> -<dt class="dt1"> -2006-05-05</dt> -<dd class="dd1"> - <ul class="ul2"> - <li><a href="download.cgi">erubis_2.0.0</a> released. - </li> - </ul> -</dd> -<dt class="dt1"> -2006-03-05</dt> -<dd class="dd1"> - <ul class="ul2"> - <li><a href="download.cgi">erubis_1.1.0</a> released. - </li> - </ul> -</dd> -</dl> +<ul class="ul1"> +<li>[2006-05-??] <a href="download.cgi">erubis_2.0.0</a> released. +</li> +<li>[2006-03-05] <a href="download.cgi">erubis_1.1.0</a> released. +</li> +</ul> <a name="Introduction"></a> <h2 class="section">Introduction</h2> -<p>Erubis is an pure Ruby implementation of eRuby. +<p>Erubis is a pure Ruby implementation of eRuby. It has the following features. </p> <ul class="ul1"> @@ -62,9 +50,17 @@ It has the following features. </li> <li>Context object available and easy to combine eRuby template with YAML datafile </li> -<li>Print statement available -</li> -<li>Easy to expand in subclass +<li>Easy to expand in subclass, for example: + <ul class="ul2"> + <li>Print statement support + </li> + <li>Lines starting with percent character ('%') support + </li> + <li>Another embedded pattern support + </li> + <li>etc... + </li> + </ul> </li> </ul> <p>eRuby is "embedded Ruby" in documents. @@ -72,20 +68,19 @@ The following is an example of eRuby. '<% ... %>' means Ruby statement and </p> <a name="example.eruby"></a> <div class="program_caption">example.eruby</div> -<pre class="program">Hello <%= user %>! -<% for item in list %> +<pre class="program">Hello <%= @user %>! +<% for item in @list %> * <%= item %> <% end %> </pre> <p>This will be compiled into Ruby program code. </p> -<pre class="terminal">$ erubis -l ruby example.eruby -_out = []; _out << 'Hello '; _out << ( user ).to_s; _out << '! -'; for item in list -; _out << ' * '; _out << ( item ).to_s; _out << ' +<pre class="terminal">$ erubis -x example.eruby +_buf = []; _buf << 'Hello '; _buf << ( @user ).to_s; _buf << '! +'; for item in @list + _buf << ' * '; _buf << ( item ).to_s; _buf << ' '; end -; -_out.join +_buf.join </pre> <p>Or you can execute eRuby script directry. </p> @@ -102,7 +97,7 @@ Hello Erubis! * ccc </pre> <p>Erubis supports not only Ruby but also PHP, C, Java, Scheme, Perl, and Javascript. -You can embed these language code into your document and compile it to target program code. +You can embed these language code into your document and compile it into target program code. </p> |