Skip to content

Commit

Permalink
add result message
Browse files Browse the repository at this point in the history
  • Loading branch information
robintindale committed Dec 16, 2017
1 parent b03a03d commit e3e9861
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Library Styles Sync",
"identifier": "com.zeroheight.library-styles-sync",
"version": "1.0.2",
"version": "1.0.3",
"description": "sync shared styles with a Library document",
"authorEmail": "[email protected]",
"author": "zeroheight team",
Expand Down
12 changes: 9 additions & 3 deletions library-styles-sync.sketchplugin/Contents/Sketch/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@ var syncJSON = function (context) {

var doc = context.document.documentData();
var currentStyles = createLookup(doc.layerTextStyles());
var result = {created: 0};

createStyles(typography, colors, doc.layerTextStyles(), currentStyles, '');
createStyles(typography, colors, doc.layerTextStyles(), currentStyles, '', result);

context.document.reloadInspector();
context.document.showMessage('Synced ' + result.created + ' styles from JSON');
};

var createStyles = function (typography, colors, sharedStyles, currentStyles, path) {
var createStyles = function (typography, colors, sharedStyles, currentStyles, path, result) {
var properties = {};
var styleColors = [];

for (var key in typography) {
if (typography.hasOwnProperty(key)) {
var value = typography[key];
if (typeof value === 'object' && !value[0]) {
createStyles(value, colors, sharedStyles, currentStyles, path + '/' + key);
createStyles(value, colors, sharedStyles, currentStyles, path + '/' + key, result);
} else {
if (key === 'color') {
styleColors.push(value);
Expand All @@ -104,13 +108,15 @@ var createStyles = function (typography, colors, sharedStyles, currentStyles, pa
if (styleColors.length === 0) {
properties['color'] = colors.primary;
createStyle(path.substr(1), properties, sharedStyles, currentStyles);
result.created++;
} else {
for (var i = 0; i < styleColors.length; ++i) {
var colorString = styleColors[i];
properties['color'] = colors[colorString];
var capitalColorString = colorString.charAt(0).toUpperCase() + colorString.slice(1);
createStyle(path.substr(1) + '/' + capitalColorString, properties,
sharedStyles, currentStyles);
result.created++;
}
}
};
Expand Down

0 comments on commit e3e9861

Please sign in to comment.