diff options
-rw-r--r-- | ChangeLog.txt | 10 | ||||
-rw-r--r-- | Rookbook.yaml | 4 | ||||
-rw-r--r-- | examples/example.ec | 20 | ||||
-rw-r--r-- | lib/erubis/engine/ec.rb | 8 | ||||
-rw-r--r-- | lib/erubis/main.rb | 34 | ||||
-rw-r--r-- | test/test-engines.rb | 4 |
6 files changed, 55 insertions, 25 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt index 54760aa..4181b80 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,16 @@ .?lastupdate: $Date$ .?version: $Rev$ +.: Rev.26 (2005-05-22) + .- [change] Ec#escaped_expr() changed to use 'escape(expr, out)' + .- [change] 'examples/example.ec' changed to include escape() function + .- [change] include 'bin/notext' into archive + .- [bugfix] command name was not displayed in help message + .- [bugfix] option '-S' currently support nested collection + +.: Rev.25 (2005-05-21) + .- [release] 2.0.1 + .: Rev.24 (2005-05-21) .- [change] Engine#escape_text() and Engine#escaped_expr() are now abstract method .- [bugfix] in Engine#compile(), rspace may be printed even if rspace is nil diff --git a/Rookbook.yaml b/Rookbook.yaml index f45beed..a5e7030 100644 --- a/Rookbook.yaml +++ b/Rookbook.yaml @@ -77,7 +77,7 @@ recipes: ingreds: [ $(project)_$(1) ] method: | rm_f @product if test(?f, @product) - tar_cjf @product, @ingred + tar_czf @product, @ingred - product: $(project)_*.zip desc: create *.zip @@ -111,7 +111,7 @@ recipes: rm_rf dir if test(?d, dir) mkdir_p dir # - store 'lib/**/*', 'bin/erubis', 'test/**/*', text_files, dir do |f| + store 'lib/**/*', 'bin/notext', 'test/**/*', text_files, dir do |f| base = File.basename(f) !exclude_libs.include?(base) end diff --git a/examples/example.ec b/examples/example.ec index 06e7961..1a1787f 100644 --- a/examples/example.ec +++ b/examples/example.ec @@ -1,12 +1,14 @@ <% #include <stdio.h> +void escape(char *str, FILE *out); + int main(int argc, char *argv[]) { int i; %> -<p>Hello <%= "%s", argv[0] %>!</p> +<p>Hello <%== argv[0] %>!</p> <table> <tbody> <% for (i = 1; i < argc; i++) { %> @@ -21,4 +23,20 @@ int main(int argc, char *argv[]) return 0; } + +void escape(char *str, FILE *out) +{ + char *pch; + for (pch = str; *pch != '\0'; pch++) { + switch (*pch) { + case '&': fputs("&", out); break; + case '>': fputs(">", out); break; + case '<': fputs("<", out); break; + case '"': fputs(""", out); break; + case '\'': fputs("'", out); break; + default: fputc(*pch, out); + } + } +} + %> diff --git a/lib/erubis/engine/ec.rb b/lib/erubis/engine/ec.rb index 0a8e6c1..0c6a93f 100644 --- a/lib/erubis/engine/ec.rb +++ b/lib/erubis/engine/ec.rb @@ -42,11 +42,7 @@ module Erubis def escaped_expr(code) @escape ||= "escape" code.strip! - if code =~ /\A(\".*?\")\s*,\s*(.*)/ - return "#{$1}, #{@escape}(#{$2})" - else - return "#{@escape}(#{code})" - end + return "#{@escape}(#{code}, #{@out})" end def add_text(src, text) @@ -74,7 +70,7 @@ module Erubis def add_expr_escaped(src, code) src << @indent if src.empty? || src[-1] == ?\n - src << " fprintf(#{@out}, " << escaped_expr(code) << ');' + src << " " << escaped_expr(code) << ';' end def add_expr_debug(src, code) diff --git a/lib/erubis/main.rb b/lib/erubis/main.rb index 7a1278e..6902810 100644 --- a/lib/erubis/main.rb +++ b/lib/erubis/main.rb @@ -176,7 +176,7 @@ module Erubis def usage command = File.basename($0) - s = <<'END' + s = <<END erubis - embedded program compiler for multi-language Usage: #{command} [..options..] [file ...] -h, --help : help @@ -196,6 +196,7 @@ Usage: #{command} [..options..] [file ...] -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) @@ -283,13 +284,13 @@ END return options, context end - def untabify(text, width=8) + def untabify(str, width=8) sb = '' - text.scan(/(.*?)\t/m) do |s, | + str.scan(/(.*?)\t/m) do |s, | len = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length sb << s << (" " * (width - len % width)) end - return $' ? (sb << $') : text + return $' ? (sb << $') : str end def get_classobj(classname, lang) @@ -342,25 +343,30 @@ END 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 opts.intern + intern_hash_keys(ydoc) if opts.intern hash.update(ydoc) end context = hash return context end - def convert_mapping_key_from_string_to_symbol(ydoc) - if ydoc.is_a?(Hash) - ydoc.each do |key, val| - ydoc[key.intern] = ydoc.delete(key) if key.is_a?(String) - convert_mapping_key_from_string_to_symbol(val) + def intern_hash_keys(obj, done={}) + return if done.key?(obj.__id__) + case obj + when Hash + done[obj.__id__] = obj + obj.keys.each do |key| + obj[key.intern] = obj.delete(key) if key.is_a?(String) end - elsif ydoc.is_a?(Array) - ydoc.each do |val| - convert_mapping_key_from_string_to_symbol(val) + obj.values.each do |val| + intern_hash_keys(val, done) if val.is_a?(Hash) || val.is_a?(Array) + end + when Array + done[obj.__id__] = obj + obj.each do |val| + intern_hash_keys(val, done) if val.is_a?(Hash) || val.is_a?(Array) end end - return ydoc end end diff --git a/test/test-engines.rb b/test/test-engines.rb index 7eea84f..9a7dffd 100644 --- a/test/test-engines.rb +++ b/test/test-engines.rb @@ -117,7 +117,7 @@ __END__ <% for (i = 0; i < list; i++) { %> <tr> <td><%= "%d", i %></td> - <td><%== "%s", list[i] %></td> + <td><%== list[i] %></td> </tr> <% } %> </tbody> @@ -130,7 +130,7 @@ __END__ for (i = 0; i < list; i++) { fputs(" <tr>\n" " <td>", stdout); fprintf(stdout, "%d", i); fputs("</td>\n" - " <td>", stdout); fprintf(stdout, "%s", escape(list[i])); fputs("</td>\n" + " <td>", stdout); escape(list[i], stdout); fputs("</td>\n" " </tr>\n", stdout); } fputs(" </tbody>\n" |