wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

#175, #179, #135, #93, #183, #184, #191, fix broken html tests, fix broken --react-import-path #176

Open nippur72 opened 8 years ago

nippur72 commented 8 years ago

This PR improves the parser for rt-scope as discussed in #175.

It's based on a regex, the improvement comes from scanning for as identifier; instead of just ; thus lowering the chances of picking a semicolon in the wrong place.

Of course there are still failing cases, but they are much less.

With this PR the following can be now parsed:

<div rt-scope="'as fast as possible' as message;';' as semicolon;'as' as as">
    {message}{semicolon}{as}
</div>
nippur72 commented 8 years ago

With the latest commits:

nippur72 commented 8 years ago

This PR now implements also #135 with the new (optional) CLI option --create-element-alias.

If an alias is specified, it will be used in place of React.createElement() thus making shorter calls and helping the minifier.

Example of rt foo.rt --create-element-alias h

'use strict';
var h = require('react').createElement;
var _ = require('lodash');
module.exports = function () {
    return h('div', {}, h('span', {}, 'Hello'));
};
nippur72 commented 8 years ago

This PR now fixes also an issue with -react-import-path when the path is different from react.

Regarding the --create-element-alias, now is possible to have a different function name than createElement (e.g. if using a different library than React like preact). Just add it after a comma:

rt foo.rt --react-import-path preact --create-element-alias h,h

will generate:

var h = require('preact').h;
module.exports = function () {
    return h('div', {}, h('span', {}, 'Hello'));
};
nippur72 commented 8 years ago

this PR now implements also #93, #183 and #184 (see for discussion).

nippur72 commented 8 years ago

this PR now fixes also #190

nippur72 commented 8 years ago

...and #191

idok commented 6 years ago

Hi nino, Can you split this PR so we can try and merge at least some of it?

nippur72 commented 6 years ago

sure, I will split it into as small as possible PRs, though it might take a while since I have to do some reconciliation