Sha256: 2084b2f791d926da5fb1e0677a485000820e018060b43dcfdeaf1eafa8ed3a43

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Bootstrap
  module ViewHelpers
    module Components
      class Modal < Component
        class Header < Component
          def to_html
            content_tag(:div, class: options[:class]) do
              concat(block.call(self)) if block.present?
              concat title if block.blank?
              concat close_button if dismiss
            end
          end

          def title(title = nil)
            title ||= title_text
            return title unless title_options[:tag]
            content_tag(title_options[:tag], title,
                        class: title_options[:class])
          end

          def close_button
            Button::Close.new(view, {}).to_html
          end

          protected

          attr_reader :title_text, :dismiss

          def title_options
            { tag: :h5, class: 'modal-title' }
          end

          def inject_class_name_to_options
            options[:class] = "modal-header #{options[:class]}"
            options[:class].strip!
          end

          def parse_options(options)
            super
            @title_text = options.delete(:title)
            @dismiss = options.delete(:dismiss)
            inject_class_name_to_options
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bootstrap-view_helpers-0.0.3 lib/bootstrap/view_helpers/components/modal/header.rb