Created
November 28, 2010 14:41
-
-
Save seki/718984 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
compiler.pre_cmd = ["#{eoutvar} = ERB4Html.quoted('')"] | |
compiler.post_cmd = [eoutvar] | |
end | |
end | |
if __FILE__ == $0 | |
str = '<%= str %>' | |
puts str | |
erb = ERB4Html.new(str) | |
str = erb.result(binding) | |
puts str | |
puts erb.result(binding) | |
str = String.new(str) | |
puts erb.result(binding) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment