Module: ApplicationHelper
- Includes:
- Admin::RegionsHelper, LocalTime, Radiant::LegacyRoutes
- Defined in:
- app/helpers/application_helper.rb
Instance Method Summary collapse
- #admin ⇒ Object
- #admin? ⇒ Boolean
- #body_classes ⇒ Object
- #clean(url) ⇒ Object
- #config ⇒ 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
- #image(name, options = {}) ⇒ Object
- #image_submit(name, options = {}) ⇒ Object
- #logged_in? ⇒ Boolean
- #meta_errors? ⇒ Boolean
- #meta_visible(symbol) ⇒ Object
- #nav_link_to(name, options) ⇒ Object
- #nav_tabs ⇒ Object
- #onsubmit_status(model) ⇒ 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
- #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
148 149 150 |
# File 'app/helpers/application_helper.rb', line 148 def admin Radiant::AdminUI.instance end |
#admin? ⇒ Boolean
91 92 93 |
# File 'app/helpers/application_helper.rb', line 91 def admin? current_user and current_user.admin? end |
#body_classes ⇒ Object
156 157 158 |
# File 'app/helpers/application_helper.rb', line 156 def body_classes @body_classes ||= [] end |
#clean(url) ⇒ Object
78 79 80 81 |
# File 'app/helpers/application_helper.rb', line 78 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_item?(item) ⇒ Boolean
54 55 56 57 58 59 60 61 |
# File 'app/helpers/application_helper.rb', line 54 def current_item?(item) if 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
63 64 65 66 |
# File 'app/helpers/application_helper.rb', line 63 def current_tab?(tab) @current_tab ||= tab if tab.any? {|item| current_url?(item.relative_url) } @current_tab == tab end |
#current_url?(options) ⇒ Boolean
68 69 70 71 72 73 74 75 76 |
# File 'app/helpers/application_helper.rb', line 68 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 |
#designer? ⇒ Boolean
95 96 97 |
# File 'app/helpers/application_helper.rb', line 95 def designer? current_user and (current_user.designer? or current_user.admin?) end |
#filter_options_for_select(selected = nil) ⇒ Object
152 153 154 |
# File 'app/helpers/application_helper.rb', line 152 def (selected=nil) ([['<none>', '']] + TextFilter.descendants.map { |s| s.filter_name }.sort, selected) end |
#focus(field_name) ⇒ Object
99 100 101 |
# File 'app/helpers/application_helper.rb', line 99 def focus(field_name) javascript_tag "Field.activate('#{field_name}');" end |
#image(name, options = {}) ⇒ Object
140 141 142 |
# File 'app/helpers/application_helper.rb', line 140 def image(name, = {}) image_tag(append_image_extension("admin/#{name}"), ) end |
#image_submit(name, options = {}) ⇒ Object
144 145 146 |
# File 'app/helpers/application_helper.rb', line 144 def image_submit(name, = {}) image_submit_tag(append_image_extension("admin/#{name}"), ) 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
132 133 134 |
# File 'app/helpers/application_helper.rb', line 132 def false end |
#meta_visible(symbol) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/application_helper.rb', line 122 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
83 84 85 86 87 88 89 |
# File 'app/helpers/application_helper.rb', line 83 def nav_link_to(name, ) if current_url?() %{<strong>#{ link_to name, }</strong>} else link_to name, end end |
#nav_tabs ⇒ Object
160 161 162 |
# File 'app/helpers/application_helper.rb', line 160 def nav_tabs admin.nav end |
#onsubmit_status(model) ⇒ Object
26 27 28 |
# File 'app/helpers/application_helper.rb', line 26 def onsubmit_status(model) model.new_record? ? "Creating #{model.class.name.downcase}…" : "Saving changes…" end |
#pluralize(count, singular, plural = nil) ⇒ Object
Redefine pluralize() so that it doesn’t put the count at the beginning of the string.
44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/application_helper.rb', line 44 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
38 39 40 |
# File 'app/helpers/application_helper.rb', line 38 def (model) submit_tag 'Save and Continue Editing', :name => 'continue', :class => 'button', :accesskey => "s" end |
#save_model_button(model, options = {}) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/helpers/application_helper.rb', line 30 def (model, = {}) [:label] ||= model.new_record? ? "Create #{model.class.name}" : "Save Changes" [:class] ||= "button" [:accesskey] ||= 'S' submit_tag .delete(:label), 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
118 119 120 |
# File 'app/helpers/application_helper.rb', line 118 def (time) time.strftime("%I:%M %p on %B %e, %Y").sub("AM", 'am').sub("PM", 'pm') 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
136 137 138 |
# File 'app/helpers/application_helper.rb', line 136 def toggle_javascript_for(id) "Element.toggle('#{id}'); Element.toggle('more-#{id}'); Element.toggle('less-#{id}'); return false;" end |
#updated_stamp(model) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/helpers/application_helper.rb', line 103 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">Last updated } html << %{by <strong>#{name}</strong> } if name html << %{at #{(time)}} if time html << %{</p>} html end end end |