Last active
December 16, 2015 12:19
-
-
Save lerouxb/5433456 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # extract the weight and style from a google font variant string | |
| splitVariant = (variant) -> | |
| weight = 'normal' | |
| style = 'normal' | |
| unless variant == 'regular' | |
| if variant == 'italic' | |
| style = 'italic' | |
| else | |
| weight = variant[..2] | |
| italic = variant[3..] | |
| if italic == 'italic' | |
| style = 'italic' | |
| info = | |
| weight: weight | |
| style: style | |
| info | |
| # turn weight and style into a google font compatible variant string | |
| combineVariant = (weight, style) -> | |
| weight ?= 'normal' | |
| style ?= 'normal' | |
| if weight == 'normal' and style == 'normal' | |
| 'regular' | |
| else | |
| if weight == 'normal' | |
| # normal + italic becomes 'italic' only | |
| # (normal/normal is already handled as regular above) | |
| weight = '' | |
| else if weight == 'bold' | |
| weight = '700' | |
| unless style == 'italic' | |
| # assume everything else is normal | |
| style = '' | |
| "#{weight}#{style}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment