Module: Atech::Helpers
- Defined in:
- lib/atech/helpers.rb
Instance Method Summary collapse
-
#c(*opts) ⇒ Object
Alias ‘c’ to ‘number_to_currency’.
-
#display_flash ⇒ Object
Flash all flash messages which have been stored.
-
#gravatar(email, options = {}) ⇒ Object
Insert a gravatar for a specified e-mail address.
-
#icon_tag(icon, text = '') ⇒ Object
Insert an image tag for an icon from the ‘public/images/icons’ folder.
-
#page_title(text = nil) ⇒ Object
Sets the page title to be passed value or returns the current value if it’s empty.
-
#user_agent_classes ⇒ Object
Return a set of three classes allowing you to determine the user agent of the clients computer.
Instance Method Details
#c(*opts) ⇒ Object
Alias ‘c’ to ‘number_to_currency’
30 31 32 |
# File 'lib/atech/helpers.rb', line 30 def c(*opts) number_to_currency(*opts) end |
#display_flash ⇒ Object
Flash all flash messages which have been stored.
15 16 17 18 19 |
# File 'lib/atech/helpers.rb', line 15 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
Insert a gravatar for a specified e-mail address.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/atech/helpers.rb', line 35 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)}&rating=#{[:rating]}&size=#{[:size]}&d=#{[:default]}" image_tag([host,path].join, :class => [:class], :width => [:size], :height => [:size]) end |
#icon_tag(icon, text = '') ⇒ Object
Insert an image tag for an icon from the ‘public/images/icons’ folder. If passed a symbol it will automatically add ‘.png’ to the end of the name, otherwise you need to pass the full image file name.
24 25 26 27 |
# File 'lib/atech/helpers.rb', line 24 def icon_tag(icon, text = '') extension = (icon.is_a?(Symbol) ? ".png" : '') image_tag "icons/#{icon.to_s}#{extension}", :alt => text, :title => text, :class => "icon #{icon}" end |
#page_title(text = nil) ⇒ Object
Sets the page title to be passed value or returns the current value if it’s empty
58 59 60 |
# File 'lib/atech/helpers.rb', line 58 def page_title(text = nil) text ? (@page_title = text) : @page_title end |
#user_agent_classes ⇒ Object
Return a set of three classes allowing you to determine the user agent of the clients computer. This method can be called as part of the <html> or <body> class. It will return the operating system, the browser’s name and the version number.
51 52 53 54 55 |
# File 'lib/atech/helpers.rb', line 51 def user_agent_classes if defined?(Atech::UserAgent) && request.user_agent.is_a?(Atech::UserAgent) "#{request.user_agent.os} #{request.user_agent.name} v#{request.user_agent.version}" end end |