Module: ApplicationHelper
- Includes:
- Admin::RegionsHelper, Admin::UrlHelper
- Defined in:
- app/helpers/application_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
- #image(name, options = {}) ⇒ Object
- #javascript_overrides ⇒ Object
- #logged_in? ⇒ Boolean
- #meta_errors? ⇒ Boolean
- #meta_label ⇒ Object
- #nav_tabs ⇒ Object
- #onsubmit_status(model) ⇒ Object
-
#pagination_for(list, options = {}) ⇒ Object
returns the usual set of pagination links.
- #save_model_and_continue_editing_button(_model) ⇒ Object
- #save_model_and_view_page_button(model, options = {}) ⇒ Object
- #save_model_button(model, options = {}) ⇒ Object
- #stylesheet_overrides ⇒ Object
- #subtitle ⇒ Object
- #timestamp(time) ⇒ Object
- #title ⇒ Object
- #translate_with_default(name) ⇒ Object
- #trusty_config ⇒ Object
- #updated_stamp(model) ⇒ Object
Instance Method Details
#admin ⇒ Object
124 125 126 |
# File 'app/helpers/application_helper.rb', line 124 def admin TrustyCms::AdminUI.instance end |
#admin? ⇒ Boolean
84 85 86 |
# File 'app/helpers/application_helper.rb', line 84 def admin? current_user&.admin? end |
#available_locales_select ⇒ Object
140 141 142 |
# File 'app/helpers/application_helper.rb', line 140 def available_locales_select [[t('select.default'), '']] + TrustyCms::AvailableLocales.locales end |
#body_classes ⇒ Object
128 129 130 |
# File 'app/helpers/application_helper.rb', line 128 def body_classes @body_classes ||= [] end |
#clean(url) ⇒ Object
79 80 81 82 |
# File 'app/helpers/application_helper.rb', line 79 def clean(url) uri = URI.parse(url) uri.path.gsub(%r{/+}, '/').gsub(%r{/$}, '') end |
#current_item?(item) ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'app/helpers/application_helper.rb', line 55 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
64 65 66 67 |
# File 'app/helpers/application_helper.rb', line 64 def current_tab?(tab) @current_tab ||= tab if tab.any? { |item| current_url?(item.relative_url) } @current_tab == tab end |
#current_url?(options) ⇒ Boolean
69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/application_helper.rb', line 69 def current_url?() url = case when Hash url_for else .to_s end request.original_fullpath =~ Regexp.new('^' + Regexp.quote(clean(url))) end |
#default_page_title ⇒ Object
9 10 11 |
# File 'app/helpers/application_helper.rb', line 9 def default_page_title title + ' - ' + subtitle end |
#designer? ⇒ Boolean
88 89 90 |
# File 'app/helpers/application_helper.rb', line 88 def designer? current_user and (current_user.designer? or current_user.admin?) end |
#image(name, options = {}) ⇒ Object
120 121 122 |
# File 'app/helpers/application_helper.rb', line 120 def image(name, = {}) image_tag(append_image_extension("admin/#{name}"), ) end |
#javascript_overrides ⇒ Object
152 153 154 155 156 157 158 |
# File 'app/helpers/application_helper.rb', line 152 def javascript_overrides overrides = [] if File.exist?("#{Rails.root}/public/javascripts/admin/overrides.js") overrides << 'admin/overrides' end overrides end |
#logged_in? ⇒ Boolean
21 22 23 |
# File 'app/helpers/application_helper.rb', line 21 def logged_in? !current_user.nil? end |
#meta_errors? ⇒ Boolean
112 113 114 |
# File 'app/helpers/application_helper.rb', line 112 def false end |
#meta_label ⇒ Object
116 117 118 |
# File 'app/helpers/application_helper.rb', line 116 def ? 'Less' : 'More' end |
#nav_tabs ⇒ Object
132 133 134 |
# File 'app/helpers/application_helper.rb', line 132 def nav_tabs admin.nav end |
#onsubmit_status(model) ⇒ Object
25 26 27 |
# File 'app/helpers/application_helper.rb', line 25 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.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/helpers/application_helper.rb', line 163 def pagination_for(list, = {}) if list.respond_to? :total_pages = { max_per_page: @trusty_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 << content_tag(:div, link_to(t('show_all'), pp: 'all'), class: 'depaginate') elsif depaginate && list.total_entries > depagination_limit.to_i html = content_tag(:div, link_to('paginate', p: 1), class: 'pagination') end html end end |
#save_model_and_continue_editing_button(_model) ⇒ Object
41 42 43 |
# File 'app/helpers/application_helper.rb', line 41 def (_model) submit_tag t('buttons.save_and_continue'), name: 'continue', class: 'button', accesskey: 's', id: 'save-and-continue-button' end |
#save_model_and_view_page_button(model, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/application_helper.rb', line 45 def (model, = {}) return nil unless generate_page_url(request.url, model) [:label] ||= model.published? ? t('buttons.save_and_view_page') : t('buttons.save_and_view_draft') [:class] ||= 'button' [:name] ||= 'save_and_view' [:id] ||= 'save-and-view-button' submit_tag .delete(:label), end |
#save_model_button(model, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/application_helper.rb', line 29 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' [:id] ||= 'save-button' submit_tag .delete(:label), end |
#stylesheet_overrides ⇒ Object
144 145 146 147 148 149 150 |
# File 'app/helpers/application_helper.rb', line 144 def stylesheet_overrides overrides = [] if File.exist?("#{Rails.root}/public/stylesheets/admin/overrides.css") || File.exist?("#{Rails.root}/public/stylesheets/sass/admin/overrides.sass") overrides << 'admin/overrides' end overrides end |
#subtitle ⇒ Object
17 18 19 |
# File 'app/helpers/application_helper.rb', line 17 def subtitle trusty_config['admin.subtitle'] || 'Publishing for Small Teams' end |
#timestamp(time) ⇒ Object
107 108 109 110 |
# File 'app/helpers/application_helper.rb', line 107 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
13 14 15 |
# File 'app/helpers/application_helper.rb', line 13 def title trusty_config['admin.title'] || 'Trusty CMS' end |
#translate_with_default(name) ⇒ Object
136 137 138 |
# File 'app/helpers/application_helper.rb', line 136 def translate_with_default(name) t(name.underscore.downcase, default: name) end |
#trusty_config ⇒ Object
5 6 7 |
# File 'app/helpers/application_helper.rb', line 5 def trusty_config TrustyCms::Config end |
#updated_stamp(model) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/application_helper.rb', line 92 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 || time html = %{<div class="updated_line">#{t('timestamp.last_updated')} } html << %{#{t('timestamp.by')} <strong>#{name}</strong> } if name html << %{#{t('timestamp.at')} #{timestamp(time)}} if time html << %{</div>} html.html_safe end end end |