Module: Compass::Magick::Functions::Types

Included in:
Compass::Magick::Functions
Defined in:
lib/magick/functions/types.rb

Overview

Methods for creating new Types.

Instance Method Summary collapse

Instance Method Details

#magick_color_stop(offset, color) ⇒ Compass::Magick::Types::ColorStop

Creates a new Types::ColorStop instance.

Parameters:

  • offset (Sass::Script::Number)

    The color stop offset, 0-100.

  • color (Sass::Script::Color)

    The color at the offset.

Returns:

  • (Compass::Magick::Types::ColorStop)

    A type that is used when constructing gradients to control color stops.



20
21
22
# File 'lib/magick/functions/types.rb', line 20

def magick_color_stop(offset, color)
  Compass::Magick::Types::Gradients::ColorStop.new(offset, color)
end

#magick_linear_gradient(angle, stops) ⇒ Compass::Magick::Types::Gradients::Linear #magick_linear_gradient(stops) ⇒ Compass::Magick::Types::Gradients::Linear

Creates a new Types::Gradients::Linear instance.

Overloads:

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/magick/functions/types.rb', line 37

def magick_linear_gradient(*args)
  angle   = args.shift if args[0].kind_of?(Sass::Script::Number)
  angle ||= Sass::Script::Number.new(90)
  stops   = []
  last_offset = 0
  args.each_with_index do |stop, index|
    if stop.kind_of?(Sass::Script::Color)
      if index > 0
        if index == args.length - 1
          offset = 100
        else
          next_index  = 0
          next_offset = nil
          args.slice(index, args.length).each do |next_stop|
            next_index = next_index + 1
            if next_stop.kind_of?(Compass::Magick::Types::Gradients::ColorStop)
              next_offset = next_stop.offset.value
              break
            end
          end
          next_offset ||= 100
          offset = last_offset + (next_offset - last_offset) / next_index
        end
      else
        offset = 0
      end
      stops.push(Compass::Magick::Types::Gradients::ColorStop.new(Sass::Script::Number.new(offset), stop))
      last_offset = offset
    elsif stop.kind_of?(Sass::Script::List)
      stops.push(Compass::Magick::Types::Gradients::ColorStop.new(stop.value[1], stop.value[0]))
      last_offset = stop.value[1].value
    else
      stops.push(stop)
      last_offset = stop.offset.value if stop.respond_to?(:offset)
    end
  end
  Compass::Magick::Types::Gradients::Linear.new(angle, stops)
end

#magick_solid(color) ⇒ Compass::Magick::Types::Solid

Creates a new Types::Solid instance.

Parameters:

  • color (Sass::Script::Color)

    The solid background color.

Returns:



10
11
12
# File 'lib/magick/functions/types.rb', line 10

def magick_solid(color)
  Compass::Magick::Types::Solid.new(color)
end