Sha256: 046c3ff919389b51b9dec475be45e74d74b84e306e810cf624c3798be646a309

Contents?: true

Size: 1.9 KB

Versions: 57

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module Olivander
  module Components
    class TablePortletComponent < ViewComponent::Base
      renders_one :header_tools
      renders_one :footer_buttons

      def initialize(collection, *args)
        super
        options = args.extract_options!
        @collection = collection
        @builder = options[:builder]
        @title = options[:title] || ''
        @card_type = options[:card_type] || 'card-default'
        @background = options[:background]
        @header_background = options[:header_background]
        @turbo_frame = options[:turbo_frame]
        @max_height = options[:max_height]
        @headers = options[:headers].nil? ? true : options[:headers]
        @id = options[:id]
        @card_data = options[:card_data]
        @turbo_frame_data = options[:turbo_frame_data]
      end

      class TableComponent < ViewComponent::Base
        with_collection_parameter :item
        delegate :can?, :cannot?, to: :helpers
        delegate :user_image_path, to: :helpers

        def initialize(item:, item_iteration:, builder:, headers:)
          super
          @item = item
          @item_iteration = item_iteration
          @builder = builder
          @headers = headers
        end
      end

      class Builder
        attr_accessor :field_blocks, :header_tools, :footer_buttons

        def initialize(collection, &block)
          self.field_blocks = []
          block.call(self) if block_given?
        end

        def field(key, alignment = 'text-left', &block)
          unless block_given?
            block = Proc.new{ |x| x.send(key).to_s.html_safe }
          end
          field_blocks << OpenStruct.new(key: key, alignment: alignment, block: block)
        end

        def with_header_tools(&block)
          self.header_tools = block
        end

        def with_footer_buttons(&block)
          self.footer_buttons = block
        end
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
five-two-nw-olivander-0.2.0.40 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.39 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.38 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.37 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.36 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.35 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.34 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.33 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.32 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.31 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.30 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.29 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.28 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.27 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.26 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.25 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.24 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.23 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.22 app/components/olivander/components/table_portlet_component.rb
five-two-nw-olivander-0.2.0.19 app/components/olivander/components/table_portlet_component.rb