diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-18 15:02:36 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-18 15:02:36 +0000 |
commit | 8480bcc8d5c72b61055cfa98e80f37fd62ae7ad4 (patch) | |
tree | f404254dbcee2a59866dbb3f7baab4df8e4b23ce /sample/erb | |
parent | 32378c5abea38a8278dae28eae9abcd547ac8a95 (diff) |
Merge -r16241:16456 from ruby_1_8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/erb')
-rw-r--r-- | sample/erb/erb4html.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/sample/erb/erb4html.rb b/sample/erb/erb4html.rb new file mode 100644 index 0000000000..df0ffae44f --- /dev/null +++ b/sample/erb/erb4html.rb @@ -0,0 +1,60 @@ +require 'erb' + +class ERB + class ERBString < String + def to_s; self; end + + def erb_concat(s) + if self.class === s + concat(s) + else + concat(erb_quote(s)) + end + end + + def erb_quote(s); s; end + end +end + +class ERB4Html < ERB + def self.quoted(s) + HtmlString.new(s) + end + + class HtmlString < ERB::ERBString + def erb_quote(s) + ERB::Util::html_escape(s) + end + end + + def set_eoutvar(compiler, eoutvar = '_erbout') + compiler.put_cmd = "#{eoutvar}.concat" + compiler.insert_cmd = "#{eoutvar}.erb_concat" + + cmd = [] + cmd.push "#{eoutvar} = ERB4Html.quoted('')" + + compiler.pre_cmd = cmd + + cmd = [] + cmd.push(eoutvar) + + compiler.post_cmd = cmd + end +end + +if __FILE__ == $0 + page = <<EOP +<title><%=title%></title> +<p><%=para%></p> +EOP + erb = ERB4Html.new(page) + + title = "<auto-quote>" + para = "<quoted>" + puts erb.result + + title = "<auto-quote>" + para = ERB4Html.quoted("<quoted>") + puts erb.result +end |