LaloMrtnz / Prism
- пятница, 8 июля 2016 г. в 03:13:47
JavaScript
Creates a beautiful artboard color palette with all your 'Document Colors' and their respective color label in a variety of formats.
Download | Features | Usage | Customization | Changelog | Next | Contribute | Credits | Donate |
---|
(Formerly ShareableColorPalette)
Creates a beautiful artboard with all the colors in your 'Document Colors' with its respective color label in a variety of formats. (Sketch 3.8.3+)
Coffeescript
and love.To change the color alias, just change the text on the Name layer. If you want the default color name, just delete the text on that same layer.
Under the Prism menu, there's an option called Show Template File... that opens the Template.sketch file located under the Prism.sketchplugin package, this file contains the all the layers that are used as templates and are later copied over to your palette.
The template file is a normal sketch file that has multiple pages, each page with its own cell Template, you can add or remove all the pages you want to manage your own templates, to select the style you want just open the file and save it on the page your desired template is. Now just generate your palette to see the changes.
Prism offers a lot of freedom to let you customize your own templates, however, in order for your template to play nicely with Prism you just have a few restrictions:
ColorFormatter.coffee
file. Here is the "RGBA_CSS" format specification:ColorFormatter.coffee This is where the format is registered
# This is were formats are registered, the ID must be unique, the name is a human readable mini description, the format is used to use a custom file extension when saving colors to a file
FORMATS: [
{ id: "HEX", name: "HEX CSS", format: "colors.css" }
{ id: "RGBA_CSS", name: "RGBA CSS", format: "colors.css" }
{ id: "SASS", name: "SASS variables", format: "_colors.scss" }
{ id: "UICOLOR_SWIFT", name: "UIColor (Swift)", format: "colors.swift" }
{ id: "UICOLOR_OBJC", name: "UIColor (Objective-C)", format: "colors.m" }
{ id: "ANDROID", name: "Android ARGB Color", format: "colors.java" }
]
Then implement it in the same file
###
HERE is when you have to do the implementation of the new format you want to add.
all these methods must be prefixed with "format_" and then the format ID specified in the FORMATS array
The commented flag is used to add comments (like when we export colors)
or removing them (like when we are populating the cell layers with color data)
the color variable that is passed is a dictionary with all the information you need:
name: the default name of the color or the alias if it exists
hex: color's hex value without the leading '#'
red: color's red value from 0 to 1
blue: color's blue value from 0 to 1
green: color's green value from 0 to 1
alpha: color's alpha value from 0 to 1
###
format_RGBA_CSS: (color, commented) ->
alpha = if color.alpha < 1
color.alpha.toFixed(2)
else
color.alpha
formattedColor = "rgba(#{Math.round(color.red * 255)},#{Math.round(color.green * 255)},#{Math.round(color.blue * 255)},#{alpha});"
if commented
"#{formattedColor} /* #{color.name} */"
else
formattedColor
You can have as many text layers for formats as you want. Also, layers can be locked or invisible as long as they conform to this restrictions.
If you wanna dive deeper on this process, you should check out the Cell.coffee
and Template.coffee
files.
The best way to get things done is by doing them yourself, if you want to specify a format or a add a new feature or fix a bug, just submit a pull request!
I have included a compile.sh
file that automatically compiles all the files inside the src/ folder into the build/ folder, however, if you add new files you must import them in the right order inside the Prism.cocoascript
file.
You can run the compile.sh file by typing this in the terminal inside the Prism.sketchplugin/Content/Sketch folder:
./compile.sh
This will compile your files as soon as they are saved, as long as the process is running. To stop the process just Ctrl-C
out of it ;)