nrstott / bogart

Fast, Sinatra-Inspired JavaScript Framework running on JSGI with Node.JS!
165 stars 29 forks source link

Supporting jade includes #45

Open tstone opened 12 years ago

tstone commented 12 years ago

The jade template engine requires the variable filename to be set to the absolute path of the template file in order for includes to work right.

It's possible to achieve this within a route handler...

router.get('/', function() {
     return viewEngine.respond('index.jade', { filename: path.join(__dirname,'/views/index.jade')  });
 });

...but that's kind of a pain. This could be solved a number of ways, but one way it can't is in the jade adapter. As implemented, bogart doesn't pass this information back to the template engine so when jade is added as a template engine it's rendering function can't automatically handle this.

As a solution to this, the viewEngine could pass the viewPath (along with the view and whatever else) back to the template engine for those engines that need it. I forked bogart and implemented this on my fork as a 5th parameter on the engine callback.

Where it was function(template, opts, cache, viewEngine)

It is now function(template, opts, cache, viewEngine, meta)

Does this sound like a solution that makes sense or is there a better approach?

https://github.com/tstone/bogart/commit/0df477cd822bc02ccaacf240657ca1d265df383f https://github.com/tstone/bogart-jade/commit/5f9d943450d06f43e61ed7974d56feb131652e28

nrstott commented 12 years ago

I'm considering moving the view engine out to its own package as it has little to do with Bogart core. The view engine that is currently in Bogart was intended to provide some level of abstraction to help make it easier to write view engines. I've heard that Jade has moved to a more Django style 'layout' support which would make it not work as well.

I do have a bogart-jade package that works with a now outdated version of Jade.

I think the best solution at the moment will be to move the view engine to its own module, have it provide basically the API it does now which can work with and add layout support to HAML, Mustache, and many other view engines. I will come up with a different recommended solution all together for those who want to use the modern Jade and that solution will be just easy helper functions to render JSGI responses from Jade Templates, in its own package as well.

tstone commented 12 years ago

What can I do to help or speed that up? Shoot me a github message.

nrstott commented 12 years ago

Github wont let me send you a message. That is greyed out and it says that you haven't provided an email address. My email / gchat is nrstott@gmail.com.