Module: CSSPool::CSS

Defined in:
lib/css_inliner/csspool.rb

Defined Under Namespace

Classes: Declaration

Class Method Summary collapse

Class Method Details

.merge_declarations(base, other) ⇒ Aarray<Declaration>

Merge declarations in each argument

Parameters:

Returns:

  • (Aarray<Declaration>)

    merged array of declarations



32
33
34
# File 'lib/css_inliner/csspool.rb', line 32

def merge_declarations(base, other)
  update_declarations base.dup, other
end

.update_declarations(base, other) ⇒ Array<Declaration>

Update declarations in base with ones in other

Parameters:

  • base (Array<Declaration>)

    updated array of declarations

  • other (Array<Declaration>)

    array of declarations

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/css_inliner/csspool.rb', line 10

def update_declarations(base, other)
  other_decls = other.map {|decl| decl.expand_border.map(&:expand_dimension)}.flatten
  other_decls.each do |other_decl|
    base_decls = base.find_all {|base_decl| base_decl.property == other_decl.property}
    base_decls = base_decls.map {|decl| decl.expand_border.map(&:expand_dimension)}.flatten
    if base_decls.empty?
      base << other_decl
    else
      base_decl = base_decls.shift
      base_decls.each do |decl|
        base_decl.update decl
      end
      base_decl.update other_decl
    end
  end
  base
end