lestrrat-p5 / Catalyst-View-Xslate

Text::Xslate View Class
Other
10 stars 8 forks source link

Added expose_methods option similar to TT view, and allow inline template to render #3

Closed jjn1056 closed 13 years ago

jjn1056 commented 13 years ago

Hi,

Here's a first attempt to support a configuration options called 'expose_methods' which is similar to the TT view, and something that I found useful with the TT view (and missed for my Xslate experiments). I also added support to pass a scalar ref to ->render to allow inlined templates. This can be useful for testing and quick mockups and is also something you can do with the TT view.

http://search.cpan.org/~abraxxa/Catalyst-View-TT-0.36/lib/Catalyst/View/TT.pm#expose_methods http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template.pm#process%28$template,_\%vars,_$output,_%options%29

I also added a tiny test case to help explain.

This could could use some cleanup, etc but I wanted to get your thoughts before I put more work into it. Let me know if you are happy with the general approach or if you'd prefer something else.

John

lestrrat commented 13 years ago

WRT to inline templates, that's a no brainer. works for me.

WRT to expose_methods, I personally wouldn't use it, but I can see why people would want it.

The only thing came to my mind is, wouldn't people also want to expose their methods, but name it differently? i.e., you have a method "foo" that you want to expose, but want to call it by some other name from the view?

Sort of like

expose_methods => {
    real_method_name => "alias_in_template"
}

Note that this is not essential, I'm just pondering what people might ask in the future.

jjn1056 commented 13 years ago

Okay,

That seems reasonable, although now I'll probably need to commit similar over at the TT View repo :)

This is the functionality, if you agree I'll fill out the docs a bit and clean up the code.

Johnn

jjn1056 commented 13 years ago

Dear lestrrat,

Did you happen to get a change to glance through my latest changes? Any thoughts?

Johnn

lestrrat commented 13 years ago

sorry, completely went past me. I'll review as soon as I'm done with $day_job morning routines in a hour or so.

lestrrat commented 13 years ago

huh, did I just close this pull request? anyway, merged and pushed. Will do a cpan release now.