Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Find a thing that looks like a color, modify it, then replace it. I made this back when I gave a shit about grunt.

License

Notifications You must be signed in to change notification settings

meyer-archives/grunt-colorswap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-colorswap

grunt-colorswap does one thing: it looks in the files you specify for strings that look like colors, runs the set of instructions you provide on each of these strings, then replaces those original strings with the updated color string.

Right now, grunt-colorswap works on hex and RGB color strings. If you read regex, the color-matching regexes might be of interest to you.

Using grunt-colorswap

I’d recommend checking out this project’s Gruntfile. Sample Gruntfile (in CoffeeScript, fight me):

module.exports = (grunt) ->

	grunt.initConfig

		colorswap:
			blue:
				files: ["tobias.svg"]
				options:
					instructions: "colorize #00F"

	grunt.loadNpmTasks "grunt-colorswap"

Running grunt colorswap will colorize the specified SVG file with the color blue using the colorize filter.

Available filters can be found in /tasks/filters.

Filters: the nitty gritty

Filters have two required methods, init and processColor.

The first method, init, validates instruction strings, and has only one parameter: the instruction string. An error should be thrown if the filter is called (set …), but the instruction string is something the filter doesn’t understand (set hungry to true). This method is expected to return true if everything went alright.

The second and last method, processColor, is what does the per-color manipulation. processColor receives one argument: a Chromath object representing the color to be modified. processColor is expected to return a Chromath object as well.

chromath and color-difference are available to filters.

TODOs

  • Friendlier instructions
  • …with pictures
  • Tests
  • Convert RGB to RGB and hex to hex instead of everything to hex

Shelved Ideas

  • instructions.yaml/txt: tasks can be dumped into a text file. Key-value kind of deal. Didn’t end up being important. Also, hex colors are read as comments in YAML.

About

Find a thing that looks like a color, modify it, then replace it. I made this back when I gave a shit about grunt.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published