Module: Sass::Extras::SvgDataUrls

Defined in:
lib/sass/extras/svg_data_urls.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
# File 'lib/sass/extras/svg_data_urls.rb', line 7

def self.included(base)
  base.declare :circle_image_data_url, [:color, :radius]
  base.declare :linear_gradient_image_data_url, [:color, :height]
  base.declare :radial_gradient_image_data_url, [:color, :height]
end

Instance Method Details

#circle_image_data_url(color = Sass::Script::Color.new([0, 0, 0]), radius = Sass::Script::Number.new(10)) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/sass/extras/svg_data_urls.rb', line 13

def circle_image_data_url(color = Sass::Script::Color.new([0, 0, 0]), radius = Sass::Script::Number.new(10))
  assert_type color, :Color
  assert_type radius, :Number
  svg_data_url(<<-SVG)
    <svg xmlns="http://www.w3.org/2000/svg">
      <circle cx="#{radius}" cy="#{radius}" r="#{radius}" fill="#{svg_color(color)}"/>
    </svg>
  SVG
end

#linear_gradient_image_data_url(color = Sass::Script::Color.new([255, 255, 255]), height = Sass::Script::Number.new(100, ['%'])) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sass/extras/svg_data_urls.rb', line 39

def linear_gradient_image_data_url(color = Sass::Script::Color.new([255, 255, 255]), height = Sass::Script::Number.new(100, ['%']))
  assert_type color, :Color
  assert_type height, :Number
  svg_data_url(<<-SVG)
    <svg xmlns="http://www.w3.org/2000/svg">
      <defs>
        <linearGradient id="gradient" x1="0" x2="0" y1="0" y2="100%">
          <stop offset="25%" stop-color="#{svg_color(color)}" stop-opacity="1"/>
          <stop offset="100%" stop-color="#{svg_color(color)}" stop-opacity="0"/>
        </linearGradient>
      </defs>
      <rect width="100%" height="#{height}" fill="url(#gradient)"></rect>
    </svg>
  SVG
end

#radial_gradient_image_data_url(color = Sass::Script::Color.new([0, 0, 0]), height = Sass::Script::Number.new(5)) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sass/extras/svg_data_urls.rb', line 23

def radial_gradient_image_data_url(color = Sass::Script::Color.new([0, 0, 0]), height = Sass::Script::Number.new(5))
  assert_type color, :Color
  assert_type height, :Number
  svg_data_url(<<-SVG)
    <svg xmlns="http://www.w3.org/2000/svg">
      <defs>
        <radialGradient id="gradient">
          <stop offset="50%" stop-color="#{svg_color(color)}" stop-opacity="0.2"/>
          <stop offset="100%" stop-color="#{svg_color(color)}" stop-opacity="0"/>
        </radialGradient>
      </defs>
      <rect width="100%" height="#{Sass::Script::Number.new(2).times(height)}" y="-#{height}" fill="url(#gradient)"></rect>
    </svg>
  SVG
end