Forum: Ruby can erb produce erb?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae9d53ff558bb66a7b181997af89c11f?d=identicon&s=25 talkin ruby (Guest)
on 2007-04-06 20:36
(Received via mailing list)
just wondering if you could do something like this...

ERB.new( some_erb_string ).result  #  '<%= result %>'  another erb
template

so that way the result could be processed by another ERB.new
4d5b5dd4e263d780a5dfe7ac8b8ac98c?d=identicon&s=25 Tim Pease (Guest)
on 2007-04-06 21:08
(Received via mailing list)
On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
> just wondering if you could do something like this...
>
> ERB.new( some_erb_string ).result  #  '<%= result %>'  another erb template
>
> so that way the result could be processed by another ERB.new
>

You are an evil and twisted individual!  ;)

To answer your question, though, sure!  ERb can do that.

require 'erb'

@blah = '<%= @not_blah %>'
ERB.new( "blah <%= @blah %>" ).result    #=>  "blah <%= @not_blah %>"


Blessings,
TwP
Dedb38b3571b323b77bc9b221e940172?d=identicon&s=25 RubyTalk@gmail.com (Guest)
on 2007-04-06 22:35
(Received via mailing list)
@maybe= val.nil? ? true : false

blah <%%=  <%= @maybe %>  %>

I use this format in generators for rails.  I dont know if it is as
clean
looking for short example but for full rhtml pages it works well.

Stephen Becker IV

On 4/6/07, Tim Pease <tim.pease@gmail.com> wrote:
> On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
> > just wondering if you could do something like this...
> >
> > ERB.new( some_erb_string ).result  #  '<%= result %>'  another erb
template
Ae9d53ff558bb66a7b181997af89c11f?d=identicon&s=25 talkin ruby (Guest)
on 2007-04-06 22:48
(Received via mailing list)
thanks! that is exactly what I needed!
851acbab08553d1f7aa3eecad17f6aa9?d=identicon&s=25 Ken Bloom (Guest)
on 2007-04-08 04:10
(Received via mailing list)
On Sat, 07 Apr 2007 04:07:16 +0900, Tim Pease wrote:

>
> To answer your question, though, sure!  ERb can do that.
>
> require 'erb'
>
> @blah = '<%= @not_blah %>'
> ERB.new( "blah <%= @blah %>" ).result    #=>  "blah <%= @not_blah %>"

If you really want to be evil and twisted, what's the smallest self-
reproducing erb program you can write that doesn't read its own file.

The following solution is illegal:
<%= open(__FILE__){|f| f.read} %>

--Ken
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (regularfry)
on 2007-04-08 09:31
(Received via mailing list)
Ken Bloom wrote:
>>>
> reproducing erb program you can write that doesn't read its own file.
>
> The following solution is illegal:
> <%= open(__FILE__){|f| f.read} %>
I think you mean "what's the smallest non-trivial self-reproducing erb
program...":

irb(main):012:0> ERB.new(' ').result
=> " "
irb(main):013:0> ERB.new('').result
=> ""

:-)
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (regularfry)
on 2007-04-08 11:05
(Received via mailing list)
Ken Bloom wrote:
>>>
> reproducing erb program you can write that doesn't read its own file.
>
> The following solution is illegal:
> <%= open(__FILE__){|f| f.read} %>

Drat.  This nearly works:

<%=s=";\"<%=s=\#{s.inspect}\#{s}\"%\>";"<%=s=#{s.inspect}#{s}"%>

The only reason it doesn't is that ERB barfs on '%>' in a string inside
a <%= %> block, while String#inspect ignores it.  This requires...
trickery.

Luckily, we have trickery on hand.  When in doubt, reverse the data:

<%=s=">%\"}esrever.s{#}tcepsni.s{#=s=%<\";";"<%=s=#{s.inspect}#{s.reverse}"%>

That's 77 characters by my count.  77 characters of pure, twisted, evil
:-)
851acbab08553d1f7aa3eecad17f6aa9?d=identicon&s=25 Ken Bloom (Guest)
on 2007-04-08 19:10
(Received via mailing list)
On Sun, 08 Apr 2007 16:30:11 +0900, Alex Young wrote:

>>>>
>> If you really want to be evil and twisted, what's the smallest self-
> => ""
Come to think of it, ERB is way too easy a language. You have to define
non-trivial to mean "includes a <% and a %>"
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2007-04-09 14:56
(Received via mailing list)
Ken Bloom <kbloom@gmail.com> writes:

>>>>>
>>>> ERB.new( "blah <%= @blah %>" ).result    #=>  "blah <%= @not_blah %>"
>> => " "
>> irb(main):013:0> ERB.new('').result
>> => ""
>
> Come to think of it, ERB is way too easy a language. You have to define
> non-trivial to mean "includes a <% and a %>"

irb(main):001:0> ERB.new('>%%<').result
=> ">%%<"
Af67824baa024e77966c5521589d95e9?d=identicon&s=25 Harrison Reiser (Guest)
on 2007-04-10 20:05
(Received via mailing list)
On 4/9/07, Christian Neukirchen <chneukirchen@gmail.com> wrote:
>
Hey, that doesn't count! It doesn't contain '<%' or '%>'.  How about
this:

  <%=File.new($FILENAME).readlines%>
This topic is locked and can not be replied to.