Module: Nifty::Utils::ViewHelpers
- Defined in:
- lib/nifty/utils/view_helpers.rb
Instance Method Summary collapse
-
#boolean_tag(bool, tip = nil, options = {}) ⇒ Object
Renders a tick or cross character based on the provided boolean.
-
#display_flash ⇒ Object
Displays the full contents of the ‘flash` hash within an appropriate <div> element.
-
#gravatar(email, options = {}) ⇒ Object
Renders an ‘<img>` containing a link to the gravatar for the given e-mail address.
Instance Method Details
#boolean_tag(bool, tip = nil, options = {}) ⇒ Object
Renders a tick or cross character based on the provided boolean. Additional options can be passed if needed.
-
:true_text- text to display next to a tick -
:false_text- text to display next to a cross
43 44 45 46 47 48 |
# File 'lib/nifty/utils/view_helpers.rb', line 43 def boolean_tag(bool, tip = nil, = {}) true_text, false_text = "", "" true_text = " <b>#{[:true_text]}</b>" if [:true_text] false_text = " <b>#{[:false_text]}</b>" if [:false_text] content_tag :span, (bool ? "<span class='true'>✔#{true_text}</span>" : "<span class='false'>✘#{false_text}</span>").html_safe, :class => "boolean", :title => tip end |
#display_flash ⇒ Object
Displays the full contents of the ‘flash` hash within an appropriate <div> element. The ID of the outputted div will be `flash-alert` where alert is the type of flash.
If there are multiple flashes set, they will all be displayed.
10 11 12 13 14 |
# File 'lib/nifty/utils/view_helpers.rb', line 10 def display_flash flashes = flash.collect do |key,msg| content_tag :div, content_tag(:p, h(msg)), :id => "flash-#{key}" end.join.html_safe end |
#gravatar(email, options = {}) ⇒ Object
Renders an ‘<img>` containing a link to the gravatar for the given e-mail address. Available options as follows:
-
:size: the size in pixels of the outputted gravatar. Defaults to 35. -
:default: the gravatar to fallback to if the user has no gravatar (see gravatar for available options or pass a URL). Defaults to ‘identicon’. -
:rating: the maximum rating to use. Defaults to PG. -
:class: the value for the class attribute for the outputted img tag. Defaults to ‘gravatar’. -
:secure: wherher or not to output an HTTPS version of the gravatar or not. Defaults to the value of ‘request.ssl?`.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nifty/utils/view_helpers.rb', line 27 def gravatar(email, = {}) [:size] ||= 35 [:default] ||= 'identicon' [:rating] ||= 'PG' [:class] ||= 'gravatar' [:secure] ||= request.ssl? host = ([:secure] ? 'https://secure.gravatar.com' : 'http://gravatar.com') path = "/avatar.php?gravatar_id=#{Digest::MD5.hexdigest(email.to_s.downcase)}&rating=#{[:rating]}&size=#{[:size] * 2}&d=#{[:default]}" image_tag([host,path].join, :class => [:class], :width => [:size], :height => [:size]) end |