[LRUG] Concat and Strings
James McCarthy
james2mccarthy at gmail.com
Tue May 13 12:19:28 PDT 2008
I just cut and pasted your example and got the latter in 2.0.2
James McCarthy
http://thewerks.org.uk
On 13 May 2008, at 09:23, Andrew Stewart wrote:
> Hi El Rug,
>
> I can't quite explain the behaviour I'm seeing below. I'd value any
> explanation.
>
> So...I have a wrap method in a Rails view helper (fragmented for
> debugging):
>
> def wrap(with, &block)
> inner = capture &block
> s = "#{with} { #{inner} }"
> concat s, block.binding
> end
>
> In the same helper, I have another method which calls the first like
> this:
>
> def ie6(&block)
> wrap '* html', &block
> end
>
> In my view, a stylesheet template, I do this:
>
> <% ie6 do %>
> body {
> padding: 4px;
> }
> <% end %>
>
> The rendered template shows what I want, which is:
>
> * html body {
> padding: 4px;
> }
>
> But I can't explain why it doesn't show this instead:
>
> * html {
> body {
> padding: 4px;
> }
> }
>
> After all, that is what I get if I insert a "puts s" line in my wrap
> method.
>
> So something about concat is interpreting the { and } in s...but what?
>
> If I remove the { and }, I get this:
>
> * html
> body {
> padding: 4px;
> }
>
> which makes sense, but isn't what I want. I want the html and body
> on the same line.
>
> The concat method looks like this:
>
> # http://github.com/rails/rails/tree/master/actionpack/lib/action_view/helpers/text_helper.rb#L28
> def concat(string, binding)
> eval(ActionView::Base.erb_variable, binding) << string
> end
>
> As far as I can tell, the string is passed through untouched.
>
> Any ideas?
>
> Regards,
> Andy Stewart
>
> -------
> AirBlade Software
> http://airbladesoftware.com
>
>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
More information about the Chat
mailing list