Sha256: 6e7fb173bd100609e5e64cfc1f14fa819146ce246720bfe879028105dac93bce

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'helpers'

module BootstrapPanelHelper
	def panel(options={}, &block)
		unless block_given?
			raise 'Missing block'
		end

		panel_options = options.dup
		panel_options[:class] = parse_html_classes_to_arr panel_options[:class]
		panel_options[:class] << 'panel'

		header = panel_options.delete :header
		title = panel_options.delete :title
		footer = panel_options.delete :footer
		context = panel_options.delete :context

		unless %w(primary info success warning danger).include? context.to_s
			context = :default
		end

		panel_options[:class] << "panel-#{context}"

		content = []
		content << panel_header(header || title)
		content << panel_body(&block)
		content << panel_footer(footer)

		content_tag :div, content.join("\n").html_safe, panel_options
	end

	private
	def panel_body(&block)
		content = capture &block

		content_tag :div, content, class: 'panel-body'
	end

	def panel_header(header)
		return unless header

		if header.is_a? Hash
			level = header[:level]

			unless (1..6).include? level
				level = 1
			end

			content = content_tag "h#{level}", header[:content], class: 'panel-title'
		else
			content = header
		end

		content_tag :div, content, class: 'panel-heading'
	end

	def panel_footer(content)
		if content
			content_tag :div, content, class: 'panel-footer'
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twitter-bootstrap-for-rails-1.3.4 app/helpers/bootstrap_panel_helper.rb
twitter-bootstrap-for-rails-1.3.3 app/helpers/bootstrap_panel_helper.rb