Skip to content

Instantly share code, notes, and snippets.

@nebrelbug
Created November 14, 2018 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nebrelbug/76c736e5a460743e4b0f0a0e14bfde4a to your computer and use it in GitHub Desktop.
Save nebrelbug/76c736e5a460743e4b0f0a0e14bfde4a to your computer and use it in GitHub Desktop.
Defining a Squirrelly helper that will translate written colors to hex codes
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