Skip to content

Commit

Permalink
add Transition add-on prop templates
Browse files Browse the repository at this point in the history
  • Loading branch information
minwe committed May 12, 2016
1 parent 3788e5d commit bcc5086
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 32 deletions.
71 changes: 65 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ For example, to create a new React class, type `rcc` and press `Tab` or press `C

```js
import React, {
Component,
PropTypes,
} from 'react';

Expand All @@ -59,7 +58,7 @@ export default $class$;
'use strict';

var React = require('react');
var PropTypes = PropTypes;
var PropTypes = React.PropTypes;

var $class$ = React.createClass({
render: function() {
Expand Down Expand Up @@ -230,6 +229,18 @@ componentWillUnmount: function() {

```

### `dn`

```js
displayName: '$END$',
```

### `dnp`

```js
$START$.displayName = '$END$';
```

### `fdn`

```js
Expand Down Expand Up @@ -315,7 +326,7 @@ dangerouslySetInnerHTML={__html: '$END$'}
```js
propTypes: {
$START$: PropTypes.$END$
}
},

```

Expand Down Expand Up @@ -391,7 +402,7 @@ this.state.$END$
```js
contextTypes: {
$START$: PropTypes.$END$
}
},

```

Expand All @@ -400,7 +411,7 @@ contextTypes: {
```js
childContextTypes: {
$START$: PropTypes.$END$
}
},

```

Expand Down Expand Up @@ -432,6 +443,12 @@ getChildContext: function() {

```

### `sdn`

```js
static displayName = '$END$';
```

### `spt`

```js
Expand Down Expand Up @@ -468,7 +485,7 @@ static childContextTypes = {

```

### `csttr`
### `cstt`

```js
constructor(props, context$START$) {
Expand All @@ -477,6 +494,48 @@ constructor(props, context$START$) {

```

### `tsn`

```js
transitionName="$END$"
```

### `tsa`

```js
transitionAppear={$END$}
```

### `tse`

```js
transitionEnter={$END$}
```

### `tsl`

```js
transitionLeave={$END$}
```

### `tset`

```js
transitionEnterTimeout={$END$}
```

### `tslt`

```js
transitionLeaveTimeout={$END$}
```

### `tsat`

```js
transitionAppearTimeout={$END$}
```

### `oncp`

```js
Expand Down
34 changes: 20 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,50 @@ var Handlebars = require('handlebars');
var template = Handlebars.compile(fs.readFileSync('src/ReactJS.hbs', 'utf8'));
var docTpl = Handlebars.compile(fs.readFileSync('src/doc.hbs', 'utf8'));
var readme = fs.readFileSync('README.md', 'utf8');

var templates = yaml.safeLoad(fs.readFileSync('src/template.yaml', 'utf8'));
var eventsTpl = yaml.safeLoad(fs.readFileSync('src/envents.yaml', 'utf8'));

var processTpl = function(tpl) {
tpl = JSON.stringify(tpl);
return tpl.replace(/\\n/g, '
')
var escapeTpl = function(tpl) {
tpl = tpl.replace(/\n/g, '
')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
// .replace(/&/g, '&amp;')

return JSON.stringify(tpl);
};

var data = [];
var docData = [];

for (var k in templates) {
if (templates.hasOwnProperty(k)) {
var t = templates[k];
console.log(typeof t.tpl);
var isMethod = (typeof t.tpl === 'string' && t.tpl.indexOf(': function') > -1);
var tpl = t.tpl.next || t.tpl;
tpl = tpl.replace(/: function/g, '').replace(/},/g, '}');

tpl = tpl.replace(/: function/g, '');

isMethod && (tpl = tpl.replace(/},/g, '}'));

var snippet = {
name: k,
description: t.description || t.tpl,
tpl: processTpl(tpl),
tpl: escapeTpl(tpl),
variables: t.variables || [],
tplRaw: tpl
};

data.push(snippet);

if (t.tpl.next ||
(typeof t.tpl === 'string' && t.tpl.indexOf(': function') > -1)) {
(typeof t.tpl === 'string' && isMethod)) {

var tpl5 = t.tpl.es5 || t.tpl;
var snippet5 = {
name: k + '5',
description: t.description || t.tpl,
tpl: processTpl(tpl5),
tpl: escapeTpl(tpl5),
variables: t.variables || [],
tplRaw: tpl5
};
Expand All @@ -56,23 +62,23 @@ for (var k in templates) {
}
}

function processEnventsTpl(eventsMap) {
function processEventsTpl(eventsMap) {
for (var key in eventsMap) {
if (eventsMap.hasOwnProperty(key)) {
var tplName = eventsMap[key];
var tpl = `${key}={$END$}`;
data.push({
name: tplName,
description: key,
tpl: JSON.stringify(tpl),
tpl: escapeTpl(tpl),
tplRaw: tpl
});

}
}
}

processEnventsTpl(eventsTpl);
processEventsTpl(eventsTpl);

fs.writeFileSync('jetbrains/templates/ReactJS.xml', template(data));
fs.writeFileSync('README.md', readme.replace(
Expand Down
Binary file modified jetbrains-react.jar
Binary file not shown.

0 comments on commit bcc5086

Please sign in to comment.