Created
May 23, 2011 05:24
-
-
Save ttakezawa/986261 to your computer and use it in GitHub Desktop.
basic eRuby implementation
This file contains hidden or 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
#!/usr/bin/ruby | |
# via [ruby-list:48093] | |
def eRuby(eruby_source) | |
source = eruby_source | |
ruby = '' | |
loop do | |
break if source.empty? | |
if source=~/<%=/m | |
text = $` | |
if text != "" | |
ruby << "print(#{text.dump})\n" | |
end | |
source = $' | |
if source=~/%>/m | |
code = $` | |
if code != "" | |
ruby << "print(#{code})\n" | |
end | |
source=$' | |
next | |
else | |
raise "<%= unmatch error" | |
end | |
end | |
if source=~/<%/m | |
text = $` | |
if text != "" | |
ruby << "print(#{text.dump})\n" | |
end | |
source = $' | |
if source=~/%>/m | |
code = $` | |
if code != "" | |
ruby << code << "\n" | |
end | |
source=$' | |
next | |
else | |
raise "<% unmatch error" | |
end | |
end | |
ruby << "print(#{source.dump})\n" | |
break | |
end | |
ruby | |
end | |
if $0==__FILE__ | |
print eRuby(STDIN.read) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment