jstransformers / jstransformer

Normalize the API of any JSTransformer.
http://npm.im/jstransformer
MIT License
152 stars 12 forks source link

Implement missing transformers #1

Closed ForbesLindesay closed 9 years ago

ForbesLindesay commented 9 years ago

This project aims to replace transformers with a large collection of separate libraries, each of which able to be separately maintained, tested and updated. Each library will implement some subset of the API in this module, and may optionally return a string body rather than the {body: String, dependencies: Array.<String>} format (lots of file formats don't actually have dependencies so it wouldn't really make sense). This module can then be used to fully normalise that interface, including implementing the methods that are otherwise not implemented.

Here is a list of all the modules that need implementing

Once all of these have been implemented, we can switch jade to look for these rather than transformers. I'll need as many collaborators as possible for this, so if you're willing to contribute a transformer, let me know and I'll add you to the organisation. P.S. note that we add jstransformer to the keywords in package.json for all transformers, so they can be found at https://www.npmjs.com/browse/keyword/jstransformer

ForbesLindesay commented 9 years ago

@bloodyowl @enlore @hemanth @jbnicolai @jeromew @rlidwka @TimothyGu would any of you like to help out?

hemanth commented 9 years ago

Count me in :)

ForbesLindesay commented 9 years ago

Awesome, welcome aboard :)

Please make sure you add forbeslindesay as an owner if you publish any new jstransformers to npm. I'll write a bot at some point to add all of the owners on GitHub as owners on npm :)

jbnicolai commented 9 years ago

I'm game as well ^^

I'll write a bot at some point to add all of the owners on GitHub as owners on npm

Good call.

hemanth commented 9 years ago

@ForbesLindesay Here we go! Started with jstransformer-handlebars (Made it look as close as your code.)

ForbesLindesay commented 9 years ago

Looks good. Just had a thought though:

For templating engines we should support two step compilation (i.e. compile then render). I would suggest we support:

exports.compile = function (str, options) {
  reutrn function (locals) { /* return resulting string */ };
};
// or
exports.compile = function (str, options) {
  reutrn {fn: function (locals) { /* return resulting string */ }, dependencies: [/* array of files */]};
};

We could the have template.render behave like the following by default:

exports.render = function (str, options, locals) {
  var compiled = exports.compile(str, options);
  if (typeof compiled === 'function') return compiled(locals || options);
  else return {body: compiled.fn(locals || options), dependencies: compiled.dependencies};
};

I'll do underscore and then update this library to show what I mean.

hemanth commented 9 years ago

Yup, compile and render makes sense and they are convenient as well.

TimothyGu commented 9 years ago

@ForbesLindesay sure I can use some fun porting modules over.

bloodyowl commented 9 years ago

I'll try to find the time to do some of them

TimothyGu commented 9 years ago

@ForbesLindesay how about caching? Do we let the libraries handle caching or do we use a DIY one like in transformers?

TimothyGu commented 9 years ago

Jade transformer written. Function signatures look like this:

compile(source, options);
compileClient(source, options);
render(source, options, locals);

If this is OK I'll go ahead and write the transformer for EJS too.

ForbesLindesay commented 9 years ago

Looking at what's actually in that repo. It looks perfect. i.e.

compileFile(source, options);
compileFileClient(source, options);
ForbesLindesay commented 9 years ago

For caching: wherever possible we disable all caching. The dependencies array is there so that it is easy for an application to tell when a file needs to be rebuilt. If the user wants caching, they should use the Transformer.compile interfaces instead of the Transformer.render interfaces and then they can cache the result of that.

The only part that I'm not 100% sure on is whether we should do anything for dynamic caches like browserify supports where you avoid re-parsing all the files that haven't changed. Currently my intention is not to do anything special for those unless someone asks for it.

TimothyGu commented 9 years ago

@ForbesLindesay sounds good.

JosefJezek commented 9 years ago

Please :sparkles: markdown-it :sparkles: - modern pluggable markdown parser

See https://www.npmjs.com/browse/keyword/markdown-it

TimothyGu commented 9 years ago

@JosefJezek TODO added.

Uglify-JS and JSON beautifier/uglifier ported.

TimothyGu commented 9 years ago

verbatim and cdata* are ported.

hemanth commented 9 years ago

@ForbesLindesay I have implemented few of them, but haven't published it yet, as you had mentioned earlier that add all of the owners on GitHub as owners on npm, should I go ahead a publish them or wait?

TimothyGu commented 9 years ago

@hemanth I already published the ones ported by me. We can change the owners after we publish anyway.

TimothyGu commented 9 years ago

