Top Level Namespace
Defined Under Namespace
Modules: InlineGradient
Constant Summary collapse
- DEFAULT_TYPE =
Sass::Script::String.new "linear"
- DEFAULT_ANGLE =
www.w3.org/TR/css3-images/#linear-gradient-examples to bottom is default
"to bottom"
- DEFAULT_COLOR_STOPS =
["#FFF 0%", "#000 100%"]
- DEFAULT_WIDTH =
Sass::Script::Number.new 100
- DEFAULT_HEIGHT =
Sass::Script::Number.new 100
Instance Method Summary collapse
- #color2hex(color) ⇒ Object
- #distance2px(distance, width) ⇒ Object
- #image2base64(image) ⇒ Object
- #side2angle(side) ⇒ Object
Instance Method Details
#color2hex(color) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/inline-gradient.rb', line 42 def color2hex (color) <<-DOC Color can be: - rgba - rgb - hex Use Sass::Script::Color class DOC color = color.to_s if color.start_with?('rgba') rgba = color.split(",").map { |s| s.to_i } color = Sass::Script::Color.new(rgba[0..2]).with(:alpha => rgba[3]) elsif color.start_with?('rba') rgb = color.split(",").map { |s| s.to_i } color = Sass::Script::Color.new(rgba[0..2]) end color end |
#distance2px(distance, width) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/inline-gradient.rb', line 19 def distance2px (distance, width) distance = distance.to_s if distance.end_with?("%") percents = Sass::Script::Number.new(distance.gsub("%", "").strip) all_persents = Sass::Script::Number.new(100) distance = percents.div(all_persents).times(width) else distance = Sass::Script::Number.new(distance.to_i) end distance end |
#image2base64(image) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/inline-gradient.rb', line 64 def image2base64(image) image.format = "png" begin #online mode client = TinyPNG::Client.new image = client.shrink(image.to_blob) image = File.read(image.to_file) rescue Exception => e #offline mode image = image.to_blob end Base64.encode64(image).gsub("\n","") end |
#side2angle(side) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/inline-gradient.rb', line 31 def side2angle (side) side2angle_object = { "to_top" => 0, "to_right" => 90, "to_bottom" => 180, "to_left" => 270 } side_name = side.to_s.strip.gsub("\s", "_") side2angle_object[side_name] or side.to_i end |