Module: BootstrapBadgeHelper

Defined in:
app/helpers/bootstrap_badge_helper.rb

Overview

RAILS BOOTSTRAP ENGINE

Bootstrap Badges twitter.github.com/bootstrap/components.html#labels-badges

Copyright 2012-2013 Luiz Eduardo de Oliveira Fonseca, Agência Orangeweb Licensed under The MIT License opensource.org/licenses/MIT

Instance Method Summary collapse

Instance Method Details

#badge_default(value, show_if_nil = false) ⇒ Object

Generates default badge markup

<span class=“badge badge-default”>Text</span>



45
46
47
# File 'app/helpers/bootstrap_badge_helper.rb', line 45

def badge_default value, show_if_nil = false
	bootstrap_badge value, :default, show_if_nil
end

#badge_important(value, show_if_nil = false) ⇒ Object

Generates important badge markup

<span class=“badge badge-important”>Text</span>



82
83
84
# File 'app/helpers/bootstrap_badge_helper.rb', line 82

def badge_important value, show_if_nil = false
  	bootstrap_badge value, :important, show_if_nil
end

#badge_info(value, show_if_nil = false) ⇒ Object

Generates info badge markup

<span class=“badge badge-info”>Text</span>



94
95
96
# File 'app/helpers/bootstrap_badge_helper.rb', line 94

def badge_info value, show_if_nil = false
	bootstrap_badge value, :info, show_if_nil
end

#badge_inverse(value, show_if_nil = false) ⇒ Object

Generates inverse badge markup

<span class=“badge badge-inverse”>Text</span>



106
107
108
# File 'app/helpers/bootstrap_badge_helper.rb', line 106

def badge_inverse value, show_if_nil = false
	bootstrap_badge value, :inverse, show_if_nil
end

#badge_success(value, show_if_nil = false) ⇒ Object

Generates success badge markup

<span class=“badge badge-success”>Text</span>



58
59
60
# File 'app/helpers/bootstrap_badge_helper.rb', line 58

def badge_success value, show_if_nil = false
  	bootstrap_badge value, :success, show_if_nil
end

#badge_warning(value, show_if_nil = false) ⇒ Object

Generates warning badge markup

<span class=“badge badge-warning”>Text</span>



70
71
72
# File 'app/helpers/bootstrap_badge_helper.rb', line 70

def badge_warning value, show_if_nil = false
  	bootstrap_badge value, :warning, show_if_nil
end

#bootstrap_badge(value, type = :default, show_if_nil = false) ⇒ Object

<span class=“badge badge-default”>Text</span>



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/bootstrap_badge_helper.rb', line 23

def bootstrap_badge(value, type = :default, show_if_nil = false)
	
		out = ( :span, value, :class => "badge badge-#{type.to_s}")
		
		if value.nil? then
			if (show_if_nil == false) then
out = ""
			end
		end
	
	raw out
end

#percent_badge(val, opts = {}) ⇒ Object

<span class=“badge badge-type”>0%</span>



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'app/helpers/bootstrap_badge_helper.rb', line 118

def percent_badge(val, opts={})
 	
  	show_sign = false
  	show_sign = opts[:sign] unless opts[:sign].nil? 
 	
	  	if show_sign then
  			out_text = "#{val.to_s}%"
  		else
  			out_text = val.to_s
  		end
 	
  	case val
  		when 0..29
  			type = :danger
  		when 30..59
  			type = :warning
  		when 60..99
  			type = :info
  		when 100
  			type = :success			  
	end #case val
 	
	bootstrap_badge(out_text, type)
end