`)
59 | }
60 |
61 | if (type === 'angular2') {
62 | output.push(`
`)
63 | }
64 | node.each(walk);
65 | output.push('
');
66 | }
67 | if (node.type === 'atrule' && node.name === 'component') {
68 | args.push(node.params);
69 | if (type === 'react') {
70 | output.push(`{${node.params}}`);
71 | }
72 | if (type === 'angular2') {
73 | if (node.params === 'children') {
74 | output.push(`
`);
75 | } else {
76 | output.push(`
`);
77 | }
78 | }
79 | }
80 | };
81 |
82 | tree.each(walk);
83 |
84 | return strategies[type](tree.nodes[0].selector, output, css, args);
85 | };
86 |
87 | module.exports = {
88 | parse
89 | };
90 |
--------------------------------------------------------------------------------
/loader/index.js:
--------------------------------------------------------------------------------
1 | var component = require('../index');
2 | module.exports = function(source) {
3 | return component.parse(source, 'react');
4 | };
5 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "css-components",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "escodegen": "^1.8.0",
13 | "mustache": "^2.2.1",
14 | "postcss": "^5.0.21"
15 | },
16 | "devDependencies": {
17 | "babel-core": "^6.9.1",
18 | "babel-loader": "^6.2.4",
19 | "babel-preset-es2015": "^6.9.0",
20 | "expect": "^1.20.1"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/react.template:
--------------------------------------------------------------------------------
1 | {{=<% %>=}}
2 | import React from 'react';
3 |
4 | const <%name%> = ({<%args%>}) => (
5 |
6 |
7 | <%={{ }}=%>
8 | {{{template}}}
9 |
10 | );
11 |
12 | export default {{name}};
13 |
--------------------------------------------------------------------------------
/webpack-example/.babelrc:
--------------------------------------------------------------------------------
1 | { "presets": ["es2015", "react"] }
2 |
--------------------------------------------------------------------------------
/webpack-example/UserComponent.css:
--------------------------------------------------------------------------------
1 | .UserComponent {
2 | display: flex;
3 | font: 12px Helvetica;
4 | color: #333;
5 | max-width: 680px;
6 | margin: auto;
7 |
8 | .Avatar {
9 | @component avatar;
10 | padding-right: 16px;
11 | }
12 |
13 | .Details {
14 | .Name {
15 | font-size: 36px;
16 | padding-bottom: 8px;
17 | @component name;
18 | }
19 |
20 | .Extra {
21 | font-size: 12px;
22 | color: #999;
23 | padding-bottom: 8px;
24 | @component extra;
25 | }
26 |
27 | .Biography {
28 | font-size: 14px;
29 | @component biography;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/webpack-example/advanced-component.css:
--------------------------------------------------------------------------------
1 | .AdvancedComponent {
2 | background-color: #000;
3 | color: #FFF;
4 | display: flex;
5 | justify-content: space-between;
6 |
7 | .Children {
8 | @component children;
9 | }
10 |
11 | .Icon {
12 | @component icon;
13 | color: green;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/webpack-example/component.css:
--------------------------------------------------------------------------------
1 | .MyComponent {
2 | background-color: #FF0;
3 | @component children;
4 | }
5 |
--------------------------------------------------------------------------------
/webpack-example/entry.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import CSSComponent from 'babel!../loader/index.js!./component.css';
4 | import AdvancedCSSComponent from 'babel!../loader/index.js!./advanced-component.css';
5 | import UserComponent from 'babel!../loader/index.js!./UserComponent.css';
6 |
7 | const Icon = () => (
8 |
Icon
9 | );
10 |
11 | class App extends React.Component {
12 | render() {
13 | return (
14 |
15 | }
17 | name='Merrick Christensen'
18 | biography='I am a kind chap but I get distracted easily. This entire component is compiled at build time. It can also compile Angular 2 components. I am not sure but I think I took this idea too far.'
19 | extra='Age 26 & Location Utah'
20 | />
21 |
22 | );
23 | }
24 | }
25 |
26 | ReactDOM.render(
, document.getElementById('app'));
27 |
--------------------------------------------------------------------------------
/webpack-example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/webpack-example/webpack.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | entry: './entry.js',
3 | output: {
4 | path: __dirname,
5 | filename: 'bundle.js'
6 | },
7 | resolve: {
8 | alias: {
9 | present: 'babel?presets=es2015,react!../loader/index.js'
10 | }
11 | },
12 | module: {
13 | loaders: [
14 | {
15 | test: /\.js$/,
16 | exclude: /(node_modules)/,
17 | loader: 'babel', // 'babel-loader' is also a legal name to reference
18 | query: {
19 | presets: ['es2015', 'react']
20 | }
21 | }
22 | ]
23 | }
24 | };
25 |
--------------------------------------------------------------------------------