@hemanth regarding @ForbesLindesay's suggestion of writing a bot that fetches GitHub owners and automatically add them to npm, it's technically not possible as npm login and GitHub login might be different (e.g. ForbesLindesay (GitHub) vs forbeslindesay (npm)). What we can do is add all of the owners to one repo (i.e. this one) and do something like this:

owners="`npm owner ls jstransformer | cut -d' ' -f1`"

for p in `curl -s 'https://api.github.com/orgs/jstransformers/repos' | sed -n 's/.*"name".*:.*"\(.*\)",/\1/pg'`; do
    for u in $owners; do
        npm owner add "$u" "$p"
    done
done

(Bash FTW)

hemanth commented 9 years ago

@TimothyGu Nice, we must also update the package.json with authors or have a common author say like jstransformer.

TimothyGu commented 9 years ago

@hemanth I would argue against that, as 1. package.json cannot have more than one authors, only maintainers, and 2. not everybody will necessarily be maintaining every module, and adding the person to maintainers would just be dubious.

ForbesLindesay commented 9 years ago

@TimothyGu I was thinking that we would maintain a file somewhere that listed all project owner's npm accounts.

@hemanth go ahead and publish them, but if possible please add me as an owner on npm via:

npm owner add forbeslindesay
hemanth commented 9 years ago

@ForbesLindesay Done.

TimothyGu commented 9 years ago

@ForbesLindesay that's fine too, but the question is where.

RobLoach commented 9 years ago

:sparkles: markdown-it :sparkles: https://github.com/RobLoach/jstransformer-markdown-it

I requested a transfer, but don't have access.

TimothyGu commented 9 years ago

@RobLoach done. I've also invited you to our maintainer team, so you can now push to that repo.

TimothyGu commented 9 years ago

@JosefJezek Markdown It support has been added.

JosefJezek commented 9 years ago

Thank you @TimothyGu and @RobLoach :+1:

RobLoach commented 9 years ago

:sparkles: eco :sparkles: https://github.com/RobLoach/jstransformer-eco

RobLoach commented 9 years ago

:sparkles: swig :sparkles: https://github.com/RobLoach/jstransformer-swig

hemanth commented 9 years ago

@RobLoach I was about to publish swig heh heh.

RobLoach commented 9 years ago

:eyes: :tongue:

ForbesLindesay commented 9 years ago

@RobLoach since you're clearly hooked, I've added you to the owners team :)

RobLoach commented 9 years ago

@ForbesLindesay Thanks! :+1:

:sparkles: mustache :sparkles: https://github.com/jstransformers/jstransformer-mustache

RobLoach commented 9 years ago

:sparkles: plates :sparkles: http://github.com/jstransformers/jstransformer-plates

TimothyGu commented 9 years ago

@RobLoach nice work! However, remember to enable Coveralls in addition to Travis CI so that the coverage badge works.

RobLoach commented 9 years ago

:sparkles: ect :sparkles: https://github.com/jstransformers/jstransformer-ect

RobLoach commented 9 years ago

:sparkles: atpl :sparkles: https://github.com/jstransformers/jstransformer-atpl

Also linked the template engines in Forbes original post so that they're easier to find.

RobLoach commented 9 years ago

:sparkles: dot :sparkles: https://github.com/jstransformers/jstransformer-dot

tunnckoCore commented 9 years ago

count me in, i follow this org since you create it, lol have some transformers in mind and can help with toffee, templayed, mote and coffeecup (there have newer impl coffee-templates and mini-coffeecup, i think we can replace legacy 4years coffeecup with them) beside that.. I'll rewrite them asap

TimothyGu commented 9 years ago

@tunnckoCore do you have anything implemented already? If so I can take over those modules right now.

tunnckoCore commented 9 years ago

atm nope, tonight (after few hours). just see the issues and lots of new transformers in org and decide to comment immediately :)

RobLoach commented 9 years ago

HyperScript wouldn't make sense as a jstransformer, would it?

TimothyGu commented 9 years ago

@RobLoach It's just JavaScript. If you really think it would be helpful to do something like:

html
  body
    :hyperscript
      h('p', "why don't you just use Jade?")

, sure. (For me at least it's a waste of time.)

RobLoach commented 9 years ago

https://github.com/reworkcss/rework

tunnckoCore commented 9 years ago

@RobLoach exactly that I have in mind + postcss. on the road

ForbesLindesay commented 9 years ago

@tunnckoCore welcome to the team. I've added you as an owner and look forward to seeing what you produce :)

I've added rework and postcss to the list :)

tunnckoCore commented 9 years ago

@ForbesLindesay thanks! :)

I've added rework and postcss to the list :)

I think we should name it just jstransformer-css? Im on them now and .. this is the Q.

tunnckoCore commented 9 years ago

:sparkles: rework :sparkles: transform CSS to JSON AST using reworkcss/css