Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit af1e660a64324d451784e5493ee725155f3de816 0 parents
@imathis authored
1  .gitignore
@@ -0,0 +1 @@
+*.gem
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem "compass", "0.11.5"
+gem 'rb-inotify'
11 LICENSE.markdown
@@ -0,0 +1,11 @@
+Copyright (c) 2011 Brandon Mathis
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. No attribution is required by products that make use of this software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.
+
+Contributors to this project agree to grant all rights to the copyright holder of the primary product. Attribution is maintained in the source control history of the product.
59 README.markdown
@@ -0,0 +1,59 @@
+# What is this?
+
+Color Hacker is a handy little utility for helping you crack your color schemes using Sass color functions.
+Simply pass the `hack-colors` function a list of colors and it will return a set of color functions that show
+how all of the colors in the color scheme can be derived from the first color.
+
+## Example
+
+``` scss
+@debug(hack-colors(#cff09e #a8dba8 #79bd9a #3b8686 #0b486b));
+```
+
+Output:
+
+``` scss
+$key: #cff09e;
+$color-2: scale-color(adjust-hue($key, 36deg), $saturation: -43.367%, $lightness: -2.764%);
+$color-3: scale-color(adjust-hue($key, 65deg), $saturation: -53.561%, $lightness: -22.111%);
+$color-4: scale-color(adjust-hue($key, 96deg), $saturation: -46.923%, $lightness: -51.508%);
+$color-5: scale-color(adjust-hue($key, 118deg), $saturation: 30.395%, $lightness: -70.352%);
+```
+
+
+## Setup
+
+Install the plugin:
+
+``` sh
+gem install color-hacker
+```
+
+Add Color Hacker to your compass configuration file:
+
+``` rb
+require 'color-hacker'
+```
+
+## Usage
+
+`hack-colors` accepts two variables.
+
+1. A space separated list of colors, e.g. (#fab #00face)
+2. Optional: A function type, scale or adjust. Defaults to scale.
+
+``` scss
+// Debug passes output to the terminal
+@debug(hack-colors(#beaf0c #deac0b));
+
+// Return adjust-color functions
+@debug(hack-colors(#beaf0c #deac0b, scale));
+
+```
+
+## License
+Copyright (c) 2008-2009 Brandon Mathis<br>
+All Rights Reserved.<br>
+Released under a [slightly modified MIT License][license].
+
+[license]: http://github.com/imathis/color-hacker/tree/master/LICENSE.markdown
4 VERSION.yml
@@ -0,0 +1,4 @@
+---
+:major: 1
+:minor: 0
+:patch: 0
22 color-hacker.gemspec
@@ -0,0 +1,22 @@
+path = "#{File.dirname(__FILE__)}/lib"
+require File.join(path, 'version')
+
+Gem::Specification.new do |gemspec|
+ gemspec.name = "color-hacker"
+ gemspec.version = ColorHacker::VERSION # Update the VERSION.yml file to set this.
+ gemspec.date = "#{Time.now.year}-#{Time.now.month}-#{Time.now.day}" # Automatically update for each build
+ gemspec.description = "Color Hacker is a Compass plugin which uses Sass color functions to find find the relationships between colors"
+ gemspec.homepage = "http://github.com/imathis/color-hacker"
+ gemspec.authors = ["Brandon Mathis"]
+ gemspec.email = "brandon@imathis.com"
+ gemspec.has_rdoc = false
+ gemspec.require_paths = %w(lib)
+ gemspec.rubygems_version = "1.3.6"
+ gemspec.summary = "Converts a list of colors into a set of dependant color functions"
+
+ gemspec.add_dependency 'compass', '>= 0.11'
+
+ gemspec.files = %w(README.markdown VERSION.yml)
+ gemspec.files += Dir.glob("lib/**/*")
+ gemspec.files += Dir.glob("stylesheets/**/*")
+end
7 lib/color-hacker.rb
@@ -0,0 +1,7 @@
+#require 'compass'
+
+base_directory = File.join(File.dirname(__FILE__), '..')
+stylesheets_dir = File.join(base_directory, 'stylesheets')
+templates_dir = File.join(base_directory, 'templates')
+
+Compass::Frameworks.register('color-hacker', :stylesheets_directory => stylesheets_dir, :templates_directory => templates_dir)
59 lib/version.rb
@@ -0,0 +1,59 @@
+module ColorHacker
+ module Version
+ # Returns a hash representing the version.
+ # The :major, :minor, and :teeny keys have their respective numbers.
+ # The :string key contains a human-readable string representation of the version.
+ # The :rev key will have the current revision hash.
+ #
+ # This method swiped from Compass by Chris Eppstein who swiped it from Haml and then modified it, so some credit goes to Nathan Weizenbaum too.
+ def version
+ if defined?(@version)
+ @version
+ else
+ read_version
+ end
+ end
+
+ protected
+
+ def scope(file) # :nodoc:
+ File.join(File.dirname(__FILE__), '..', file)
+ end
+
+ def read_version
+ require 'yaml'
+ @version = YAML::load(File.read(scope('VERSION.yml')))
+ @version[:teeny] = @version[:patch]
+ @version[:string] = "#{@version[:major]}.#{@version[:minor]}"
+ @version[:string] << ".#{@version[:patch]}" if @version[:patch]
+ @version[:string] << ".#{@version[:state]}" if @version[:state]
+ @version[:string] << ".#{@version[:build]}" if @version[:build]
+ #if !ENV['OFFICIAL'] && r = revision
+ # @version[:string] << ".#{r[0..6]}"
+ #end
+ @version
+ end
+
+ def revision
+ revision_from_git
+ end
+
+ def revision_from_git
+ if File.exists?(scope('.git/HEAD'))
+ rev = File.read(scope('.git/HEAD')).strip
+ if rev =~ /^ref: (.*)$/
+ rev = File.read(scope(".git/#{$1}")).strip
+ end
+ end
+ end
+ end
+ extend ColorHacker::Version
+ def self.const_missing(const)
+ # This avoid reading from disk unless the VERSION is requested.
+ if const == :VERSION
+ version[:string]
+ else
+ super
+ end
+ end
+end
35 stylesheets/_color-hacker.scss
@@ -0,0 +1,35 @@
+@function scale-to-adjust($start, $change) {
+ @if($change > 0) {
+ $end: $start + $change;
+ @return percentage(($end - $start)/(100 - $start));
+ } @else {
+ @return percentage($change / $start);
+ }
+}
+
+@function scale-key($key, $color) {
+ $h: hue($color) - hue($key);
+ $s: saturation($color) - saturation($key);
+ $l: lightness($color) - lightness($key);
+ @return "scale-color(adjust-hue($key, #{$h}), $saturation: #{scale-to-adjust(saturation($key), $s)}, $lightness: #{scale-to-adjust(lightness($key), $l)}); ";
+}
+
+@function adjust-key($key, $color) {
+ $h: hue($color) - hue($key);
+ $s: saturation($color) - saturation($key);
+ $l: lightness($color) - lightness($key);
+ @return "adjust-color($key, $hue: #{$h}, $saturation: #{$s}, $lightness: #{$l}); ";
+}
+
+@function hack-colors($colors, $method: scale){
+ $key: nth($colors, 1);
+ $hack: "$key: #{$key}; ";
+ @for $i from 2 through length($colors) {
+ @if $method == scale {
+ $hack: $hack + "$color-#{$i}: #{scale-key($key, nth($colors, $i))}";
+ } @else {
+ $hack: $hack + "$color-#{$i}: #{adjust-key($key, nth($colors, $i))}";
+ }
+ }
+ @return $hack;
+}

0 comments on commit af1e660

Please sign in to comment.
Something went wrong with that request. Please try again.