columns_from

in lib/primer/view_components/linters/two_column_layout_migration_counter.rb [131:151]


      def columns_from(tag_tree)
        tag_tree[:children].each_with_object([]) do |tag_data, tags_memo|
          next unless tag_data.is_a?(Hash)
          next unless tag_data[:tag].name == "div"

          classes = classes_from(tag_data[:tag])
          widths = Breakpoints.new

          classes.each do |cls|
            match = cls.match(/\Acol(?:-(xl|lg|md|sm))?-(\d{1,2})(?:-max)?\z/)
            next unless match

            breakpoint, width = match.captures
            breakpoint ||= :all
            widths.set(breakpoint.to_sym, width.to_i)
          end

          tags_memo << Column.new(widths, tag_data)
        end
      end