Creating a new template handler via plugin

I am trying to add a template type to render FlexImage::Model objects.
I seem to be missing some understanding on how rails handles some of the
details around this.

The template is pure ruby code, it just has some special handling around
the template to further process the returned value of the template.

The biggest issue is that I can’t figure out how to get the view aware
of the helpers and instance variables from the controller. Currently, I
am simply doing something like this:

result = action_view.controller.instance_eval(@flexi_template)

This allows me access to the instance variable from the controllers, but
not the helpers.

So what is proper way to implement a template handler so that it gets
all the treatments that a view should. Meaning it gets the helpers and
instance variables that one would expect from the rhtml views.

I have studied some other plugins like markaby and the rails code itself
and can’t seem to get my head around this. Also the rails docs
regarding this are quite brief.

The full code for my Template handler is here:
http://pastie.caboo.se/29106

Any insight would be appreciated.

Alex W. wrote:

Any insight would be appreciated.

While I am at it, if anyone has any idea why

ActionController::Base.exempt_from_layout :foo

doesn’t work, it would help to get rid of the render statement from the
controller:

def image
@image = MyImage.find(1)
render :layout => false # required cause exempt_from_layout is
broken
end

Alex W. wrote:

Alex W. wrote:

Any insight would be appreciated.

While I am at it, if anyone has any idea why

ActionController::Base.exempt_from_layout :foo

doesn’t work, it would help to get rid of the render statement from the
controller:

def image
@image = MyImage.find(1)
render :layout => false # required cause exempt_from_layout is
broken
end

Don’t you love when you struggle with something for a long time, then
you get frustrated and voice a question about it to others. Then, as if
by magic, the universe answers your public outcry for assistance and
grants the knowledge you were looking for.

I stumbled upon the MarkDownOnRails plugin
http://rubygreenblue.com/blog/article/markdown_template_handler_for_rails,
which has exactly the simple and easy to understand template handling
that I needed to figure this out. Turns out that rails passes you a
view object which mostly has what you need.

Here is the template handler, rewritten, and seems to work properly, for
all that are curious:

Parked at Loopia