Layout multiple inheritance works with operators

The case of using relative operators and multiple inheritance is handled now.

Fixes #244
This commit is contained in:
Andy Meneely
2018-07-31 15:07:33 -04:00
parent 3d1f1ff989
commit 248eb2fb91
7 changed files with 108 additions and 14 deletions
+24 -12
View File
@@ -49,25 +49,37 @@ module Squib
h = {}
parent_keys.each do |parent_key|
from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
if child_val.to_s.strip.start_with?('+=')
add_parent_child(parent_val, child_val)
elsif child_val.to_s.strip.start_with?('-=')
sub_parent_child(parent_val, child_val)
elsif child_val.to_s.strip.start_with?('*=')
mul_parent_child(parent_val, child_val)
elsif child_val.to_s.strip.start_with?('/=')
div_parent_child(parent_val, child_val)
else
child_val # child overrides parent when merging, no +=
end
handle_relative_operators(parent_val, child_val)
end
h = h.merge(from_extends) do |key, older_sibling, younger_sibling|
younger_sibling # when two siblings have the same entry, the "younger" (lower one) overrides
# In general, go with the younger sibling.
# UNLESS that younger sibling had a relative operator, in which use the
# (already computed) relative operator applied, which lands in older_sibling
# See bug 244.
sibling = younger_sibling
%w(+= -= *= /=).each do |op|
sibling = older_sibling if younger_sibling.to_s.strip.start_with? op
end
sibling
end
end
return h
end
def handle_relative_operators(parent_val, child_val)
if child_val.to_s.strip.start_with?('+=')
add_parent_child(parent_val, child_val)
elsif child_val.to_s.strip.start_with?('-=')
sub_parent_child(parent_val, child_val)
elsif child_val.to_s.strip.start_with?('*=')
mul_parent_child(parent_val, child_val)
elsif child_val.to_s.strip.start_with?('/=')
div_parent_child(parent_val, child_val)
else
child_val # child overrides parent when merging, no +=
end
end
def add_parent_child(parent, child)
parent_pixels = Args::UnitConversion.parse(parent, @dpi).to_f
child_pixels = Args::UnitConversion.parse(child.sub('+=', ''), @dpi).to_f