Module: Tenon::ApplicationHelper
- Defined in:
- app/helpers/tenon/application_helper.rb
Instance Method Summary collapse
-
#first_image(obj, options = {}) ⇒ Object
eg.
- #flash_messages ⇒ Object
-
#gravatar_for(object) ⇒ Object
now uses github.com/mdeering/gravatar_image_tag.
- #html(options = {}, &blk) ⇒ Object
- #menu_item(title, link, options = {}) ⇒ Object
- #route_exist?(thing) ⇒ Boolean
- #seo_meta_tags ⇒ Object
- #table_row(*args) ⇒ Object
Instance Method Details
#first_image(obj, options = {}) ⇒ Object
eg. first_image(@product)
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/tenon/application_helper.rb', line 54 def first_image(obj, = {}) opts = { collection: :images, method: :image, style: :thumbnail, default: image_path('noimage.jpg') }.merge(.symbolize_keys!) image = obj.send(opts[:collection]).first image ? image.send(opts[:method]).url(opts[:style]) : opts[:default] end |
#flash_messages ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/tenon/application_helper.rb', line 3 def = [] %w(notice alert warning error).each do |msg| unless flash[msg.to_sym].blank? content = content_tag(:p, flash[msg.to_sym]) content += link_to fa_icon('times'), '#', id: 'flash-dismiss' << content_tag(:div, content, class: "flash flash-#{msg}") end end .join('').html_safe end |
#gravatar_for(object) ⇒ Object
25 26 27 |
# File 'app/helpers/tenon/application_helper.rb', line 25 def gravatar_for(object) gravatar_image_tag(object.email) end |
#html(options = {}, &blk) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/tenon/application_helper.rb', line 66 def html( = {}, &blk) .recursive_symbolize_keys! open = h5bp_opening_tag([:ie_versions]) body = capture_haml(&blk) close = '</html>'.html_safe open + body + close end |
#menu_item(title, link, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/helpers/tenon/application_helper.rb', line 15 def (title, link, = {}) klass = '' # set the link class to active if it matches the current link or any of the alternate supplied links [:alt_links].each { |a| klass = request.fullpath.match(a) ? 'active' : '' unless klass == 'active' } if [:alt_links].is_a?(Array) klass = 'active' if link == request.fullpath klass += " #{[:class]}" unless [:class].blank? link_to(title, link, class: klass) end |
#route_exist?(thing) ⇒ Boolean
76 77 78 79 80 |
# File 'app/helpers/tenon/application_helper.rb', line 76 def route_exist?(thing) main_app.polymorphic_path(thing) rescue NoMethodError false end |
#seo_meta_tags ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/tenon/application_helper.rb', line 39 def obj = instance_variable_get("@#{params[:controller].singularize}") = [] if obj if obj.respond_to?(:seo_keywords) && !obj.seo_keywords.blank? << tag(:meta, name: 'keywords', content: obj.seo_keywords) end if obj.respond_to?(:seo_description) && !obj.seo_description.blank? << tag(:meta, name: 'description', content: obj.seo_description) end end .join end |
#table_row(*args) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/tenon/application_helper.rb', line 29 def table_row(*args) html = '<tr>' args.each_with_index do |cell, i| html += "<td class='cell-#{i + 1}'>#{cell}</td>" end html += '</tr>\n' html.html_safe end |