Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
blocks / lib / blocks / layout / row.rb
Size: Mime:
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