Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

rework #14

Merged
merged 6 commits into from
Jan 30, 2014
Merged

rework #14

merged 6 commits into from
Jan 30, 2014

Conversation

queckezz
Copy link
Contributor

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
Copy link
Contributor

nice! ill leave some comments inline

// Grab our Jade templates.
if (!pkg.config.templates) return callback();
var files = pkg.config.templates.filter(filterJade);
function templates (plain) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this an options object instead, for future compatibility in case we want to add more. and then change the name from plain to string, so it would be like this. and then also add the "templates" key as the first argument to match the native concat and copy plugins

with all that it would end up looking like this:

builder.use(jade('templates', { string: true }));

@ianstormtaylor
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

, jade = require('component-jade');

var Builder = require('component-builder');
var write = require('fs').readFileSync;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo

@ianstormtaylor
Copy link
Contributor

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

ianstormtaylor added a commit that referenced this pull request Jan 30, 2014
@ianstormtaylor ianstormtaylor merged commit e22c87c into segment-boneyard:master Jan 30, 2014
@eivindfjeldstad
Copy link

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
Copy link
Contributor Author

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
Copy link

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
Copy link

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

@eivindfjeldstad
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants