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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad865b1c0b766f541c1d1388b2c0947c95936a44
4
- data.tar.gz: 519a73fdf34fe652f4175d0e07a837764f51ffe2
3
+ metadata.gz: 97e0b6581f86ddbf23b9b42ed549e35bef32ca24
4
+ data.tar.gz: a2938e01e6f8a420ee4fd00ecfdfff26286cfd2b
5
5
  SHA512:
6
- metadata.gz: 214b2ecda1f9d5aa5cbbf966302ed988f8c2a7ba484a3dbeaa35eae28b577cee6a8f1ee6794d8fc5b6cf542b77170075883f7917aa51ee3d6dad7b8e056f1d1b
7
- data.tar.gz: 44657a28a71d2d26ae25b3b274694d4f3d73403ddc82c4ae46518709516e6845f41abf84d915dd6301effed5bf14c8e32def8d716aa6c79c1b470c1ead663ad3
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
@@ -1,3 +1,3 @@
1
1
  module ColorHelpers
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/color_helpers.rb CHANGED
@@ -1,7 +1,2 @@
1
1
  require 'color_helpers/version'
2
- require 'color_helpers/action_controller/filters'
3
- require 'color_helpers/action_view/helpers'
4
- require 'color_helpers/railtie' if defined?(Rails)
5
-
6
- module ColorHelpers
7
- end
2
+ require 'color_helpers/helpers'
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.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/action_view/helpers.rb
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