Created
July 9, 2014 16:42
-
-
Save kwatch/6de44a5532787e94b757 to your computer and use it in GitHub Desktop.
ヒアドキュメントとBabyErubisの組み合わせ例。テンプレート内のエラーでも、正確なファイル名と行番号が表示されることに注目!
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
# -*- coding: utf-8 -*- | |
require 'baby_erubis' | |
erb = BabyErubis::Html.new.from_str <<'END', __FILE__, __LINE__+1 | |
<html> | |
<body> | |
<ul> | |
<% (1..3).each do %> | |
<li><%= x %></li> | |
<% end %> | |
</ul> | |
</body> | |
</html> | |
END | |
html = erb.render() | |
print "Content-Type: text/html;charset=utf-8\r\n" | |
print "\r\n" | |
print html | |
#### 実行結果:BabyErubisを使えば、eRubyテンプレート内のエラーであっても、 | |
#### 正確なファイル名と行番号が表示される!(最初の「ex-heredoc2.rb:10」がそれ) | |
# ex-heredoc2.rb:10:in `block (2 levels) in empty_binding': undefined local variable or method `x' for #<BabyErubis::HtmlTemplateContext:0x000001010a48d8> (NameError) | |
# from ex-heredoc2.rb:9:in `each' | |
# from ex-heredoc2.rb:9:in `block in empty_binding' | |
# from /Users/kwatch/src/baby_erubis/lib/baby_erubis.rb:107:in `instance_eval' | |
# from /Users/kwatch/src/baby_erubis/lib/baby_erubis.rb:107:in `render' | |
# from ex-heredoc2.rb:16:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment