Class: CSSPool::CSS::Declaration

Inherits:
Object
  • Object
show all
Defined in:
lib/css_inliner/csspool.rb

Defined Under Namespace

Classes: InvalidExpressionCountError, InvalidExpressionError

Constant Summary collapse

COLOR_NAMES =
%w[aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen]
BORDER_STYLES =
%w[none hidden solid double groove ridge inset outset dashed dotted]
BORDER_WIDTH_KEYWORDS =
%w[thin medium thick]
BORDER_COLOR_KEYWORDS =
%w[transparent]
DIMENSIONS =
%w[top right bottom left]
PROPERTY_EXPANSION =
{}
EXPANSION_INDICES =
{
  1 => [0, 0, 0, 0],
  2 => [0, 1, 0, 1],
  3 => [0, 1, 2, 1],
  4 => [0, 1, 2, 3]
}

Instance Method Summary collapse

Instance Method Details

#expand_borderArray<Declaration>

TODO:

consider transparent and so on

Returns array of declaration expanded to style, width and color.

Returns:

  • (Array<Declaration>)

    array of declaration expanded to style, width and color

Raises:



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/css_inliner/csspool.rb', line 85

def expand_border
  expanded_properties = PROPERTY_EXPANSION[property]
  return [self] unless expanded_properties
  raise InvalidExpressionCountError, "has #{expressions.length} expressions" if expressions.length > expanded_properties.length

  decls = []
  expanded_properties.each do |prop|
    expressions.each do |exp|
      if prop.end_with? find_property(exp)
        decls << Declaration.new(prop, [exp], important, rule_set)
      end
    end
  end

  decls
end

#expand_dimensionArray<Declaration>

Returns array of declaration indicating four dimensions.

Returns:

  • (Array<Declaration>)

    array of declaration indicating four dimensions

Raises:



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/css_inliner/csspool.rb', line 103

def expand_dimension
  expanded_properties = PROPERTY_EXPANSION[property]

  return [self] unless expanded_properties

  expansion_map = EXPANSION_INDICES[expressions.length]
  raise InvalidExpressionCountError, "has #{expressions.length} expressions" unless expansion_map

  expanded_properties.map.with_index {|prop, i|
    expression = expressions[expansion_map[i]]
    Declaration.new(prop, [expression], important, rule_set)
  }
end

#merge(other) ⇒ Declaration

Returns merged declaration.

Parameters:

Returns:



79
80
81
# File 'lib/css_inliner/csspool.rb', line 79

def merge(other)
  dup.update other
end

#update(other) ⇒ Declaration Also known as: merge!

Returns self.

Parameters:

Returns:

Raises:

  • (ArgumentError)


70
71
72
73
74
# File 'lib/css_inliner/csspool.rb', line 70

def update(other)
  raise ArgumentError, 'different property' unless property == other.property
  self.expressions = other.expressions if !important? or other.important?
  self
end