segment-boneyard / component-jade

A plugin to transpile Jade files for the component builder.
12 stars 8 forks source link

Ability to compile directly to html #9

Closed wejendorp closed 11 years ago

wejendorp commented 11 years ago

Allows component-jade to transparently use jade files as component html -> js templates.

Breaking changes: The middleware is now wrapped in a configuration function.

builder.use(jade({toHtml: true}));

The jade includes are no longer functions.

var templateHtml = require('./template');

Dependencies: Updates jade version for fix of jade.render.

ianstormtaylor commented 11 years ago

hey cool idea. ideally the plugin could either be invoked options, or just passed in like normal. for an example of how i've done this in the past, see https://github.com/segmentio/model-defaults/blob/master/index.js – you can then do just .use(jade) or .use(jade({ html: true }))

should probably bump the version to 0.4.0. but luckily that should mean no breaking changes - im assuming the functions backwards compat is only if you turn on the html option yeah?

can you call the option just html

and can you pull all the string escaping logic into one helper named escapeHtml or whatever best describes it

wejendorp commented 11 years ago

Nice way to wrap it, I will use that. Sounds good, on it. And yea, it is fully backwards compatible if you dont use the flag.

wejendorp commented 11 years ago

But they are both objects here, can't really use typeof to distinguish between an options object and a builder instance. You know another way? How about making it a configuration step instead: jade.set({html: true}) before passing it to builder?

ianstormtaylor commented 11 years ago

might be able to check if the builder instanceof Builder dunno how circular deps work in node — or jankier, check for a known property on the builder.

wejendorp commented 11 years ago

I just check for the Builder.build method, that shouldn't be going anywhere. Now it's backwards compatible. Sorry for the commit spam.

hallas commented 11 years ago

:+1:

ianstormtaylor commented 11 years ago

thanks for this, just cleaned up a bit, let me know if you run into anything else

wejendorp commented 11 years ago

Nice cleanup.

wejendorp commented 11 years ago

However, escapeHtml function is broken now, remove the first quote line and move it to the end: string = '\'' + string + '\'';

ianstormtaylor commented 11 years ago

ah shoot yup, check again