Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
[ANN] Erubis 1.1.0 - an implementation of eRuby
Makoto Kuwata
3/6/2006 2:53:00 PM
I have released Erubis 1.1.0.
http://rubyforge.org/projec...
Erubis is an implementation of eRuby.
It has the following features:
* Auto sanitizing support
* Embedded pattern changeable (default '<% %>')
* Auto trimming spaces around '<% %>'
* Context object available
* Print statement available
* Faster mode support
* Easy to expand in subclass
Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
Sample code (example.rb):
--------------------
## eRuby script
## ('<%= %>' is escaped and '<%== %>' is not escaped when XmlEruby)
input = <<END
<ul>
<% for item in list %>
<li><%= item %>
<%== item %></li>
<% end %>
</ul>
END
## create Eruby object
require 'erubis'
eruby = Erubis::XmlEruby.new(input) # or Erubis::Eruby.new(input)
## get result
list = ['<aaa>', 'b&b', '"ccc"']
puts eruby.result(binding())
--------------------
result:
====================
$ ruby example.rb
<ul>
<li><aaa>
<aaa></li>
<li>b&b
b&b</li>
<li>"ccc"
"ccc"</li>
</ul>
====================
See doc/users-guide.html in archive for details.
: Enhancement from 1.0.1
* '<%# .. %>' supported. Erubis ignores '<%# %>'.
* New class PrintEruby and PrintXmlEruby available.
These class enables you to embed print statement in eRuby
(this feature is not supported in ERB).
ex. example.eb
--------------------
## data and context
list = ['aaa', 'bbb', 'ccc']
context = { :list => list }
## eRuby script
## (use print statement instead of <%= item %>)
input = <<-END
<ul>
<% for item in list %>
<li><% print item %></li>
<% end %>
</ul>
END
## create eruby and get result as string
require 'erubis'
eruby = Erubis::PrintEruby.new(input)
str = eruby.evaluate(context) # don't use result()!
print str
--------------------
result:
====================
$ ruby example.rb
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ul>
====================
Have fun!
--
regards,
kwatch
1 Answer
Gyoung-Yoon Noh
3/7/2006 2:53:00 AM
0
On 3/6/06, kwatch <kwa@kuwata-lab.com> wrote:> I have released Erubis 1.1.0.>
http://rubyforge.org/projects/erubi...
Erubis is an implementation of eRuby.> It has the following features:>> * Auto sanitizing support> * Embedded pattern changeable (default '<% %>')> * Auto trimming spaces around '<% %>'> * Context object available> * Print statement available> * Faster mode support> * Easy to expand in subclass>> Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.>> Sample code (example.rb):> --------------------> ## eRuby script> ## ('<%= %>' is escaped and '<%== %>' is not escaped when XmlEruby)> input = <<END> <ul>> <% for item in list %>> <li><%= item %>> <%== item %></li>> <% end %>> </ul>> END>> ## create Eruby object> require 'erubis'> eruby = Erubis::XmlEruby.new(input) # or Erubis::Eruby.new(input)>> ## get result> list = ['<aaa>', 'b&b', '"ccc"']> puts eruby.result(binding())> -------------------->> result:> ====================> $ ruby example.rb> <ul>> <li><aaa>> <aaa></li>> <li>b&b> b&b</li>> <li>"ccc"> "ccc"</li>> </ul>> ====================>> See doc/users-guide.html in archive for details.>>> : Enhancement from 1.0.1>> * '<%# .. %>' supported. Erubis ignores '<%# %>'.>> * New class PrintEruby and PrintXmlEruby available.> These class enables you to embed print statement in eRuby> (this feature is not supported in ERB).>> ex. example.eb> --------------------> ## data and context> list = ['aaa', 'bbb', 'ccc']> context = { :list => list }>> ## eRuby script> ## (use print statement instead of <%= item %>)> input = <<-END> <ul>> <% for item in list %>> <li><% print item %></li>> <% end %>> </ul>> END>> ## create eruby and get result as string> require 'erubis'> eruby = Erubis::PrintEruby.new(input)> str = eruby.evaluate(context) # don't use result()!> print str> -------------------->> result:> ====================> $ ruby example.rb> <ul>> <li>aaa</li>> <li>bbb</li>> <li>ccc</li>> </ul>> ====================>> Have fun!>> --> regards,> kwatch>>>Nice work, very cool features.But can we replace current erb usage in Rails without any problem?I've used some hackish 'concat string, binding'.--
http://nohmad.su...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
[ANN] Erubis 1.1.0 - an implementation of eRuby
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password