Module: ApplicationHelper
- Includes:
- Admin::RegionsHelper, LocalTime, Radiant::LegacyRoutes
- Defined in:
- app/helpers/application_helper.rb
Instance Method Summary collapse
- #admin ⇒ Object
- #admin? ⇒ Boolean
- #clean(url) ⇒ Object
- #config ⇒ Object
- #current_url?(options) ⇒ Boolean
- #default_page_title ⇒ Object
- #developer? ⇒ Boolean
- #filter_options_for_select(selected = nil) ⇒ Object
- #focus(field_name) ⇒ Object
- #image(name, options = {}) ⇒ Object
- #image_submit(name, options = {}) ⇒ Object
- #links_for_navigation ⇒ Object
- #logged_in? ⇒ Boolean
- #meta_errors? ⇒ Boolean
- #meta_visible(symbol) ⇒ Object
- #nav_link_to(name, options) ⇒ Object
-
#pluralize(count, singular, plural = nil) ⇒ Object
Redefine pluralize() so that it doesn’t put the count at the beginning of the string.
- #save_model_and_continue_editing_button(model) ⇒ Object
- #save_model_button(model, options = {}) ⇒ Object
- #separator ⇒ Object
- #subtitle ⇒ Object
- #timestamp(time) ⇒ Object
- #title ⇒ Object
- #toggle_javascript_for(id) ⇒ Object
- #updated_stamp(model) ⇒ Object
Methods included from LocalTime
Instance Method Details
#admin ⇒ Object
144 145 146 |
# File 'app/helpers/application_helper.rb', line 144 def admin Radiant::AdminUI.instance end |
#admin? ⇒ Boolean
85 86 87 |
# File 'app/helpers/application_helper.rb', line 85 def admin? current_user and current_user.admin? end |
#clean(url) ⇒ Object
72 73 74 75 |
# File 'app/helpers/application_helper.rb', line 72 def clean(url) uri = URI.parse(url) uri.path.gsub(%r{/+}, '/').gsub(%r{/$}, '') end |
#config ⇒ Object
6 7 8 |
# File 'app/helpers/application_helper.rb', line 6 def config Radiant::Config end |
#current_url?(options) ⇒ Boolean
62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/application_helper.rb', line 62 def current_url?() url = case when Hash url_for else .to_s end request.request_uri =~ Regexp.new('^' + Regexp.quote(clean(url))) end |
#default_page_title ⇒ Object
10 11 12 |
# File 'app/helpers/application_helper.rb', line 10 def default_page_title title + ' - ' + subtitle end |
#developer? ⇒ Boolean
89 90 91 |
# File 'app/helpers/application_helper.rb', line 89 def developer? current_user and (current_user.developer? or current_user.admin?) end |
#filter_options_for_select(selected = nil) ⇒ Object
148 149 150 |
# File 'app/helpers/application_helper.rb', line 148 def (selected=nil) ([['<none>', '']] + TextFilter.descendants.map { |s| s.filter_name }.sort, selected) end |
#focus(field_name) ⇒ Object
93 94 95 |
# File 'app/helpers/application_helper.rb', line 93 def focus(field_name) javascript_tag "Field.activate('#{field_name}');" end |
#image(name, options = {}) ⇒ Object
136 137 138 |
# File 'app/helpers/application_helper.rb', line 136 def image(name, = {}) image_tag(append_image_extension("admin/#{name}"), ) end |
#image_submit(name, options = {}) ⇒ Object
140 141 142 |
# File 'app/helpers/application_helper.rb', line 140 def image_submit(name, = {}) image_submit_tag(append_image_extension("admin/#{name}"), ) end |
#links_for_navigation ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/helpers/application_helper.rb', line 50 def tabs = admin.tabs links = tabs.map do |tab| nav_link_to(tab.name, File.join(ActionController::Base.relative_url_root || '', tab.url)) if tab.shown_for?(current_user) end.compact links.join(separator) end |
#logged_in? ⇒ Boolean
22 23 24 |
# File 'app/helpers/application_helper.rb', line 22 def logged_in? !current_user.nil? end |
#meta_errors? ⇒ Boolean
128 129 130 |
# File 'app/helpers/application_helper.rb', line 128 def false end |
#meta_visible(symbol) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'app/helpers/application_helper.rb', line 118 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
77 78 79 80 81 82 83 |
# File 'app/helpers/application_helper.rb', line 77 def nav_link_to(name, ) if current_url?() %{<strong>#{ link_to name, options }</strong>} else link_to name, end end |
#pluralize(count, singular, plural = nil) ⇒ Object
Redefine pluralize() so that it doesn’t put the count at the beginning of the string.
40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/application_helper.rb', line 40 def pluralize(count, singular, plural = nil) if count == 1 singular elsif plural plural else ActiveSupport::Inflector.pluralize(singular) end end |
#save_model_and_continue_editing_button(model) ⇒ Object
34 35 36 |
# File 'app/helpers/application_helper.rb', line 34 def (model) submit_tag 'Save and Continue Editing', :name => 'continue', :class => 'button' end |
#save_model_button(model, options = {}) ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/helpers/application_helper.rb', line 26 def (model, = {}) [:label] ||= model.new_record? ? "Create #{model.class.name}" : "Save Changes" [:class] ||= "button" submit_tag .delete(:label), end |
#separator ⇒ Object
58 59 60 |
# File 'app/helpers/application_helper.rb', line 58 def separator %{ <span class="separator"> | </span> } end |
#subtitle ⇒ Object
18 19 20 |
# File 'app/helpers/application_helper.rb', line 18 def subtitle config['admin.subtitle'] || 'Publishing for Small Teams' end |
#timestamp(time) ⇒ Object
114 115 116 |
# File 'app/helpers/application_helper.rb', line 114 def (time) time.strftime("%I:%M <small>%p</small> on %B %d, %Y") end |
#title ⇒ Object
14 15 16 |
# File 'app/helpers/application_helper.rb', line 14 def title config['admin.title'] || 'Radiant CMS' end |
#toggle_javascript_for(id) ⇒ Object
132 133 134 |
# File 'app/helpers/application_helper.rb', line 132 def toggle_javascript_for(id) "Element.toggle('#{id}'); Element.toggle('more-#{id}'); Element.toggle('less-#{id}'); return false;" end |
#updated_stamp(model) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/helpers/application_helper.rb', line 97 def updated_stamp(model) unless model.new_record? updated_by = (model.updated_by || model.created_by) login = updated_by ? updated_by.login : nil time = (model.updated_at || model.created_at) if login or time html = %{<p style="clear: left"><small>Last updated } html << %{by #{login} } if login html << %{at #{ timestamp(time) }} if time html << %{</small></p>} html end else %{<p class="clear"> </p>} end end |