I''ll probably do my respond_to API rewrite, as discussed here: http://rubyforge.org/pipermail/merb-devel/2007-September/000275.html sometime this week, unless someone has come up with a better API. I''ll also work in http://merb.devjavu.com/ticket/227 at the same time. Any serious objections?
I must be emotionally attached to the current API, because the proposal isn''t clicking for me. On one hand it makes sense, but on the other hand it feels disconnected and doesn''t have an obvious flow. "respond_to" may seem to be a magic box in terms of deciding what format to use, but the flow is clear to me. The "provides" declaration gives a very clear definition of what formats to use but appears to have too much magic in *how* the format choice is actually made. Just voicing a concern from a different perspective. Feel free to ignore me - still a newbie some days. :) On 10/16/07, Michael D. Ivey <ivey at gweezlebur.com> wrote:> I''ll probably do my respond_to API rewrite, as discussed here: > > http://rubyforge.org/pipermail/merb-devel/2007-September/000275.html > > sometime this week, unless someone has come up with a better API. > > I''ll also work in http://merb.devjavu.com/ticket/227 at the same time. > > Any serious objections? > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel >-- Cheers, Kevin Williams http://kevwil.com/ http://www.almostserio.us/ http://kevwil.jaiku.com/
Originally sent this a couple of days ago, but only sent it to Kevin Williams. Original Message: = I still don''t like the case statement there... It won''t be able to help being magical in it''s attempt to not be so magical (though, I also fail to see what''s magical about a method that takes blocks). I don''t like that you have to state twice what sort of format you want to deal with if you want to do something other than render a template. def index provides :foo case request.format when :foo : Object.to_foo end end seems clumsy beside: def index respond_to do |format| format.foo {Object.to_foo} end end in the case of a rendered template, you do end up with a win though: class MyController provides :html def index provides :json, :yaml end end vs. class MyController def index respond_to do |format| format.html format.json format.yaml end end end but just as soon as the controller slips past the simple case (which I posit it will more often than not, otherwise you''d be using a non- content-type-sensitive action), you lose that benefit. In my mind that API is more of a 20/80 solution for people that actually develop RESTful applications on Merb. I''ll illustrate using an actual RESTful controller (from a 0.3.7 app) that is in production. Written using the current style: http://pastie.caboo.se/107837 Now written using the proposed style: http://pastie.caboo.se/107838 I just don''t see a net benefit in clarity, beauty or brevity. Sorry to be a curmudgeon. -- Stephen (voxdolo) = On Oct 16, 2007, at 1:03 PM, Kevin Williams wrote:> I must be emotionally attached to the current API, because the > proposal isn''t clicking for me. On one hand it makes sense, but on the > other hand it feels disconnected and doesn''t have an obvious flow. > > "respond_to" may seem to be a magic box in terms of deciding what > format to use, but the flow is clear to me. > > The "provides" declaration gives a very clear definition of what > formats to use but appears to have too much magic in *how* the format > choice is actually made. > > Just voicing a concern from a different perspective. Feel free to > ignore me - still a newbie some days. :) > > On 10/16/07, Michael D. Ivey <ivey at gweezlebur.com> wrote: >> I''ll probably do my respond_to API rewrite, as discussed here: >> >> http://rubyforge.org/pipermail/merb-devel/2007-September/ >> 000275.html >> >> sometime this week, unless someone has come up with a better API. >> >> I''ll also work in http://merb.devjavu.com/ticket/227 at the same >> time. >> >> Any serious objections? >> _______________________________________________ >> Merb-devel mailing list >> Merb-devel at rubyforge.org >> http://rubyforge.org/mailman/listinfo/merb-devel >> > > > -- > Cheers, > > Kevin Williams > http://kevwil.com/ > http://www.almostserio.us/ > http://kevwil.jaiku.com/ > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel
On Thu, Oct 18, 2007 at 02:11:24PM -0400, Stephen Caudill wrote:> in the case of a rendered template, you do end up with a win though: > > class MyController > provides :html > def index > provides :json, :yaml > end > end > > vs. > > class MyController > def index > respond_to do |format| > format.html > format.json > format.yaml > end > end > endBut in that simple case, couldn''t you just match the format to the template extension automatically? That is, format.foo { ... } tells you how to render a foo request, but if not specified, it defaults to render action.rfoo The ''provides'' would be implied by the existence of the template with the right extension. B.
http://merb.devjavu.com/changeset/795 crossing_fingers.do ::Manually.refactor_controllers views.each {|v| mv "#{v.name}.#{v.extension}" "#{v.name}.#{v.format}.#{v.extension}"} end I got one controller refactored, and the html format didn''t break yet, so we''ll see how the :xml and :json formats go. On 10/18/07, Brian Candler <B.Candler at pobox.com> wrote:> On Thu, Oct 18, 2007 at 02:11:24PM -0400, Stephen Caudill wrote: > > in the case of a rendered template, you do end up with a win though: > > > > class MyController > > provides :html > > def index > > provides :json, :yaml > > end > > end > > > > vs. > > > > class MyController > > def index > > respond_to do |format| > > format.html > > format.json > > format.yaml > > end > > end > > end > > But in that simple case, couldn''t you just match the format to the template > extension automatically? > > That is, > > format.foo { ... } > > tells you how to render a foo request, but if not specified, it defaults to > render action.rfoo > > The ''provides'' would be implied by the existence of the template with the > right extension. > > B. > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel >-- Cheers, Kevin Williams http://kevwil.com/ http://www.almostserio.us/ http://kevwil.jaiku.com/
On Nov 2, 2007, at 7:19 AM, Kevin Williams wrote:> http://merb.devjavu.com/changeset/795 > > crossing_fingers.do > ::Manually.refactor_controllers > views.each {|v| mv "#{v.name}.#{v.extension}" > "#{v.name}.#{v.format}.#{v.extension}"} > end > > I got one controller refactored, and the html format didn''t break yet, > so we''ll see how the :xml and :json formats go.For the record, I didn''t *have* to drop the legacy template names, but Ez wanted me to get it in the same changeset so everything broke at once. HTML-only apps will probably not notice, other than the template rename. respond_to based apps will be a little harder, but really shouldn''t be too tough. If anyone runs into trouble converting, hit me up on IRC, or on the Mailing List, or the Google Group, or in Charlotte Saturday...I''ll be more than happy to help.
Everything seems smooth so far, but I''ve only got one (restful) controller so far. I do have about a dozen view files which needed renaming, but that wasn''t too bad. I''m not complaining - this is life on the edge, things will break. I''m looking forward to the next release. On 11/2/07, Michael D. Ivey <ivey at gweezlebur.com> wrote:> On Nov 2, 2007, at 7:19 AM, Kevin Williams wrote: > > http://merb.devjavu.com/changeset/795 > > > > crossing_fingers.do > > ::Manually.refactor_controllers > > views.each {|v| mv "#{v.name}.#{v.extension}" > > "#{v.name}.#{v.format}.#{v.extension}"} > > end > > > > I got one controller refactored, and the html format didn''t break yet, > > so we''ll see how the :xml and :json formats go. > > For the record, I didn''t *have* to drop the legacy template names, > but Ez wanted me to get it in the same changeset so everything broke > at once. > > HTML-only apps will probably not notice, other than the template rename. > > respond_to based apps will be a little harder, but really shouldn''t > be too tough. > > If anyone runs into trouble converting, hit me up on IRC, or on the > Mailing List, or the Google Group, or in Charlotte Saturday...I''ll be > more than happy to help. > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel >-- Cheers, Kevin Williams http://kevwil.com/ http://www.almostserio.us/ http://kevwil.jaiku.com/