Sha256: 845639411411c74d274738edfb3c09d7f686b7b09ad3fd33f26b2d60f5dc5ae6

Contents?: true

Size: 1.36 KB

Versions: 28

Compression:

Stored size: 1.36 KB

Contents

module Hyrax
  # Draws a collapsable list widget using the Bootstrap 3 / Collapse.js plugin
  class CollapsableSectionPresenter
    def initialize(view_context:, text:, id:, icon_class:, open:)
      @view_context = view_context
      @text = text
      @id = id
      @icon_class = icon_class
      @open = open
    end

    attr_reader :view_context, :text, :id, :icon_class, :open
    delegate :content_tag, :safe_join, to: :view_context

    def render(&block)
      button_tag + list_tag(&block)
    end

    private

      def button_tag
        content_tag(:a,
                    role: 'button',
                    class: "#{button_class}collapse-toggle",
                    data: { toggle: 'collapse' },
                    href: "##{id}",
                    'aria-expanded' => open,
                    'aria-controls' => id) do
                      safe_join([content_tag(:span, '', class: icon_class, 'aria-hidden' => true),
                                 content_tag(:span, text)], ' ')
                    end
      end

      def list_tag
        content_tag(:ul,
                    class: "collapse #{workflows_class}nav nav-pills nav-stacked",
                    id: id) do
                      yield
                    end
      end

      def button_class
        'collapsed ' unless open
      end

      def workflows_class
        'in ' if open
      end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.9.5 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.9.4 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.9.3 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.9.2 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.9.1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.9.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.8.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.7.2 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.7.1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.7.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.6.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-3.0.0.pre.rc1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-3.0.0.pre.beta3 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.5.1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.5.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-3.0.0.pre.beta2 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.4.1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-3.0.0.pre.beta1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.4.0 app/presenters/hyrax/collapsable_section_presenter.rb