> I'm not sure that I agree. My concern with Oliver's patch (which has 
> been suggested at least once before) is that it over complicates the 
> model. I'm a little leary of creating a complex inheritance heirarchy 
> for Radiant. Yes pages and images and redirects have URLs, but beyond 
> that they have very little in common. Sometimes things that 
> look similar 
> are not similar at all. I'm not ruling out what Oliver is suggesting, 
> but I am having difficulty seeing the true value.

Actually the commonality is:

- available through a url
- updates the response

There'd be a couple of advantages of unifying pages/images/redirects into the 
one model - most notably the fact that the
SiteController could remain untouched when you add another of these 'url 
handling' objects (I pretty much had to do a copy/paste
duplicate to serve up images in my asset extension). I definitely think they 
should be viewed differently in the admin interface,
but I could be sold on unifying the model.

The Page object adds really only one extra thing to that mix:

- has many page parts

I'm not sure if those advantages are worth it, but the point that I do see is 
that we currently have the view that Pages must be
made up of parts - I don't think that's necessarily true... but until the work 
in facets for changing the way that you can interact
with a page through the editing interface is worked out properly, I don't think 
it's easy to see the need. Perhaps if there was a
SimplePage above page that didn't have page parts, that'd by all the seperation 
I would need.


Maybe that 'separate url lookup' table that has been rattling round a little 
could come into play here. Pages and Assets and
Redirects are all 'mappable' things - they can handle a url.


class UrlMapping
  belongs_to :handler, :polymorphic => true
end

module UrlHandler
  def self.included(base)
    base.class_eval {
      has_one :url_mapping
      before_save :update_mapping      
    }
  end

  def update_mapping
    url_mapping = UrlMapping.new(:path => url)
  end
end

class Page
  include UrlHandler
  def handle(request, response)
    #do whatever
  end
end

class Attachment
  include UrlHandler
  def update_mapping
    #url can have a transform part (the %) (ie /page/thumbnail/slug)
    url_mapping = UrlMapping.new(:path => "#{page.url}%#{slug}"
  end
  def handles_url?(url)
    /#{Regexp.escape(page.url)}([^\/]\/)?#{Regexp.escape(slug)}"
  end
  def handle(request, response)
    #do whatever
  end
end

(Not sure if that should be has_one or has_many, I'll go with has_one for now)

If the sitecontroller looked up pages using a reverse like lookup (not sure 
about the database compatability of that):

  mappings = UrlMapping.find(:all, :conditions => ['? like path',url])
  if(mapping = mappings.find {|m| m.handler.handles_url?(url)}) 
    handler = mapping.handler
    handler.handle(request, response)
  end

Pages that would need to handle multiple url paths that are unknown at publish 
time could override the update_mapping method to set
a mapping like "/search/%" and would be able to handle "/search/monkeys/blah" 
or "/search/things/bump/night". 


Dan.
_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to