Sha256: eebc64d89df4ce2c571780722787782c682dfad0c0dd2b946eef590ed7b3996f

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

require_relative 'lists/line'
require_relative 'lists/separator'
require_relative 'lists/header'
require_relative 'mixins/content'
require_relative 'mixins/append'
require_relative 'mixins/attaches'

module Voom
  module Presenters
    module DSL
      module Components
        class List < Base
          include Mixins::Content
          include Mixins::Append
          include Mixins::Attaches
          
          attr_reader :lines, :lines_only, :selectable, :total_lines
          attr_accessor :components
          
          def initialize(**attribs_, &block)
            super(type: :list, **attribs_, &block)
            @lines_only = attribs.delete(:lines_only) { false }
            @selectable = attribs.delete(:selectable) { false }
            @lines = []
            @components = []
            @total_lines = attribs.delete(:total_lines) || 0
            add_select_control!( attribs.fetch(:select_control_label) { 'Select All' } )
            expand!
          end

          def add_select_control!(text)
            return unless @selectable && !@lines_only
            @lines << Lists::Header.new(parent: self,
                                        context: context,
                                        total_lines: @total_lines,
                                        checkbox: {text: text})
          end

          def line(text=nil, **attribs, &block)
            @lines << Lists::Line.new(parent:self, context: context, text: text, selectable: selectable, **attribs, &block)
          end

          def separator(**attribs, &block)
            @lines << Lists::Separator.new(parent:self, context: context, **attribs, &block)
          end
        end
      end
    end
  end
end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
voom-presenters-0.1.13 lib/voom/presenters/dsl/components/list.rb
voom-presenters-0.1.12 lib/voom/presenters/dsl/components/list.rb
voom-presenters-0.1.11 lib/voom/presenters/dsl/components/list.rb
voom-presenters-0.1.10 lib/voom/presenters/dsl/components/list.rb