Closed nesquena closed 13 years ago
Another way is to use the existing system:
source = File.read('templates/really_cool_template.rabl')
rabl_engine = Rabl::Engine.new(source, :format => 'json')
output = rabl_engine.render(self, {})
puts output
That would work today.
Awesome, thanks
I think we need a mini-controller-type place to wire up views with models anyway because I don't want this to be part of the model.
I'm looking into this today.
Thanks!
On Aug 6, 2011, at 4:46 AM, nesquena wrote:
Another way is to use the existing system:
source = File.read('templates/really_cool_template.haml') rabl_engine = Rabl::Engine.new(source, :format => 'json') output = rabl_engine.render(self, {}) puts output
That would work today.
Reply to this email directly or view it on GitHub: https://github.com/nesquena/rabl/issues/86#issuecomment-1740489
Yeah I agree, good idea to separate out these views from the model as much as possible IMO, its just clutter not business logic. Interested to see what you guys come up with. I will probably create that helper for rendering as defined above:
Rabl::Engine.render("path/to/file", :object => @test, :format => 'json')
Unless you have a better syntax suggestion.
Hmm, actually so far I think what rabl has is good enough, except that I'd maybe want to use caching of path lookups and template files, like actionview does that (and tilt, too, i guess?)
This is what I have now, and it works fine for now:
https://gist.github.com/bd5415e6e12b1425d271
Cheers!
On Aug 7, 2011, at 12:40 AM, nesquena wrote:
Yeah I agree, good idea to separate out these views from the model as much as possible IMO, its just clutter not business logic. Interested to see what you guys come up with. I will probably create that helper for rendering as defined above:
Rabl::Engine.render("path/to/file", :object => @test, :format => 'json')
Unless you have a better syntax suggestion.
Reply to this email directly or view it on GitHub: https://github.com/nesquena/rabl/issues/86#issuecomment-1746666
Oh, excellent. That's a good approach. In that case, perhaps this is closed without me actually committing a line of code. Do let me know if you need any other rabl-related support / fixes though through this process.
Talking with @svenfuchs and reminded me that it might be helpful to render RABL outside of a controller context (for messaging queues, etc). One simple possibility is to support partial at the class level. We already support:
Perhaps the simplest thing to do is to extend this as a class level method:
or something similar. Thoughts?