Created
November 14, 2018 04:23
-
-
Save nebrelbug/76c736e5a460743e4b0f0a0e14bfde4a to your computer and use it in GitHub Desktop.
Defining a Squirrelly helper that will translate written colors to hex codes
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
Sqrl.defineHelper("returnColor", function (arg) { // In our case, the argument will be the value of 'options.color' | |
var colorScheme = { // This just maps the written colors to hex codes. Try editing or adding more colors! | |
brightgreen: "#4c1", | |
green: "#97CA00", | |
orange: "#fe7d37", | |
red: "#e05d44", | |
blue: "#007ec6", | |
} | |
if (colorScheme.hasOwnProperty(arg)) { // Then the color has a valid hex code associated with it | |
var result = colorScheme[arg] // Get the hex code | |
console.log("Resulting Hex: " + result) | |
return result // Return the hex code | |
} else { // If the color doesn't have a valid hex code associated with it | |
return arg // Just in case it's one of the built-in SVG colors | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment