segment-boneyard / component-jade

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

rework #14

Closed queckezz closed 10 years ago

queckezz commented 10 years ago

I've basically rewrote the module so that it works with @yields changes on the newest builder (0.12.0).

If you would merge this the basic usage will be:

// Build templates.
builder.use(jade());
builder.use(commonjs('templates'));
builder.use(concat('templates'));

component-jade will compile to plain html if you set opts.plain to true

builder.use(jade(true))

Otherwise it would compile to templates like it did before.

Also, jade and the runtime.js are now not included in the module itself, instead they must be added as dependencies.

If you don't like any of those changes you can simply ignore this PR :) I will add tests and update the readme as soon as it gets accepted.

ianstormtaylor commented 10 years ago

nice! ill leave some comments inline

ianstormtaylor commented 10 years ago

awesome, happy to merge with those changes applied. would be sweet to get tests in this PR as well

/cc @swatinem to check it out, it'll remove jade dep

Swatinem commented 10 years ago

Nice! Don’t forget to mention it in the readme though.

And I must shamefully admit, I haven’t tried the new builder yet. Will it still work on the commandline via component build --use component-jade?

queckezz commented 10 years ago

yeah I will update the readme and add tests tomorrow if I get to it :)

The cli isn't compatible with the newest builder just yet. It shouldn't be hard to implement it again though.

queckezz commented 10 years ago

I added tests now, updated the docs and changed the code based on your suggestions. Can you review again? :)

ianstormtaylor commented 10 years ago

looks good to me! thanks for the awesome pull. i'll fix that typo

eivindfjeldstad commented 10 years ago

hmm, the templates won't actually work if you don't eval them first though. https://github.com/segmentio/component-jade/blob/master/examples/template/build.js#L417

maybe add a note in the readme?

queckezz commented 10 years ago

Yeah, I guess the problem right now is in the builder: https://github.com/component/builder.js/blob/master/lib/plugins/commonjs.js#L62

Everything that is not json or a js file will get stringified and exported. That means this

var jade = require(\'jade-runtime\');module.exports = function template(locals) {...

gets turned into this

module.exports = "var jade = require(\'jade-runtime\');module.exports = function template(locals) {..."

even though there is already a module.exports.

eivindfjeldstad commented 10 years ago

yeah. we need an equivalent of the old builder.addFile and builder.removeFile (#157) or maybe some kind of filter in the commonjs plugin

bmcmahen commented 10 years ago

this messed me up too -- couldn't figure out what was going wrong until I saw that the whole thing was stringified.

eivindfjeldstad commented 10 years ago

If #169 gets merged we can use that. In the meantime I'll just use the old builder