bleedingwolf / Ratpack

A micro web framework for Groovy
Other
210 stars 4 forks source link

Allow render to accept URL and InputStream #2

Open aalmiray opened 14 years ago

aalmiray commented 14 years ago

Ratpack looks like a great option to embed a minimal web app in other apps. If so then resources are likely to be available in the classpath and not in the file system. render() assumes that the 1st argument to be the name of a file that exists in the file system. Adding support for URL and InputStream would allow embedding apps to feed the data to the template directly.

render(myapp.class.getResourceAsStream("/page.html", params)

The exact example I have in mind is embedding Ratpack in Griffon via a plugin ;-)

PD: It would also be great to consider a render() variant that accepts the full text too, even a closure that's supposed to be parsed by MarkupBuilder

render(params) { html { title('Ratpack') body { // you get the idea } } }

Kudos for a cool project!

justinvoss commented 14 years ago

How do you feel about a method that accepts the template text as the first parameter? That would allow you to use any mechanism you like to load the template. Your code might look like this (this method doesn't exist, it's just a suggestion):

renderTemplateText(myapp.class.getResourceAsStream("/page.html").text, params)
aalmiray commented 14 years ago

Excellent! That would work wonders. However I also noticed that Ratpack apps can serve static resources. They too assume file based resources are available instead of classpath resources.

Perhaps the code could be refactored in a way that a custom resource handler could be injected, while the default one uses file based resources.

What do you think?