ISSUE: MULTIPLE FORMATS
Not sure how academic this is but i certainly had an app which wanted
xml for api and html for browser for the same controller action and I
would have wanted to use erector to define them.
I assume that xml and html formats are separate widget subclasses with
rails integration included.
for clarity let's say
class XMLViewWidget < XMLWidget
include Rails # lets assume this would suck in rails integration
end
class HTMLViewWidget < HTMLWidget
include Rails
end
now what will a view template file look like?
then
# app/views/posts/index.xml.rb:
class Views::Posts::Index < Erector::XMLViewWidget
end
# app/views/posts/index.html.rb:
class Views::Posts::Index < Erector::HTMLViewWidget
end
OOPS, that is the same class name, you see the problem? this means
erector widgets cannot be used
in view to define different formats.
This can be fixed if the erector rails template-renderer enforces a
bit of alternative naming of classes
for instance, for xml app/views/posts/index.xml.rb we could expect
Views::Posts::Xml::Index.
But I think this line
https://github.com/pivotal/erector/blob/master/lib/erector/rails/template_handler.rb#L5
will raise: expected 'app/views/posts/index.xml.rb' to define
Views::Posts::Index.
Does anyone know how exactly this works?
mind you there surely are workarounds:
* one can use alternative class and file names but then the controller
would need to explicit specify the template to render for a format and
most of the rails convenience would be lost.
* one could always use distinct view paths for html and xml, but that
would also mess the rails conventions
my point is how to design erector integration that seamlessly solves
this problem