Module: Compass::Core::SassExtensions::Functions::Constants

Included in:
GradientSupport::LinearGradient, GradientSupport::RadialGradient, Sass::Script::Functions
Defined in:
lib/compass/core/sass_extensions/functions/constants.rb

Constant Summary collapse

POSITIONS =
/top|bottom|left|right|center/

Instance Method Summary collapse

Instance Method Details

#is_position(position) ⇒ Object



3
4
5
# File 'lib/compass/core/sass_extensions/functions/constants.rb', line 3

def is_position(position)
  bool(position.is_a?(Sass::Script::Value::String) && !!(position.value =~ POSITIONS))
end

#is_position_list(position_list) ⇒ Object



6
7
8
# File 'lib/compass/core/sass_extensions/functions/constants.rb', line 6

def is_position_list(position_list)
  bool(position_list.is_a?(Sass::Script::Value::List) && position_list.value.all?{|p| is_position(p).to_bool})
end

#is_url(string) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/compass/core/sass_extensions/functions/constants.rb', line 48

def is_url(string)
  if string.is_a?(Sass::Script::Value::String)
    is_url = !!(string.value =~ /^url\(.*\)$/)
    bool(is_url)
  else
    bool(false)
  end
end

#opposite_position(position) ⇒ Object

returns the opposite position of a side or corner.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/compass/core/sass_extensions/functions/constants.rb', line 10

def opposite_position(position)
  position = unless position.is_a?(Sass::Script::Value::List)
    list(position, :space)
  else
    list(position.value.dup, position.separator)
  end
  position = list(position.value.map do |pos|
    if pos.is_a? Sass::Script::Value::String
      opposite = case pos.value
      when "top" then "bottom"
      when "bottom" then "top"
      when "left" then "right"
      when "right" then "left"
      when "center" then "center"
      else
        Compass::Util.compass_warn("Cannot determine the opposite position of: #{pos}")
        pos.value
      end
      identifier(opposite)
    elsif pos.is_a? Sass::Script::Value::Number
      if pos.numerator_units == ["%"] && pos.denominator_units == []
        number(100-pos.value, "%")
      else
        Compass::Util.compass_warn("Cannot determine the opposite position of: #{pos}")
        pos
      end
    else
      Compass::Util.compass_warn("Cannot determine the opposite position of: #{pos}")
      pos
    end
  end, position.separator)
  if position.value.size == 1
    position.value.first
  else
    position
  end
end