Skip to content

Commit

Permalink
Develop into master for v2.7.0 release (#244)
Browse files Browse the repository at this point in the history
* feat: add registerFilter method (#233)
* doc: remove registerTemplate from examples (#232)
* feat: add node example (#228)
* feat: making include accept an array of globs, like source does (#227)
* fix: the naming for Sass/Scss in documentation, tests, formats, fixes #213 (#222)
* fix: handle showFileHeader option in androids formats templates, fixes #237
 (#243)
  • Loading branch information
dbanksdesign authored Feb 5, 2019
1 parent 098f6b6 commit 6f62c3e
Show file tree
Hide file tree
Showing 63 changed files with 1,235 additions and 242 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ While not exactly necessary, we feel this classification structure of style prop

Structuring style properties in this manner gives us consistent naming and accessing of these properties. You don't need to remember if it is button_color_error or error_button_color, it is color_background_button_error!

Technically, you can organize and name your style properties however you want, there are no restrictions. But we have a good amount of helpers if you do use this structure, like the 'attribute/cti' transform which adds attributes to the property of its CTI based on the path in the object. There are a lot of name transforms as well for when you want a flat structure like for sass variables.
Technically, you can organize and name your style properties however you want, there are no restrictions. But we have a good amount of helpers if you do use this structure, like the 'attribute/cti' transform which adds attributes to the property of its CTI based on the path in the object. There are a lot of name transforms as well for when you want a flat structure like for Sass variables.

Also, the CTI structure provides a good mechanism to target transforms for specific kinds of properties. All of the transforms provided by the framework use the CTI of a property to know if it should be applied. For instance, the 'color/hex' transform only applies to properties of the category 'color'.

Expand Down
40 changes: 32 additions & 8 deletions __tests__/extend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,33 @@ describe('extend', () => {
).toThrow('include must be an array');
});

it('should throw if a path in the includes array doesnt resolve', () => {
expect(
StyleDictionary.extend.bind(null, {include: ['foo']})
).toThrow("Cannot find module 'foo'");
it('should not update properties if include glob paths dont resolve to anything', () => {
var StyleDictionaryExtended = StyleDictionary.extend({
include: ['foo']
});
expect(typeof StyleDictionaryExtended.properties.size).toBe('undefined');
});

it('should properly glob paths', () => {
var StyleDictionaryExtended = StyleDictionary.extend({
include: [__dirname + '/__properties/*.json']
});
expect(typeof StyleDictionaryExtended.properties.size.padding.tiny).toBe('object');
});

it('should build the properties object if an include is given', () => {
var StyleDictionaryExtended = StyleDictionary.extend({
"include": [__dirname + "/__properties/paddings.json"]
});
expect(StyleDictionaryExtended.properties).toEqual(helpers.fileToJSON(__dirname + "/__properties/paddings.json"));
});

it('should override existing properties if include is given', () => {
var StyleDictionaryExtended = StyleDictionary.extend({
properties: test_props,
include: [__dirname + "/__properties/paddings.json"]
});
expect(StyleDictionaryExtended.properties).toEqual(helpers.fileToJSON(__dirname + "/__properties/paddings.json"));
});

it('should update properties if there are includes', () => {
Expand All @@ -91,10 +114,11 @@ describe('extend', () => {
).toThrow('source must be an array');
});

it('should throw if a path in the source array doesnt resolve', () => {
expect(
StyleDictionary.extend.bind(null, {include: ['foo']})
).toThrow("Cannot find module 'foo'");
it('should not update properties if source glob paths don\'t resolve to anything', () => {
var StyleDictionaryExtended = StyleDictionary.extend({
source: ['foo']
});
expect(typeof StyleDictionaryExtended.properties.size).toBe('undefined');
});

it('should build the properties object if a source is given', () => {
Expand Down
25 changes: 15 additions & 10 deletions __tests__/filterProperties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,21 @@ describe('filterProperties', () => {
expect(filteredDictionary.properties).not.toHaveProperty('color');
});

it('should work with a filter object', () => {
var filter = { "attributes": { "category": "size" } };
var filteredDictionary = filterProperties(dictionary, filter);
_.each(filteredDictionary.allProperties, function(property) {
expect(property).not.toBe(colorRed);
expect(property).not.toBe(colorBlue);
describe('should throw if', () => {
it('filter is a string', () => {
expect(
function(){
filterProperties(dictionary, 'my_filter')
}
).toThrow(/filter is not a function/);
});
it('filter is an object', () => {
expect(
function(){
filterProperties(dictionary, { "attributes": { "category": "size" } })
}
).toThrow(/filter is not a function/);
});
expect(filteredDictionary.allProperties).toEqual([sizeSmall, sizeLarge]);
expect(filteredDictionary.properties).toHaveProperty('size');
expect(filteredDictionary.properties).not.toHaveProperty('color');

});

});
Loading

0 comments on commit 6f62c3e

Please sign in to comment.