Skip to content

Commit

Permalink
Addressing a few items from #3
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer516 committed Jan 9, 2017
1 parent 06e7e91 commit fac3c3b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
45 changes: 36 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,42 @@ export default Component.extend({
{{/each}}
```

## The Pieces
### Dynamically Generated Class Names

1. A Broccoli Plugin for finding the config files and processing in order from addon up to app.
- Should create an in memory file for converting a class name into a list of class names
2. The `classNamesMacro` for converting `classNameBindings` that have truthy/falsey values.
3. Babel Plugin to transpile component files looking for string definitions beginning with `@`
- Imports file from step 1
4. HTMLBars Plugin to transpile template files looking for `class="@"`
- Imports file from step 2
In the event that you need to dynamically generate class names, you can directly import the `classify`
utility to convert a key into a list of class names. For example:

```css
/* app/styles/app.css-compose */
@composer {
@myComponent-red {
composes: 'red';
}

@myComponent-blue {
composes: 'blue';
}

}
```

```js
import Component from 'ember-component';
import computed from 'ember-computed';
import get from 'ember-metal/get';
import { classify } from 'ember-css-composer';

export default Component.extend({
classNameBindings: ['colorClass'],
color: 'red',

colorClass: computed('color', {
get() {
return classify(`myComponent-${get(this, 'color')}`);
}
})
});
```

## Installation

Expand All @@ -113,4 +140,4 @@ export default Component.extend({

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).

![Amadeus](http://24.media.tumblr.com/tumblr_mcbz1pZFKN1qllovxo1_500.gif)
![Amadeus](http://24.media.tumblr.com/tumblr_mcbz1pZFKN1qllovxo1_500.gif)
10 changes: 10 additions & 0 deletions addon/[css-classes-json.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
This is a placeholder file. At build time, the application will generate a
real file that exports a POJO that maps from lookup names to output names.

Something like:
*/

export default {
'component-a': ['class-1', 'class-2', 'class-3']
};
5 changes: 5 additions & 0 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import classify from './classify';

export {
classify
};
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* jshint node: true */
'use strict';

const LOOKUP_OUTPUT = 'css-classes-json.js';
const CSStoJSON = require('./lib/css-plugin/index');
const BabelPlugin = require('./lib/babel-plugin/index');
const BabelTranspiler = require('broccoli-babel-transpiler');
Expand Down Expand Up @@ -43,7 +44,7 @@ module.exports = {
});

let configFileTree = CSStoJSON(cssComposeTree, {
outputFile: 'modules/ember-css-composer/css-classes-json.js'
outputFile: `modules/ember-css-composer/${LOOKUP_OUTPUT}`
});

return new MergeTrees([addonTree, configFileTree]);
Expand Down

0 comments on commit fac3c3b

Please sign in to comment.