Module: AdminHelper
- Includes:
- Admin::RegionsHelper, LocalTime, Radiant::LegacyRoutes
- Defined in:
- app/helpers/admin_helper.rb
Instance Method Summary collapse
- #admin ⇒ Object
- #admin? ⇒ Boolean
- #available_locales_select ⇒ Object
- #body_classes ⇒ Object
- #clean(url) ⇒ Object
- #current_item?(item) ⇒ Boolean
- #current_tab?(tab) ⇒ Boolean
- #current_url?(options) ⇒ Boolean
- #default_page_title ⇒ Object
- #designer? ⇒ Boolean
- #filter_options_for_select(selected = nil) ⇒ Object
- #focus(field_name) ⇒ Object
-
#gravatar_url(email, options = {}) ⇒ Object
Returns a Gravatar URL associated with the email parameter.
- #image(name, options = {}) ⇒ Object
- #image_submit(name, options = {}) ⇒ Object
- #logged_in? ⇒ Boolean
- #meta_errors? ⇒ Boolean
- #meta_label ⇒ Object
- #meta_visible(symbol) ⇒ Object
- #nav_link_to(name, options) ⇒ Object
- #nav_tabs ⇒ Object
- #onsubmit_status(model) ⇒ Object
-
#pagination_for(list, options = {}) ⇒ Object
returns the usual set of pagination links.
-
#pluralize(count, singular, plural = nil) ⇒ Object
Redefine pluralize() so that it doesn’t put the count at the beginning of the string.
- #radiant_config ⇒ Object
- #save_model_and_continue_editing_button(model) ⇒ Object
- #save_model_button(model, options = {}) ⇒ Object
- #stylesheet_and_javascript_overrides ⇒ Object
- #subtitle ⇒ Object
- #timestamp(time) ⇒ Object
- #title ⇒ Object
- #toggle_javascript_for(id) ⇒ Object
- #translate_with_default(name) ⇒ Object
- #updated_stamp(model) ⇒ Object
Methods included from LocalTime
Instance Method Details
#admin ⇒ Object
159 160 161 |
# File 'app/helpers/admin_helper.rb', line 159 def admin Radiant::AdminUI.instance end |
#admin? ⇒ Boolean
97 98 99 |
# File 'app/helpers/admin_helper.rb', line 97 def admin? current_user and current_user.admin? end |
#available_locales_select ⇒ Object
179 180 181 |
# File 'app/helpers/admin_helper.rb', line 179 def available_locales_select [[t('select.default'),'']] + Radiant::AvailableLocales.locales end |
#body_classes ⇒ Object
167 168 169 |
# File 'app/helpers/admin_helper.rb', line 167 def body_classes @body_classes ||= [] end |
#clean(url) ⇒ Object
84 85 86 87 |
# File 'app/helpers/admin_helper.rb', line 84 def clean(url) uri = URI.parse(url) uri.path.gsub(%r{/+}, '/').gsub(%r{/$}, '') end |
#current_item?(item) ⇒ Boolean
60 61 62 63 64 65 66 67 |
# File 'app/helpers/admin_helper.rb', line 60 def current_item?(item) if item.tab && item.tab.many? {|i| current_url?(i.relative_url) } # Accept only stricter URL matches if more than one matches current_page?(item.url) else current_url?(item.relative_url) end end |
#current_tab?(tab) ⇒ Boolean
69 70 71 72 |
# File 'app/helpers/admin_helper.rb', line 69 def current_tab?(tab) @current_tab ||= tab if tab.any? {|item| current_url?(item.relative_url) } @current_tab == tab end |
#current_url?(options) ⇒ Boolean
74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/admin_helper.rb', line 74 def current_url?() url = case when Hash url_for else .to_s end request.fullpath =~ Regexp.new('^' + Regexp.quote(clean(url))) end |
#default_page_title ⇒ Object
13 14 15 |
# File 'app/helpers/admin_helper.rb', line 13 def default_page_title title + ' - ' + subtitle end |
#designer? ⇒ Boolean
101 102 103 |
# File 'app/helpers/admin_helper.rb', line 101 def designer? current_user and (current_user.designer? or current_user.admin?) end |
#filter_options_for_select(selected = nil) ⇒ Object
163 164 165 |
# File 'app/helpers/admin_helper.rb', line 163 def (selected=nil) ([[t('select.none'), '']] + TextFilter.descendants_names, selected) end |
#focus(field_name) ⇒ Object
105 106 107 |
# File 'app/helpers/admin_helper.rb', line 105 def focus(field_name) javascript_tag "Field.activate('#{field_name}');" end |
#gravatar_url(email, options = {}) ⇒ Object
Returns a Gravatar URL associated with the email parameter. See: douglasfshearer.com/blog/gravatar-for-ruby-and-ruby-on-rails
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'app/helpers/admin_helper.rb', line 196 def gravatar_url(email, ={}) # Default to highest rating. Rating can be one of G, PG, R X. [:rating] ||= "G" # Default size of the image. [:size] ||= "32px" # Default image url to be used when no gravatar is found # or when an image exceeds the rating parameter. default_avatar_url = "#{request.protocol}#{request.host_with_port}/images/admin/avatar_#{([[:size].to_i] * 2).join('x')}.png" [:default] ||= default_avatar_url unless email.blank? # Build the Gravatar url. url = 'http://www.gravatar.com/avatar.php?' url << "gravatar_id=#{Digest::MD5.new.update(email)}" url << "&rating=#{[:rating]}" if [:rating] url << "&size=#{[:size]}" if [:size] url << "&default=#{[:default]}" if [:default] url else default_avatar_url end end |
#image(name, options = {}) ⇒ Object
151 152 153 |
# File 'app/helpers/admin_helper.rb', line 151 def image(name, = {}) image_tag(append_image_extension("admin/#{name}"), ) end |
#image_submit(name, options = {}) ⇒ Object
155 156 157 |
# File 'app/helpers/admin_helper.rb', line 155 def image_submit(name, = {}) image_submit_tag(append_image_extension("admin/#{name}"), ) end |
#logged_in? ⇒ Boolean
25 26 27 |
# File 'app/helpers/admin_helper.rb', line 25 def logged_in? !current_user.nil? end |
#meta_errors? ⇒ Boolean
139 140 141 |
# File 'app/helpers/admin_helper.rb', line 139 def @page and !!(@page.errors[:slug].present? or @page.errors[:breadcrumb].present?) end |
#meta_label ⇒ Object
143 144 145 |
# File 'app/helpers/admin_helper.rb', line 143 def ? 'Less' : 'More' end |
#meta_visible(symbol) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/admin_helper.rb', line 129 def (symbol) v = case symbol when :meta_more not when :meta, :meta_less end v ? {} : {:style => "display: none"} end |
#nav_link_to(name, options) ⇒ Object
89 90 91 92 93 94 95 |
# File 'app/helpers/admin_helper.rb', line 89 def nav_link_to(name, ) if current_url?() %{<strong>#{ link_to translate_with_default(name), }</strong>} else link_to translate_with_default(name), end end |
#nav_tabs ⇒ Object
171 172 173 |
# File 'app/helpers/admin_helper.rb', line 171 def nav_tabs admin.nav end |
#onsubmit_status(model) ⇒ Object
29 30 31 |
# File 'app/helpers/admin_helper.rb', line 29 def onsubmit_status(model) model.new_record? ? t('creating_status', :model => t(model.class.name.downcase)) : "#{I18n.t('saving_changes')}…" end |
#pagination_for(list, options = {}) ⇒ Object
returns the usual set of pagination links. options are passed through to will_paginate and a ‘show all’ depagination link is added if relevant.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'app/helpers/admin_helper.rb', line 224 def pagination_for(list, ={}) if list.respond_to? :total_pages = { :max_per_page => radiant_config['pagination.max_per_page'] || 500, :depaginate => true }.merge(.symbolize_keys) depaginate = .delete(:depaginate) # supply :depaginate => false to omit the 'show all' link depagination_limit = .delete(:max_per_page) # supply :max_per_page => false to include the 'show all' link no matter how large the collection html = will_paginate(list, .merge()) if depaginate && list.total_pages > 1 && (!depagination_limit.blank? || list.total_entries <= depagination_limit.to_i) html.insert(html.index("</div>"), content_tag(:span, link_to("show all", :pp => list.total_entries), :class => 'toggle')) elsif list.total_entries > depagination_limit.to_i html = content_tag(:div, link_to("paginate", :p => 1), :class => 'pagination') end html end end |
#pluralize(count, singular, plural = nil) ⇒ Object
Redefine pluralize() so that it doesn’t put the count at the beginning of the string.
50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/admin_helper.rb', line 50 def pluralize(count, singular, plural = nil) if count == 1 singular elsif plural plural else ActiveSupport::Inflector.pluralize(singular) end end |
#radiant_config ⇒ Object
9 10 11 |
# File 'app/helpers/admin_helper.rb', line 9 def radiant_config Radiant::Config end |
#save_model_and_continue_editing_button(model) ⇒ Object
44 45 46 |
# File 'app/helpers/admin_helper.rb', line 44 def (model) submit_tag t('buttons.save_and_continue'), :name => 'continue', :class => 'button', :accesskey => "s" end |
#save_model_button(model, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/admin_helper.rb', line 33 def (model, = {}) model_name = model.class.name.underscore human_model_name = model_name.humanize.titlecase [:label] ||= model.new_record? ? t('buttons.create', :name => t(model_name, :default => human_model_name), :default => 'Create ' + human_model_name) : t('buttons.save_changes', :default => 'Save Changes') [:class] ||= "button" [:accesskey] ||= 'S' submit_tag .delete(:label), end |
#stylesheet_and_javascript_overrides ⇒ Object
183 184 185 186 187 188 189 190 191 192 |
# File 'app/helpers/admin_helper.rb', line 183 def stylesheet_and_javascript_overrides overrides = '' if File.exist?("#{Rails.root}/public/stylesheets/admin/overrides.css") || File.exist?("#{Rails.root}/public/stylesheets/sass/admin/overrides.sass") overrides << stylesheet_link_tag('admin/overrides') end if File.exist?("#{Rails.root}/public/javascripts/admin/overrides.js") overrides << javascript_include_tag('admin/overrides') end overrides.html_safe end |
#subtitle ⇒ Object
21 22 23 |
# File 'app/helpers/admin_helper.rb', line 21 def subtitle radiant_config['admin.subtitle'] || 'Publishing for Small Teams' end |
#timestamp(time) ⇒ Object
124 125 126 127 |
# File 'app/helpers/admin_helper.rb', line 124 def (time) # time.strftime("%I:%M %p on %B %e, %Y").sub("AM", 'am').sub("PM", 'pm') I18n.localize(time, :format => :timestamp) end |
#title ⇒ Object
17 18 19 |
# File 'app/helpers/admin_helper.rb', line 17 def title radiant_config['admin.title'] || 'Radiant CMS' end |
#toggle_javascript_for(id) ⇒ Object
147 148 149 |
# File 'app/helpers/admin_helper.rb', line 147 def toggle_javascript_for(id) "Element.toggle('#{id}'); Element.toggle('more-#{id}'); Element.toggle('less-#{id}'); return false;" end |
#translate_with_default(name) ⇒ Object
175 176 177 |
# File 'app/helpers/admin_helper.rb', line 175 def translate_with_default(name) t(name.underscore.downcase, :default => name) end |
#updated_stamp(model) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/admin_helper.rb', line 109 def updated_stamp(model) unless model.new_record? updated_by = (model.updated_by || model.created_by) name = updated_by ? updated_by.name : nil time = (model.updated_at || model.created_at) if name or time html = %{<p class="updated_line">#{t('timestamp.last_updated')} } html << %{#{t('timestamp.by')} <strong>#{name}</strong> } if name html << %{#{t('timestamp.at')} #{(time)}} if time html << %{</p>} html.html_safe end end end |