color_helpers 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/color_helpers/helpers.rb +26 -0
- data/lib/color_helpers/version.rb +1 -1
- data/lib/color_helpers.rb +1 -6
- metadata +2 -3
- data/lib/color_helpers/action_view/helpers.rb +0 -22
- data/lib/color_helpers/railtie.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97e0b6581f86ddbf23b9b42ed549e35bef32ca24
|
4
|
+
data.tar.gz: a2938e01e6f8a420ee4fd00ecfdfff26286cfd2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3ab42f984f88553b47f8130c948e2f1d30edb93192cbd68e9ff4d9b9e93868d5f9aae0cdda4004fc66e65c2a44916634daa66b227f5f7d21be72e593dc3c448
|
7
|
+
data.tar.gz: 8710fe3f0a98ae311eb2d439c4f172546f018f755a8181d0eb3faa75c2e86b49dce259a8637b56b08790688b7bb7db56b0722e6f7ebdae39f52a211b58935c11
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ColorHelpers
|
2
|
+
module ActionViewExtension
|
3
|
+
|
4
|
+
def darken_color(hex_color, amount=0.4)
|
5
|
+
hex_color = hex_color.gsub('#','')
|
6
|
+
rgb = hex_color.scan(/../).map(&:hex).map{|color| color * amount}.map(&:round)
|
7
|
+
"#%02x%02x%02x" % rgb
|
8
|
+
end
|
9
|
+
|
10
|
+
def lighten_color(hex_color, amount=0.6)
|
11
|
+
hex_color = hex_color.gsub('#','')
|
12
|
+
rgb = hex_color.scan(/../).map(&:hex).map{|color| (color + 255) * amount}.map(&:round)
|
13
|
+
"#%02x%02x%02x" % rgb
|
14
|
+
end
|
15
|
+
|
16
|
+
def contrasting_text_color(hex_color)
|
17
|
+
color = hex_color.gsub('#','')
|
18
|
+
convert_to_brightness_value(color) > 382.5 ? darken_color(color) : lighten_color(color)
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert_to_brightness_value(hex_color)
|
22
|
+
(hex_color.scan(/../).map {|color| color.hex}).sum
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
ActionView::Base.send :include, ColorHelpers::ActionViewExtension
|
data/lib/color_helpers.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Schneider
|
@@ -70,8 +70,7 @@ files:
|
|
70
70
|
- bin/setup
|
71
71
|
- color_helpers.gemspec
|
72
72
|
- lib/color_helpers.rb
|
73
|
-
- lib/color_helpers/
|
74
|
-
- lib/color_helpers/railtie.rb
|
73
|
+
- lib/color_helpers/helpers.rb
|
75
74
|
- lib/color_helpers/version.rb
|
76
75
|
homepage: https://github.com/mschneider85/color_helpers
|
77
76
|
licenses:
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module ColorHelpers::ActionView::Helpers
|
2
|
-
def darken_color(hex_color, amount=0.4)
|
3
|
-
hex_color = hex_color.gsub('#','')
|
4
|
-
rgb = hex_color.scan(/../).map(&:hex).map{|color| color * amount}.map(&:round)
|
5
|
-
"#%02x%02x%02x" % rgb
|
6
|
-
end
|
7
|
-
|
8
|
-
def lighten_color(hex_color, amount=0.6)
|
9
|
-
hex_color = hex_color.gsub('#','')
|
10
|
-
rgb = hex_color.scan(/../).map(&:hex).map{|color| (color + 255) * amount}.map(&:round)
|
11
|
-
"#%02x%02x%02x" % rgb
|
12
|
-
end
|
13
|
-
|
14
|
-
def contrasting_text_color(hex_color)
|
15
|
-
color = hex_color.gsub('#','')
|
16
|
-
convert_to_brightness_value(color) > 382.5 ? darken_color(color) : lighten_color(color)
|
17
|
-
end
|
18
|
-
|
19
|
-
def convert_to_brightness_value(hex_color)
|
20
|
-
(hex_color.scan(/../).map {|color| color.hex}).sum
|
21
|
-
end
|
22
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module ColorHelpers
|
2
|
-
class Railtie > ::Rails::Railtie
|
3
|
-
initializer "color_helpers.configure_view_controller" do |app|
|
4
|
-
ActiveSupport.on_load :action_view do
|
5
|
-
include ColorHelpers::ActionView::Helpers
|
6
|
-
end
|
7
|
-
|
8
|
-
ActiveSupport.on_load :action_controller do
|
9
|
-
include ColorHelpers::ActionController::Filters
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|