Repository URL to install this package:
Version:
0.5.0 ▾
|
module Blocks
module Layout
class Row
attr_reader :blocks
def initialize(blocks = [])
@blocks = blocks
end
def add_block(block)
return false unless can_add_block?(block)
@blocks.append(block)
true
end
def can_add_block?(block)
return false if totally_full?
case block.arrangement
when "full"
empty?
when "half"
empty? || has_one_half_block?
when /float.*/
empty? || has_full_width_block?
else
false
end
end
def primary_blocks
if has_full_width_block?
[blocks.detect(&:full?)]
else
blocks
end
end
def secondary_blocks
if has_full_width_block?
floated_blocks
else
[]
end
end
def floated_blocks
blocks.select(&:float?)
end
def empty?
blocks.empty?
end
def totally_full?
has_two_halves?
end
def has_floats?
blocks.any?(&:float?)
end
def has_full_width_block?
blocks.any?(&:full?)
end
def has_one_half_block?
blocks.count == 1 && blocks.first.half?
end
def has_two_halves?
blocks.count == 2 && blocks.all?(&:half?)
end
end
end
end