Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added badge helper.

Cleaned up inline_label.
  • Loading branch information...
commit 61268118b4c3032f1f9c93da4282087b62a5deec 1 parent 6b24844
@joshuapinter authored
Showing with 32 additions and 6 deletions.
  1. +32 −6 bootstrap_helper.rb
View
38 bootstrap_helper.rb
@@ -95,7 +95,7 @@ def alert msg, classes = nil
# Generates a label a la Bootstrap.
#
# @param [String] text Label text.
- # @param [Hash] options Class options and
+ # @param [Hash] options Class options and label style.
#
# @option options [String, Symbol] label_style (nil) Label style from Bootstrap. Possible choices
# are: `:success`, `:warning`, `:important`, `:info`, `inverse`
@@ -104,14 +104,40 @@ def alert msg, classes = nil
# @todo Tests.
#
def inline_label text, options = {}
- klass = options[:class].split
- klass << 'label'
+ klass = ['label']
+ klass << options[:class].try(:split)
+
- label_style = options[:label_style]
- label_style.insert( 0, 'label-' ) unless label_style.starts_with?( 'label-' )
+ label_style = options[:label_style].to_s
+ label_style.insert(0, 'label-') unless label_style.blank? or label_style.starts_with?('label-')
klass << label_style
- content_tag :div, text, class: klass.compact.join(' ')
+ content_tag :span, text, class: klass.compact.join(' ')
+ end
+
+ # Generates a badge a la Bootstrap.
+ #
+ # @param [String] text Badge text.
+ # @param [Hash] options Class options and badge style.
+ #
+ # @option options [String, Symbol] badge_style (nil) Badge style from Bootstrap. Possible choices
+ # are: `:success`, `:warning`, `:important`, `:info`, `inverse`
+ #
+ # @todo Allow any html_options for options.
+ # @todo Tests.
+ # @todo DRY this and #inline_label up.
+ #
+ # @see #inline_label
+ #
+ def badge text, options = {}
+ klass = ['badge']
+ klass << options[:class].try(:split)
+
+ badge_style = options[:badge_style].to_s
+ badge_style.insert(0, 'badge-') unless badge_style.blank? or badge_style.starts_with?('badge-')
+ klass << badge_style
+
+ content_tag :span, text, class: klass.compact.join(' ')
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.