Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'npm:react';

<%= prefix %> <%= camelizedModuleName %> <%= contents %>

<%= camelizedModuleName %>.propTypes = {

};

export default <%= camelizedModuleName %>;
83 changes: 83 additions & 0 deletions blueprints/react-component/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*jshint node:true*/

var stringUtil = require('ember-cli-string-utils');
var pathUtil = require('ember-cli-path-utils');
var validComponentName = require('ember-cli-valid-component-name');
var getPathOption = require('ember-cli-get-component-path-option');
var path = require('path');

var normalizeEntityName = require('ember-cli-normalize-entity-name');

var templates = {
func: '= props => {\n\n\treturn (\n\t\t<div></div>\n\t);\n};',
class: 'extends React.Component {\n\trender() {\n\t\treturn (\n\t\t\t<div></div>\n\t\t);\n\t}\n};',
blockless: '= props => \n\t(\n\t\t<div></div>\n\t);'
}

module.exports = {
description: 'Generates a react component. Name must contain a hyphen.',

availableOptions: [
{
name: 'type',
type: String,
default: 'class',
aliases:[
{'func': 'function'},
{'no-block': 'blockless-function'}
]
}
],

fileMapTokens: function() {
return {
__path__: function(options) {
return 'components';
}
};
},

normalizeEntityName: function(entityName) {
entityName = normalizeEntityName(entityName);

return validComponentName(entityName);
},

locals: function(attrs) {
options = attrs.entity.options;
var prefix = 'const';
if (Object.keys(options).indexOf('func') !== -1) {
return {
prefix: prefix,
contents: templates.func
}
}

if (Object.keys(options).indexOf('no-block') !== -1) {
return {
prefix: prefix,
contents: templates.blockless
}
}

if (Object.keys(options).indexOf('type') !== -1) {
if (options.type === 'function' || options.type === 'func') {
return {
prefix: prefix,
contents: templates.func
}
}
if (options.type === 'blockless-function' || options.type === 'no-block') {
return {
prefix: prefix,
contents: templates.blockless
}
}
}

return {
prefix: 'class',
contents: templates.class
};
}
};
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var react = require('broccoli-react');

module.exports = {
name: 'ember-cli-react',

preprocessTree: function(type, tree) {
if (type === 'js') {
tree = react(tree, { transform: { es6module: true } } );
Expand Down