> going to cause the removal of a useful (if undocumented) feature -- theWhenever these discussions come up I kind of get lost in details, but yes,
> ability to call "helpers.foo" and have it grab the 'concat'ed output from
> whatever wacky Rails helper 'foo' is.
of course we should be able to call arbitrary rails helpers with a minimum
of fuss.
The plan as I see it is:
1) Make erector's notion of html safety compatible with Rails's. HTML
produced by erector via to_s or capture should be treated as safe by
Rails, HTML produced by Rails helpers should be treated as safe by
erector.
2) Monkey patch Rails such that it uses erector's output buffer, and
captures via erector's capture method. (This is the approach haml
takes. Erector's current approach is the opposite -- erector uses
Rails's output buffer and delegates capture to Rails. This fails in
the case where you have a Rails helper that tries to capture a erector
block.)
3) Delegate the majority of helpers directly via method_missing.
Hopefully #1 and #2 allow this to "just work". Because of #1, we no
longer need to worry about escaping. Because of #2, output always goes
to erector.
4) Write wrappers for only the subset of helpers that return a string
that you would usually want immediately outputted. For example,
link_to, but not translate. The wrapper is very simple: it just
delegates to rails and then outputs the result.
Thomas has been working on this on his fork:
http://github.com/wless1/erector/tree/experimental
> --
>
> You received this message because you are subscribed to the Google Groups
> "erector" group.
> To post to this group, send email to ere...@googlegroups.com.
> To unsubscribe from this group, send email to
> erector+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/erector?hl=en.
>
Looking at the haml code (and being dissatisfied with the complexity - and
presumed fragility in light of new rails versions) is part of what
motivated Brian and I to switch to the current erector approach of using
the rails buffer. (Before that, erector had the worst of both worlds -
its own buffer and the rails buffer, and a fairly flaky set of mechanisms
which tried to move output from one to the other).
My impression reading the haml code was that they went to all that trouble
so that they could run the non-haml output through their prettyprinter.
I'm not sure about the rails capture mechanism (and whether it has changed
since I last looked), but why wouldn't it hijack the rails output buffer?
Isn't that what capture generally does?
> 4) Write wrappers for only the subset of helpers that return a string
> that you would usually want immediately outputted. For example,
> link_to, but not translate. The wrapper is very simple: it just
> delegates to rails and then outputs the result.
Why not just make people write "text link_to"? ERB makes people do the
equivalent.
I'll look at the fork soon. Have you guys checked out the 'output'
branch yet?
Sent from my iPhone
On Dec 16, 2009, at 9:16 PM, John Firebaugh <john.fi...@gmail.com>
wrote:
I thought the same at first, and this is how my fork currently works
and how I'm currently using helpers. But I find it unsatisfactory. In
ERB, where you already need the <% %> tags, the extra = isn't a big
deal. But in the erector context, where the default is for helper
methods to emit rather than return, the extra 'text' call is
cognitively dissonant and error prone. Because my erector helper
methods don't require it, I tend to forget it when using rails
helpers. The returned result string is silently ignored and I spend a
good chunk of time wondering why portions of my view aren't showing
up.
It's certainly attractive not to have to write any wrappers though.
I'd welcome feedback from anyone else using erector+rails as to this
tradeoff.