Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up sass integration

  • Loading branch information...
commit 646fed364b5a171e11d07d62b6faa888e047b464 1 parent db6289f
@joshuaclayton authored
Showing with 17 additions and 10 deletions.
  1. +1 −1  Gemfile.lock
  2. +16 −9 lib/palette/color_scheme.rb
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- palette (0.0.3)
+ palette (0.0.4)
sass (= 3.1.0.alpha.23)
GEM
View
25 lib/palette/color_scheme.rb
@@ -33,9 +33,7 @@ def method_missing(name, *args)
%w(darken lighten saturate desaturate).each do |sass_method|
class_eval <<-EOM
def #{sass_method}(hex, number)
- rgb = Palette::Color.hex_to_decimal(Palette::Color.parse(hex))
- sass_context.#{sass_method}(Sass::Script::Color.new(rgb),
- Sass::Script::Number.new(number)).tap{|c| c.options = {}}.inspect.gsub(/#/, "")
+ sass_evaluator(:#{sass_method}, hex_to_sass_color(hex), Sass::Script::Number.new(number))
end
EOM
end
@@ -43,16 +41,11 @@ def #{sass_method}(hex, number)
%w(grayscale complement invert).each do |sass_method|
class_eval <<-EOM
def #{sass_method}(hex)
- rgb = Palette::Color.hex_to_decimal(Palette::Color.parse(hex))
- sass_context.#{sass_method}(Sass::Script::Color.new(rgb)).tap{|c| c.options = {}}.inspect.gsub(/#/, "")
+ sass_evaluator(:#{sass_method}, hex_to_sass_color(hex))
end
EOM
end
- def sass_context
- @context ||= Sass::Script::Functions::EvaluationContext.new({})
- end
-
def String(*args)
@rules ||= []
@rules << Palette::Rule.new("String", *args)
@@ -124,5 +117,19 @@ def self.run(name, block)
instance.instance_eval(&block)
instance.to_s
end
+
+ private
+
+ def sass_evaluator(method, *arguments)
+ sass_context.send(method, *arguments).tap {|c| c.options = {}}.inspect.gsub(/#/, "")
+ end
+
+ def hex_to_sass_color(hex)
+ Sass::Script::Color.new(Palette::Color.hex_to_decimal(Palette::Color.parse(hex)))
+ end
+
+ def sass_context
+ @context ||= Sass::Script::Functions::EvaluationContext.new({})
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.