Module: AspectGlobalHelper
- Defined in:
- app/helpers/aspect_global_helper.rb
Overview
Copyright © 2010, Diaspora Inc. This file is
licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
Instance Method Summary (collapse)
- - (Object) aspect_badge(aspect, opts = {})
- - (Object) aspect_badges(aspects, opts = {})
- - (Object) aspect_dropdown_list_item(aspect, contact, person)
- - (Object) aspect_li(aspect, opts = {})
- - (Object) aspect_links(aspects, opts = {})
- - (Object) aspect_or_all_path(aspect)
- - (Object) aspects_with_post(aspects, post)
- - (Object) aspects_without_post(aspects, post)
- - (Boolean) current_aspect?(aspect)
- - (Object) link_for_aspect(aspect, opts = {})
Instance Method Details
- (Object) aspect_badge(aspect, opts = {})
26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/aspect_global_helper.rb', line 26 def aspect_badge(aspect, opts={}) str = "<span class='aspect_badge single'>" link = opts.delete(:link) if !link str << link_to(aspect.name, "#", 'data-guid' => aspect.id, :class => 'hard_aspect_link').html_safe else str << link_for_aspect(aspect).html_safe end str << "</span>" end |
- (Object) aspect_badges(aspects, opts = {})
18 19 20 21 22 23 24 |
# File 'app/helpers/aspect_global_helper.rb', line 18 def aspect_badges(aspects, opts={}) str = '' aspects.each do |aspect| str << aspect_badge(aspect, opts) end str.html_safe end |
- (Object) aspect_dropdown_list_item(aspect, contact, person)
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/aspect_global_helper.rb', line 85 def aspect_dropdown_list_item(aspect, contact, person) checked = (contact.persisted? && contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id}) klass = checked ? "selected" : "" hidden = !checked ? "hidden" : "" str = "<li data-aspect_id=#{aspect.id} class='#{klass}'>" #str << "<input #{checked} id=\"in_aspect\" name=\"in_aspect\" type=\"checkbox\" value=\"in_aspect\" />" str << "<img src='/images/icons/check_yes_ok.png' width=18 height=18 class='check #{hidden}'/>" str << "<img src='/images/icons/check_yes_ok_white.png' width=18 height=18 class='checkWhite'/>" str << aspect.name str << "<div class=\"hidden\">" str << (aspect, contact, person) str << "</div>" str << "</li>" str.html_safe end |
- (Object) aspect_li(aspect, opts = {})
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/aspect_global_helper.rb', line 47 def aspect_li(aspect, opts={}) param_string = "" if opts.size > 0 param_string << '?' opts.each_pair do |k, v| param_string << "#{k}=#{v}" end end "<li> <a href='/aspects/#{aspect.id}#{param_string}'> #{aspect.name} </a> </li>".html_safe end |
- (Object) aspect_links(aspects, opts = {})
37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/aspect_global_helper.rb', line 37 def aspect_links(aspects, opts={}) str = "" aspects.each do |aspect| str << '<li>' str << link_for_aspect(aspect, :params => opts, 'data-guid' => aspect.id, :class => 'hard_aspect_link').html_safe str << '</li>' end str.html_safe end |
- (Object) aspect_or_all_path(aspect)
77 78 79 80 81 82 83 |
# File 'app/helpers/aspect_global_helper.rb', line 77 def aspect_or_all_path(aspect) if @aspect.is_a? Aspect aspect_path @aspect else aspects_path end end |
- (Object) aspects_with_post(aspects, post)
6 7 8 9 10 |
# File 'app/helpers/aspect_global_helper.rb', line 6 def aspects_with_post(aspects, post) aspects.select do |aspect| AspectVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) end end |
- (Object) aspects_without_post(aspects, post)
12 13 14 15 16 |
# File 'app/helpers/aspect_global_helper.rb', line 12 def aspects_without_post(aspects, post) aspects.reject do |aspect| AspectVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) end end |
- (Boolean) current_aspect?(aspect)
73 74 75 |
# File 'app/helpers/aspect_global_helper.rb', line 73 def current_aspect?(aspect) !@aspect.nil? && !@aspect.instance_of?(Symbol) && @aspect.id == aspect.id end |
- (Object) link_for_aspect(aspect, opts = {})
62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/aspect_global_helper.rb', line 62 def link_for_aspect(aspect, opts={}) opts[:params] ||= {} params ||= {} opts[:params] = opts[:params].merge("a_ids[]" => aspect.id, :created_at => params[:created_at]) opts[:class] ||= "" opts[:class] << " hard_aspect_link" opts['data-guid'] = aspect.id link_to aspect.name, aspects_path( opts[:params] ), opts end |