-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get rid of lodash, refactor templates to ES6 (#1160)
- Loading branch information
1 parent
6cfce97
commit 3485467
Showing
44 changed files
with
906 additions
and
761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'style-dictionary': minor | ||
--- | ||
|
||
Fix some inconsistencies in some of the templates, usually with regards to spaces/newlines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
examples/advanced/custom-formats-with-templates/templates/android-xml.template
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
examples/advanced/custom-formats-with-templates/templates/android-xml.template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @typedef {import('../../../../types/DesignToken.d.ts').Dictionary} Dictionary | ||
* @typedef {import('../../../../types/DesignToken.d.ts').TransformedToken} TransformedToken | ||
*/ | ||
|
||
export default ({ dictionary }) => `<?xml version="1.0" encoding="UTF-8"?> | ||
<resources> | ||
${dictionary.allTokens | ||
.map((token) => { | ||
if (token.attributes.category === 'color') { | ||
token.tag = 'color'; | ||
} else if (token.attributes.category === 'size') { | ||
token.tag = 'dimen'; | ||
} else if ( | ||
token.attributes.category === 'time' || | ||
token.attributes.category === 'opacity' || | ||
token.attributes.category === 'multiplier' | ||
) { | ||
token.tag = 'double'; | ||
} else if (token.attributes.category === 'content') { | ||
token.tag = 'string'; | ||
} else { | ||
token.tag = 'item'; | ||
} | ||
return token; | ||
}) | ||
.map( | ||
(token) => | ||
` <${token.tag} name="${token.name}">${token.value}</${token.tag}>${ | ||
token.comment ? `<!-- ${token.comment} -->` : '' | ||
}`, | ||
) | ||
.join('\n')} | ||
</resources>`; |
24 changes: 0 additions & 24 deletions
24
examples/advanced/custom-formats-with-templates/templates/ios-plist.template
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
examples/advanced/custom-formats-with-templates/templates/plist.template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @typedef {import('../../../../types/DesignToken.d.ts').Dictionary} Dictionary | ||
* @typedef {import('../../../../types/DesignToken.d.ts').TransformedToken} TransformedToken | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {TransformedToken} token | ||
*/ | ||
const tokenTemplate = (token) => { | ||
let output = ` <key>${token.name}</key>\n`; | ||
if (token.type === 'color') { | ||
output += ` <dict> | ||
<key>r</key> | ||
<real>${token.value[0] / 255}</real> | ||
<key>g</key> | ||
<real>${token.value[1] / 255}</real> | ||
<key>b</key> | ||
<real>${token.value[2] / 255}</real> | ||
<key>a</key> | ||
<real>1</real> | ||
</dict>`; | ||
} else if (token.type === 'dimension') { | ||
output += `<integer>${token.value}</integer>`; | ||
} else { | ||
output += `<string>${token.value}</string>`; | ||
} | ||
|
||
if (token.comment) { | ||
output += `\n <!-- ${token.comment} -->`; | ||
} | ||
return output; | ||
}; | ||
|
||
/** | ||
* @param {{ | ||
* dictionary: Dictionary | ||
* }} opts | ||
*/ | ||
export default ({ dictionary }) => ` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
${dictionary.allTokens | ||
.filter( | ||
(token) => | ||
token.type !== 'asset' && | ||
token.type !== 'border' && | ||
token.type !== 'shadow' && | ||
token.type !== 'transition', | ||
) | ||
.map((token) => tokenTemplate(token)) | ||
.join('\n')} | ||
</dict> | ||
</plist>`; |
3 changes: 0 additions & 3 deletions
3
examples/advanced/custom-formats-with-templates/templates/web-scss.template
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
examples/advanced/custom-formats-with-templates/templates/web-scss.template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @typedef {import('../../../../types/DesignToken.d.ts').TransformedToken} TransformedToken | ||
*/ | ||
|
||
/** | ||
* @param {{ | ||
* allTokens: TransformedToken[] | ||
* }} opts | ||
*/ | ||
export default ({ allTokens }) => `${allTokens | ||
.map((token) => `$${token.name}: ${token.value};${token.comment ? ` // ${token.comment}` : ''}`) | ||
.join('\n')} | ||
`; |
Oops, something went wrong.