From: Devin Mullins Date: 2005-09-12T01:26:38+09:00 Subject: Re: RCR to modify #puts and #print inside ERB Mark Hubbart wrote: >I'm getting the idea that the people on each side of this discussion >disagree because they have different mental models of what ERB does, >and what a ERB document is: > >1. ERB just implements very fancy, flexible, string interpolation. >or >2. ERB documents are executable code (actual programs), where text >prints itself, and code blocks get run. > >#1 is, I gather, much like the JSP way (though I've never done JSP stuff) > > Observant. The JSP way (which is also the Rails way) embraces MVC, and avoids sticking domain logic in the template. The kind of code that sits in a Rails view is "for foo in barlist" and "link_to :action => 'someaction'". (In truth, the design of the JSP spec didn't really have this in mind; rather, it flowed out through a couple years in the "real world" as the most natural usage of JSP.) >#2 is much like PHP. > >If you are in the #1 camp, I suspect you think this RCR would not be >all that much different from one allowing this: >"#{puts 23}" #==> "23\n" > > It really is about inconsistency in behavior. Java falls prey to inconsistent behavior for the sake of making some particular special case "so easy you don't have to think about it." For me, Ruby was sort of a safe haven from that. >Now, I have a proposal: What if _erbout was made into a StringIO, and >we shifted the idea from an ERB template to an ERB program? Then would >it make sense for puts to output to _erbout? > > That's not an altogether horrible idea. Changing mindsets about ERB turns it into one big embedded interpreter (capturing output the same way that Kernel#` does) rather than one big string interpolation. I would then be more likely to want *every* form of standard output to get captured, then -- whether from puts, print, p, $stdout.write, log4r, ... and I don't really want that. :/ I have a proposal, too. What if ERB exposed (and documented) eputs, eprint, and ep methods to the templates? I would be coo wit dat. >(my apologies if any part of this doesn't make sense, it's been a very long day) > > Nope, all very sensical. Devin oops! my opinion's showing. *zip*