compass 0.10.0.pre5 → 0.10.0.pre6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.markdown +48 -0
- data/VERSION.yml +1 -1
- data/examples/css3/extensions/compass-colors/README.markdown +50 -0
- data/examples/css3/extensions/compass-colors/VERSION.yml +5 -0
- data/examples/css3/extensions/compass-colors/example/config.rb +13 -0
- data/examples/css3/extensions/compass-colors/example/src/_split_compliment_theme.sass +28 -0
- data/examples/css3/extensions/compass-colors/example/src/screen.sass +40 -0
- data/examples/css3/extensions/compass-colors/lib/compass-colors.rb +9 -0
- data/examples/css3/extensions/compass-colors/lib/compass-colors/compass_extension.rb +7 -0
- data/examples/css3/extensions/compass-colors/lib/compass-colors/hsl.rb +109 -0
- data/examples/css3/extensions/compass-colors/lib/compass-colors/sass_extensions.rb +112 -0
- data/examples/css3/extensions/compass-colors/spec/approximate_color_matching.rb +43 -0
- data/examples/css3/extensions/compass-colors/spec/sass_extensions_spec.rb +54 -0
- data/examples/css3/extensions/compass-colors/templates/analogous/_theme.sass +28 -0
- data/examples/css3/extensions/compass-colors/templates/analogous/manifest.rb +1 -0
- data/examples/css3/extensions/compass-colors/templates/basic/_theme.sass +7 -0
- data/examples/css3/extensions/compass-colors/templates/basic/manifest.rb +1 -0
- data/examples/css3/extensions/compass-colors/templates/complementary/_theme.sass +20 -0
- data/examples/css3/extensions/compass-colors/templates/complementary/manifest.rb +1 -0
- data/examples/css3/extensions/compass-colors/templates/split_complement/_theme.sass +28 -0
- data/examples/css3/extensions/compass-colors/templates/split_complement/manifest.rb +1 -0
- data/examples/css3/extensions/compass-colors/templates/triadic/_theme.sass +28 -0
- data/examples/css3/extensions/compass-colors/templates/triadic/manifest.rb +1 -0
- data/examples/css3/gradients.html.haml +60 -0
- data/examples/css3/index.html.haml +10 -8
- data/examples/css3/src/fancy-fonts.sass +1 -1
- data/examples/css3/src/gradients.sass +69 -0
- data/examples/css3/src/main.sass +38 -10
- data/frameworks/blueprint/stylesheets/blueprint/_liquid.sass +12 -10
- data/frameworks/blueprint/stylesheets/blueprint/modules/_buttons.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_colors.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_debug.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_fancy_type.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_form.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_grid.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_interaction.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_link_icons.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_liquid.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_reset.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_rtl.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_scaffolding.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_typography.sass +1 -1
- data/frameworks/blueprint/stylesheets/blueprint/modules/_utilities.sass +1 -1
- data/frameworks/compass/stylesheets/compass/css3/_gradient.sass +54 -36
- data/frameworks/compass/stylesheets/compass/layout/_sticky_footer.sass +1 -0
- data/frameworks/compass/stylesheets/compass/utilities/general/_hacks.sass +7 -7
- data/frameworks/compass/stylesheets/compass/utilities/lists/_horizontal_list.sass +6 -2
- data/lib/compass.rb +1 -1
- data/lib/compass/app_integration/rails.rb +6 -0
- data/lib/compass/app_integration/rails/{action_controller.rb → actionpack2/action_controller.rb} +0 -0
- data/lib/compass/app_integration/rails/{sass_plugin.rb → actionpack2/sass_plugin.rb} +0 -0
- data/lib/compass/app_integration/rails/{urls.rb → actionpack2/urls.rb} +0 -0
- data/lib/compass/app_integration/rails/installer.rb +8 -5
- data/lib/compass/app_integration/rails/runtime.rb +8 -4
- data/lib/compass/commands/installer_command.rb +1 -3
- data/lib/compass/commands/project_base.rb +1 -3
- data/lib/compass/commands/write_configuration.rb +5 -2
- data/lib/compass/compiler.rb +7 -0
- data/lib/compass/configuration/adapters.rb +3 -3
- data/lib/compass/configuration/defaults.rb +4 -0
- data/lib/compass/configuration/helpers.rb +16 -0
- data/lib/compass/configuration/inheritance.rb +6 -2
- data/lib/compass/configuration/serialization.rb +8 -3
- data/lib/compass/exec.rb +5 -1
- data/lib/compass/frameworks.rb +15 -5
- data/lib/compass/logger.rb +8 -4
- data/lib/compass/sass_extensions/functions.rb +3 -2
- data/lib/compass/sass_extensions/functions/gradient_support.rb +186 -0
- data/lib/compass/sass_extensions/functions/image_size.rb +97 -0
- data/test/compass_test.rb +1 -1
- data/test/configuration_test.rb +30 -0
- data/test/fixtures/stylesheets/compass/100x150.jpg +0 -0
- data/test/fixtures/stylesheets/compass/css/gradients.css +71 -0
- data/test/fixtures/stylesheets/compass/css/image_size.css +15 -0
- data/test/fixtures/stylesheets/compass/css/layout.css +1 -0
- data/test/fixtures/stylesheets/compass/images/100x150.gif +0 -0
- data/test/fixtures/stylesheets/compass/images/100x150.jpeg +0 -0
- data/test/fixtures/stylesheets/compass/images/100x150.jpg +0 -0
- data/test/fixtures/stylesheets/compass/images/100x150.png +0 -0
- data/test/fixtures/stylesheets/compass/sass/gradients.sass +48 -0
- data/test/fixtures/stylesheets/compass/sass/image_size.sass +12 -0
- metadata +70 -15
- data/examples/css3/src/gradient.sass +0 -10
- data/lib/compass/sass_extensions/functions/color_stop.rb +0 -10
data/CHANGELOG.markdown
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
COMPASS CHANGELOG
|
|
2
2
|
=================
|
|
3
3
|
|
|
4
|
+
0.10.0.pre6 (February 22, 2010)
|
|
5
|
+
-------------------------------
|
|
6
|
+
|
|
7
|
+
**IMPORTANT:**
|
|
8
|
+
|
|
9
|
+
* Rails users need to update their compass initializer.
|
|
10
|
+
* The CSS 3 Gradient mixins were re-written and their usage has changed.
|
|
11
|
+
|
|
12
|
+
Read on for the details:
|
|
13
|
+
|
|
14
|
+
### CLI
|
|
15
|
+
* Fixed some issues with colorized output.
|
|
16
|
+
* Don't force the user to specify the configuration path when calling compass config
|
|
17
|
+
|
|
18
|
+
### Compass Core
|
|
19
|
+
* Fix to the bang_hack mixin (Credit: Mark Rajcok)
|
|
20
|
+
* Support :first-child and :last-child pseudo selectors for +horizontal-list. (Credit: Cody Robbins)
|
|
21
|
+
* Clear the sticky footer so that it works correctly with grid layouts.
|
|
22
|
+
* The css3 gradient module has been re-written and has a new, much simpler mixins. If you have been using the css3 gradient mixins, you'll need to update your sass stylesheets. The new mixins can be seen in action [here](http://compass-style.org/examples/css3/gradients.html).
|
|
23
|
+
* Added new helper functions: `image_width("path/to/image.png")` & `image_height("path/to/image.png")` that return the size in pixels. (Credit: Deepak Jois & Richard Aday)
|
|
24
|
+
|
|
25
|
+
### Blueprint
|
|
26
|
+
* Take margins into account in liquid grid. (Credit: Christoffer Eliesen)
|
|
27
|
+
|
|
28
|
+
### Rails
|
|
29
|
+
* Several Rails 3 bug fixes (Credit: Jacques Crocker)
|
|
30
|
+
* Don't set unset options on the Sass::Plugin
|
|
31
|
+
* Fixed a setup bug and handle compass configuration changes at rails boot.
|
|
32
|
+
|
|
33
|
+
**IMPORTANT:** Existing rails projects _must_ change their compass initializer file to:
|
|
34
|
+
|
|
35
|
+
require 'compass'
|
|
36
|
+
rails_root = (defined?(Rails) ? Rails.root : RAILS_ROOT).to_s
|
|
37
|
+
Compass.add_project_configuration(File.join(rails_root, "config", "compass.rb"))
|
|
38
|
+
Compass.configure_sass_plugin!
|
|
39
|
+
Compass.handle_configuration_change!
|
|
40
|
+
|
|
41
|
+
### Internals
|
|
42
|
+
* New APIs for dealing with configuration changes and accessing a compiler instance.
|
|
43
|
+
* Provide a convenience function for discovering extensions: `Compass.discover_extensions!` that can be called during project configuration w/ other ruby frameworks.
|
|
44
|
+
|
|
45
|
+
### Extensions
|
|
46
|
+
|
|
47
|
+
* Don't force an extension to register itself just because it has ruby code.
|
|
48
|
+
This makes it easier for extensions to provide Sass functions from ruby.
|
|
49
|
+
|
|
50
|
+
Special thanks to Daniel Hofstetter for fixing my typos.
|
|
51
|
+
|
|
4
52
|
0.10.0.pre5 (January 18, 2010)
|
|
5
53
|
------------------------------
|
|
6
54
|
* Fixed a bug in the grid builder in ruby 1.8.6 (Credit: [Richard Wöber][der-rich])
|
data/VERSION.yml
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Compass Colors
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
This compass extension provides support for working with colors in Sass and generating color themes for use on your website.
|
|
5
|
+
|
|
6
|
+
Installing
|
|
7
|
+
==========
|
|
8
|
+
|
|
9
|
+
sudo gem install chriseppstein-compass-colors
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
To install a theme into your existing compass project, add the following to your compass configuration file:
|
|
13
|
+
|
|
14
|
+
require 'compass-colors'
|
|
15
|
+
|
|
16
|
+
Then run this command:
|
|
17
|
+
|
|
18
|
+
compass -f colors -p <Theme Name>
|
|
19
|
+
|
|
20
|
+
The _theme.sass partial can then be imported into your stylesheets and the color constants can be used.
|
|
21
|
+
|
|
22
|
+
@import theme.sass
|
|
23
|
+
|
|
24
|
+
Supported Color Themes
|
|
25
|
+
======================
|
|
26
|
+
|
|
27
|
+
With all of these themes, you must pick a base color and the theme takes it from there:
|
|
28
|
+
|
|
29
|
+
* Basic/Monochromatic (basic)
|
|
30
|
+
* Complementary (complementary)
|
|
31
|
+
* Triadic (triadic)
|
|
32
|
+
* Split Complementary (split_complement)
|
|
33
|
+
* Analogous (analogous)
|
|
34
|
+
|
|
35
|
+
Sass Functions Provided
|
|
36
|
+
=======================
|
|
37
|
+
|
|
38
|
+
* `lighten(color, percentage)` - Create a color lighter by the percent amount provided.
|
|
39
|
+
* `darken(color, percentage)` - Create a color darker by the percent amount provided.
|
|
40
|
+
* `saturate(color, percentage)` - Increase the saturation of a color by the percent amount provided.
|
|
41
|
+
* `desaturate(color, percentage)` - Decrease the saturation of a color by the percent amount provided.
|
|
42
|
+
* `hue(color)` - Extract the hue from the color in degrees (0-360). Suitable to be passed as the first argument of hsl.
|
|
43
|
+
* `saturation(color)` - Extract the saturation from the color in percent (0-100). Suitable to be passed as the second argument of hsl.
|
|
44
|
+
* `luminosity(color)` - Extract the luminosity from the color in percent (0-100). Suitable to be passed as the third argument of hsl.
|
|
45
|
+
* `mix(color1, color2, percentage)` - Create a new color by mixing two colors together. Percentage (0-100) is optional, and indicates how
|
|
46
|
+
much of color2 should be mixed into color1.
|
|
47
|
+
* `grayscale(color)` - Create a gray color by mapping the color provided to the grayscale.
|
|
48
|
+
* `adjust_hue(color, degrees)` - Add the number of degrees provided to the hue of the color keeping luminosity and saturation constant.
|
|
49
|
+
Degrees can be negative.
|
|
50
|
+
* `complement(color)` - Returns the compliment of the color provided.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Require any additional compass plugins here.
|
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'compass-colors')
|
|
3
|
+
|
|
4
|
+
project_type = :stand_alone
|
|
5
|
+
# Set this to the root of your project when deployed:
|
|
6
|
+
http_path = "/"
|
|
7
|
+
css_dir = "stylesheets"
|
|
8
|
+
sass_dir = "src"
|
|
9
|
+
images_dir = "images"
|
|
10
|
+
extensions_dir = "extensions"
|
|
11
|
+
output_style = :compact
|
|
12
|
+
# To enable relative paths to assets via compass helper functions. Uncomment:
|
|
13
|
+
relative_assets = true
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// In theory the lightness and saturation values of corresponding colors should not change.
|
|
2
|
+
// In reality, these values should be adjusted to create a more pleasant color combination.
|
|
3
|
+
// There is not any mathematical formula for this, but you can use the lighten, darken,
|
|
4
|
+
// saturate and desaturate functions to adjust your main colors.
|
|
5
|
+
!base_color ||= red
|
|
6
|
+
!complement_support_color = adjust_hue(!base_color, 180 + 30)
|
|
7
|
+
!complement_accent_color = adjust_hue(!base_color, 180 - 30)
|
|
8
|
+
|
|
9
|
+
!base_dark_color = darken(!base_color, 25)
|
|
10
|
+
!base_darker_color = darken(!base_color, 50)
|
|
11
|
+
!base_darkest_color = darken(!base_color, 75)
|
|
12
|
+
!base_light_color = lighten(!base_color, 25)
|
|
13
|
+
!base_lighter_color = lighten(!base_color, 50)
|
|
14
|
+
!base_lightest_color = lighten(!base_color, 75)
|
|
15
|
+
|
|
16
|
+
!dark_complement_support_color = darken(!complement_support_color, 25)
|
|
17
|
+
!darker_complement_support_color = darken(!complement_support_color, 50)
|
|
18
|
+
!darkest_complement_support_color = darken(!complement_support_color, 75)
|
|
19
|
+
!light_complement_support_color = lighten(!complement_support_color, 25)
|
|
20
|
+
!lighter_complement_support_color = lighten(!complement_support_color, 50)
|
|
21
|
+
!lightest_complement_support_color = lighten(!complement_support_color, 75)
|
|
22
|
+
|
|
23
|
+
!dark_complement_accent_color = darken(!complement_accent_color, 25)
|
|
24
|
+
!darker_complement_accent_color = darken(!complement_accent_color, 50)
|
|
25
|
+
!darkest_complement_accent_color = darken(!complement_accent_color, 75)
|
|
26
|
+
!light_complement_accent_color = lighten(!complement_accent_color, 25)
|
|
27
|
+
!lighter_complement_accent_color = lighten(!complement_accent_color, 50)
|
|
28
|
+
!lightest_complement_accent_color = lighten(!complement_accent_color, 75)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@import compass/utilities.sass
|
|
2
|
+
// We can change the theme color here by pre-setting the !base_color
|
|
3
|
+
!base_color = #614DA3
|
|
4
|
+
@import split_compliment_theme.sass
|
|
5
|
+
|
|
6
|
+
html
|
|
7
|
+
:height 100%
|
|
8
|
+
|
|
9
|
+
body#split-compliment
|
|
10
|
+
:margin 0
|
|
11
|
+
:height 100%
|
|
12
|
+
.base
|
|
13
|
+
:background-color = !base_color
|
|
14
|
+
.darker
|
|
15
|
+
:background-color = !base_dark_color
|
|
16
|
+
.lighter
|
|
17
|
+
:background-color = !base_light_color
|
|
18
|
+
.complement-support
|
|
19
|
+
:background-color = !complement_support_color
|
|
20
|
+
.darker
|
|
21
|
+
:background-color = !dark_complement_support_color
|
|
22
|
+
.lighter
|
|
23
|
+
:background-color = !light_complement_support_color
|
|
24
|
+
.complement-accent
|
|
25
|
+
:background-color = !complement_accent_color
|
|
26
|
+
.darker
|
|
27
|
+
:background-color = !dark_complement_accent_color
|
|
28
|
+
.lighter
|
|
29
|
+
:background-color = !light_complement_accent_color
|
|
30
|
+
.base, .complement-support, .complement-accent
|
|
31
|
+
+clearfix
|
|
32
|
+
:height 33%
|
|
33
|
+
div
|
|
34
|
+
:height 100%
|
|
35
|
+
.darker
|
|
36
|
+
:float left
|
|
37
|
+
.lighter
|
|
38
|
+
:float right
|
|
39
|
+
.darker, .lighter
|
|
40
|
+
:width 33%
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'compass'
|
|
2
|
+
|
|
3
|
+
module Compass
|
|
4
|
+
module Colors
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
require File.join(File.dirname(__FILE__), 'compass-colors', 'hsl')
|
|
8
|
+
require File.join(File.dirname(__FILE__), 'compass-colors', 'compass_extension')
|
|
9
|
+
require File.join(File.dirname(__FILE__), 'compass-colors', 'sass_extensions')
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
if defined?(Compass)
|
|
2
|
+
options = Hash.new
|
|
3
|
+
options[:stylesheets_directory] = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'sass'))
|
|
4
|
+
options[:templates_directory] = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'templates'))
|
|
5
|
+
|
|
6
|
+
Compass::Frameworks.register('colors', options)
|
|
7
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
module Compass
|
|
2
|
+
module Colors
|
|
3
|
+
class HSL
|
|
4
|
+
|
|
5
|
+
# Stored in degrees [0, 360)
|
|
6
|
+
attr_reader :h
|
|
7
|
+
# Stored as a number from [0,1]
|
|
8
|
+
attr_reader :s, :l
|
|
9
|
+
|
|
10
|
+
def self.from_color(color)
|
|
11
|
+
rgb = color.respond_to?(:rgb) ? color.rgb : color.value
|
|
12
|
+
from_rgb(*rgb)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.from_rgb(r, g, b)
|
|
16
|
+
rgb = [r,g,b]
|
|
17
|
+
rgb.map!{|c| c / 255.0}
|
|
18
|
+
min_rgb = rgb.min
|
|
19
|
+
max_rgb = rgb.max
|
|
20
|
+
delta = max_rgb - min_rgb
|
|
21
|
+
|
|
22
|
+
lightness = (max_rgb + min_rgb) / 2.0
|
|
23
|
+
|
|
24
|
+
if delta < 1e-5
|
|
25
|
+
hue = 0
|
|
26
|
+
saturation = 0
|
|
27
|
+
else
|
|
28
|
+
saturation = if ( lightness < 0.5 )
|
|
29
|
+
delta / ( max_rgb + min_rgb )
|
|
30
|
+
else
|
|
31
|
+
delta / ( 2 - max_rgb - min_rgb )
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
deltas = rgb.map{|c| (((max_rgb - c) / 6.0) + (delta / 2.0)) / delta}
|
|
35
|
+
|
|
36
|
+
hue = if (rgb[0] - max_rgb).abs < 1e-5
|
|
37
|
+
deltas[2] - deltas[1]
|
|
38
|
+
elsif (rgb[1] - max_rgb).abs < 1e-5
|
|
39
|
+
( 1.0 / 3.0 ) + deltas[0] - deltas[2]
|
|
40
|
+
else
|
|
41
|
+
( 2.0 / 3.0 ) + deltas[1] - deltas[0]
|
|
42
|
+
end
|
|
43
|
+
hue += 1 if hue < 0
|
|
44
|
+
hue -= 1 if hue > 1
|
|
45
|
+
end
|
|
46
|
+
from_fractions(hue, saturation, lightness)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.from_fractions(hue, saturation, lightness)
|
|
50
|
+
HSL.new(360 * hue, saturation, lightness)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def initialize(h, s, l)
|
|
54
|
+
self.h = h
|
|
55
|
+
self.s = s
|
|
56
|
+
self.l = l
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def to_color
|
|
60
|
+
m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s
|
|
61
|
+
m1 = l * 2 - m2
|
|
62
|
+
Sass::Script::Color.new([hue_to_rgb(m1, m2, hp + 1.0/3),
|
|
63
|
+
hue_to_rgb(m1, m2, hp),
|
|
64
|
+
hue_to_rgb(m1, m2, hp - 1.0/3)].map { |c| (c * 0xff).round })
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def h=(hue)
|
|
68
|
+
@h = hue % 360
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def s=(saturation)
|
|
72
|
+
@s = if saturation < 0
|
|
73
|
+
0.0
|
|
74
|
+
elsif saturation > 1
|
|
75
|
+
1.0
|
|
76
|
+
else
|
|
77
|
+
saturation
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def l=(lightness)
|
|
82
|
+
@l = if lightness < 0
|
|
83
|
+
0.0
|
|
84
|
+
elsif lightness > 1
|
|
85
|
+
1.0
|
|
86
|
+
else
|
|
87
|
+
lightness
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
#hue as a percentage
|
|
93
|
+
def hp
|
|
94
|
+
h / 360.0
|
|
95
|
+
end
|
|
96
|
+
# helper for making rgb
|
|
97
|
+
def hue_to_rgb(m1, m2, h)
|
|
98
|
+
h += 1 if h < 0
|
|
99
|
+
h -= 1 if h > 1
|
|
100
|
+
return m1 + (m2 - m1) * h * 6 if h * 6 < 1
|
|
101
|
+
return m2 if h * 2 < 1
|
|
102
|
+
return m1 + (m2 - m1) * (2.0/3 - h) * 6 if h * 3 < 2
|
|
103
|
+
return m1
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require 'sass'
|
|
2
|
+
|
|
3
|
+
module Sass::Script::Functions
|
|
4
|
+
module Colors
|
|
5
|
+
extend self
|
|
6
|
+
def rgb_value(color)
|
|
7
|
+
if color.respond_to?(:rgb)
|
|
8
|
+
color.rgb
|
|
9
|
+
else
|
|
10
|
+
color.value
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
# Takes a color object and amount by which to lighten it (0 to 100).
|
|
15
|
+
def lighten(color, amount)
|
|
16
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
17
|
+
hsl.l += amount.value / 100.0
|
|
18
|
+
hsl.to_color
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Takes a color object and percent by which to lighten it (0 to 100).
|
|
22
|
+
def lighten_percent(color, amount)
|
|
23
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
24
|
+
hsl.l += (1 - hsl.l) * (amount.value / 100.0)
|
|
25
|
+
hsl.to_color
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Takes a color object and amount by which to darken it (0 to 100).
|
|
29
|
+
def darken(color, amount)
|
|
30
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
31
|
+
hsl.l -= amount.value / 100.0
|
|
32
|
+
hsl.to_color
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Takes a color object and percent by which to darken it (0 to 100).
|
|
36
|
+
def darken_percent(color, amount)
|
|
37
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
38
|
+
hsl.l *= 1.0 - (amount.value / 100.0)
|
|
39
|
+
hsl.to_color
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Saturate (make a color "richer") a color by the given amount (0 to 100)
|
|
43
|
+
def saturate(color, amount)
|
|
44
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
45
|
+
hsl.s += amount.value / 100.0
|
|
46
|
+
hsl.to_color
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Saturate (make a color "richer") a color by the given percent (0 to 100)
|
|
50
|
+
def saturate_percent(color, amount)
|
|
51
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
52
|
+
hsl.s += (1 - hsl.s) * (amount.value / 100.0)
|
|
53
|
+
hsl.to_color
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Desaturate (make a color "grayer") a color by the given amount (0 to 100)
|
|
57
|
+
def desaturate(color, amount)
|
|
58
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
59
|
+
hsl.s -= amount.value / 100.0
|
|
60
|
+
hsl.to_color
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Desaturate (make a color "grayer") a color by the given percent (0 to 100)
|
|
64
|
+
def desaturate_percent(color, amount)
|
|
65
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
66
|
+
hsl.s *= (1.0 - (amount.value / 100.0))
|
|
67
|
+
hsl.to_color
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Return the hue of a color as a number between 0 and 360
|
|
71
|
+
def hue(color)
|
|
72
|
+
Sass::Script::Number.new(Compass::Colors::HSL.from_color(color).h.round)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Return the saturation of a color as a number between 0 and 100
|
|
76
|
+
def saturation(color)
|
|
77
|
+
Sass::Script::Number.new((Compass::Colors::HSL.from_color(color).s * 100).round)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Return the luminosity of a color as a number between 0 and 100
|
|
81
|
+
def luminosity(color)
|
|
82
|
+
Sass::Script::Number.new((Compass::Colors::HSL.from_color(color).l * 100).round)
|
|
83
|
+
end
|
|
84
|
+
alias lightness luminosity
|
|
85
|
+
|
|
86
|
+
# Mixes two colors by some amount (0 to 100). Defaults to 50.
|
|
87
|
+
def mix(color1, color2, amount = nil)
|
|
88
|
+
percent = amount ? amount.value.round / 100.0 : 0.5
|
|
89
|
+
new_colors = Colors.rgb_value(color1).zip(Colors.rgb_value(color2)).map{|c1, c2| (c1 * percent) + (c2 * (1 - percent))}
|
|
90
|
+
Sass::Script::Color.new(new_colors)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Returns the grayscale equivalent color for the given color
|
|
94
|
+
def grayscale(color)
|
|
95
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
96
|
+
g = (hsl.l * 255).round
|
|
97
|
+
Sass::Script::Color.new([g, g, g])
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# adjust the hue of a color by the given number of degrees.
|
|
101
|
+
def adjust_hue(color, degrees)
|
|
102
|
+
hsl = Compass::Colors::HSL.from_color(color)
|
|
103
|
+
degrees = degrees.value.to_f.round if degrees.is_a?(Sass::Script::Literal)
|
|
104
|
+
hsl.h += degrees
|
|
105
|
+
hsl.to_color
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def complement(color)
|
|
109
|
+
adjust_hue color, 180
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|