Sha256: 76f799f0f9351785d648c97462d6e212223b2ce397e34927dc8babfced4f9a68

Contents?: true

Size: 1.34 KB

Versions: 29

Compression:

Stored size: 1.34 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),
                                 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

29 entries across 29 versions & 1 rubygems

Version Path
hyrax-1.1.1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.3 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.2.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.1.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.1.0.rc4 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.1.0.rc3 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.1.0.rc2 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.1.0.rc1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-1.1.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.1.0.beta2 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.2 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.1.0.beta1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.0 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.0.rc3 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.0.rc2 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.0.rc1 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-1.0.5 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.0.beta5 app/presenters/hyrax/collapsable_section_presenter.rb
hyrax-2.0.0.beta4 app/presenters/hyrax/collapsable_section_presenter.rb