Module: Droom::DroomHelper
- Defined in:
- app/helpers/droom/droom_helper.rb
Instance Method Summary collapse
- #action_menu(thing, locals = {}) ⇒ Object
- #action_menulink(thing, html_options = {}) ⇒ Object
- #admin? ⇒ Boolean
- #allowed?(permission_code) ⇒ Boolean
-
#cloud(these, threshold = 0, biggest = 3.0, smallest = 1.3) ⇒ Object
This will apply cloud-weighting to any list of items.
- #day_names ⇒ Object
- #deletable?(thing) ⇒ Boolean
- #dropbox? ⇒ Boolean
- #dropbox_auth_url ⇒ Object
- #dropbox_link(folder) ⇒ Object
- #dropbox_session ⇒ Object
- #editable?(thing) ⇒ Boolean
- #month_header_for(date) ⇒ Object
- #nav_link_to(name, url, options = {}) ⇒ Object
- #pageclass ⇒ Object
- #pagination_summary(collection, options = {}) ⇒ Object
- #preference_checkbox(key, options = {}) ⇒ Object
- #preference_radio_set(key, *values) ⇒ Object
- #shorten(text, length = 64, separator = " ") ⇒ Object
- #show_dropbox_links? ⇒ Boolean
- #url_for_date(date) ⇒ Object
- #url_for_month(date) ⇒ Object
- #visible?(thing) ⇒ Boolean
Instance Method Details
#action_menu(thing, locals = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/helpers/droom/droom_helper.rb', line 22 def (thing, locals={}) if can?(:edit, thing) type = thing.class.to_s.downcase.underscore classname = type.split('/').last locals[classname.to_sym] = thing render :partial => "#{type.pluralize}/action_menu", :locals => locals end end |
#action_menulink(thing, html_options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/droom/droom_helper.rb', line 10 def (thing, ={}) if can?(:edit, thing) classname = thing.class.to_s.downcase.underscore.split('/').last .reverse_merge!({ :class => "", :data => {:menu => "#{classname}_#{thing.id}"} }) [:class] << " menu" link_to t(:edit), "#", if editable?(thing) end end |
#admin? ⇒ Boolean
43 44 45 |
# File 'app/helpers/droom/droom_helper.rb', line 43 def admin? current_user && current_user.admin? end |
#allowed?(permission_code) ⇒ Boolean
6 7 8 |
# File 'app/helpers/droom/droom_helper.rb', line 6 def allowed?() current_user.admin? || current_user.permitted?() end |
#cloud(these, threshold = 0, biggest = 3.0, smallest = 1.3) ⇒ Object
This will apply cloud-weighting to any list of items. They must have a ‘weight’ attribute and be ready to accept a ‘cloud_size’ attribute.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/helpers/droom/droom_helper.rb', line 130 def cloud(these, threshold=0, biggest=3.0, smallest=1.3) counts = these.map{|t| t.weight.to_i}.compact if counts.any? max = counts.max min = counts.min if max == min these.each do |this| this.cloud_size = sprintf("%.2f", biggest/2 + smallest/2) end else steepness = Math.log(max - (min-1))/(biggest - smallest) these.each do |this| offset = Math.log(this.weight.to_i - (min-1))/steepness this.cloud_size = sprintf("%.2f", smallest + offset) end end if block_given? these.each do |this| yield this end end end end |
#day_names ⇒ Object
162 163 164 |
# File 'app/helpers/droom/droom_helper.rb', line 162 def day_names ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] end |
#deletable?(thing) ⇒ Boolean
93 94 95 |
# File 'app/helpers/droom/droom_helper.rb', line 93 def deletable?(thing) admin? || current_user == thing.created_by end |
#dropbox? ⇒ Boolean
67 68 69 |
# File 'app/helpers/droom/droom_helper.rb', line 67 def dropbox? current_user and !!current_user.dropbox_token end |
#dropbox_auth_url ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/droom/droom_helper.rb', line 75 def dropbox_auth_url dbs = dropbox_session # get an auth link address, with our register action as the callback = dbs.(droom.register_dropbox_tokens_url) # store the requesting dropbox session, serialized, in our user's session cookie # if the oauth confirmation is successful, we will need it. session[:dropbox_session] = dbs.serialize end |
#dropbox_link(folder) ⇒ Object
31 32 33 34 35 |
# File 'app/helpers/droom/droom_helper.rb', line 31 def dropbox_link(folder) if dropbox? && current_user.pref('dropbox.strategy') == 'clicked' && folder.populated? && !folder.dropboxed_for?(current_user) link_to t(:copy_to_dropbox), droom.dropbox_folder_url(folder), :id => "dropbox_folder_#{folder.id}", :class => 'dropboxer minimal', :data => {:action => "remove", :removed => "#dropbox_folder_#{folder.id}"} end end |
#dropbox_session ⇒ Object
37 38 39 40 41 |
# File 'app/helpers/droom/droom_helper.rb', line 37 def dropbox_session # note that we usually don't want to pick up an existing dropbox session. That happens in the dropbox_tokens_controller, when # following up an access token round trip, but in the view any existing session has probably expired and we're better off with a new one. DropboxSession.new(Droom.dropbox_app_key, Droom.dropbox_app_secret) end |
#editable?(thing) ⇒ Boolean
89 90 91 |
# File 'app/helpers/droom/droom_helper.rb', line 89 def editable?(thing) admin? || current_user == thing.created_by end |
#month_header_for(date) ⇒ Object
103 104 105 |
# File 'app/helpers/droom/droom_helper.rb', line 103 def month_header_for(date) content_tag('h3', l(date, :format => :month_header)) end |
#nav_link_to(name, url, options = {}) ⇒ Object
97 98 99 100 101 |
# File 'app/helpers/droom/droom_helper.rb', line 97 def nav_link_to(name, url, ={}) [:class] ||= "" [:class] << "here" if (request.path == url) || (url != "/" && request.path =~ /^#{url}/) link_to name, url, end |
#pageclass ⇒ Object
47 48 49 |
# File 'app/helpers/droom/droom_helper.rb', line 47 def pageclass controller.controller_name end |
#pagination_summary(collection, options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/helpers/droom/droom_helper.rb', line 107 def pagination_summary(collection, = {}) entry_name = [:entry_name] || (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' ')) summary = if collection.num_pages < 2 case collection.total_count when 0; "No #{entry_name.pluralize} found" when 1; "Displaying <strong>1</strong> #{entry_name}:" else; "Displaying <strong>all #{collection.total_count}</strong> #{entry_name.pluralize}:" end else offset = (collection.current_page - 1) * collection.limit_value %{Displaying <strong>%d - %d</strong> of <strong>%d</strong> #{entry_name.pluralize}: } % [ offset + 1, offset + collection.length, collection.total_count ] end summary.html_safe end |
#preference_checkbox(key, options = {}) ⇒ Object
51 52 53 |
# File 'app/helpers/droom/droom_helper.rb', line 51 def preference_checkbox(key, ={}) render :partial => "droom/preferences/checkbox", :locals => .merge({:key => key}) end |
#preference_radio_set(key, *values) ⇒ Object
55 56 57 |
# File 'app/helpers/droom/droom_helper.rb', line 55 def preference_radio_set(key, *values) render :partial => "droom/preferences/radio_set", :locals => {:key => key, :values => values} end |
#shorten(text, length = 64, separator = " ") ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/helpers/droom/droom_helper.rb', line 59 def shorten(text, length=64, separator=" ") text = (text) length = length[:length] if length.is_a?(Hash) content_tag :span, class: 'shortened', title: text do truncate(text, {:length => length, :separator => separator}) end end |
#show_dropbox_links? ⇒ Boolean
71 72 73 |
# File 'app/helpers/droom/droom_helper.rb', line 71 def show_dropbox_links? dropbox?# && preference is 'clicked' end |
#url_for_date(date) ⇒ Object
158 159 160 |
# File 'app/helpers/droom/droom_helper.rb', line 158 def url_for_date(date) droom.events_url(:year => date.year, :month => date.month, :mday => date.day) end |
#url_for_month(date) ⇒ Object
154 155 156 |
# File 'app/helpers/droom/droom_helper.rb', line 154 def url_for_month(date) droom.events_url(:year => date.year, :month => date.month) end |
#visible?(thing) ⇒ Boolean
85 86 87 |
# File 'app/helpers/droom/droom_helper.rb', line 85 def visible?(thing) admin? || privileged? || current_user.can_see?(thing) end |