Module: ApplicationHelper
Instance Method Summary
collapse
#build_url, #default_route?, #extract_base_url, #format_path, #generate_page_url, #lookup_page_path
#lazy_initialize_region_set, #render_region
Instance Method Details
#admin ⇒ Object
114
115
116
|
# File 'app/helpers/application_helper.rb', line 114
def admin
TrustyCms::AdminUI.instance
end
|
#admin? ⇒ Boolean
74
75
76
|
# File 'app/helpers/application_helper.rb', line 74
def admin?
current_user&.admin?
end
|
#available_locales_select ⇒ Object
130
131
132
|
# File 'app/helpers/application_helper.rb', line 130
def available_locales_select
[[t('select.default'), '']] + TrustyCms::AvailableLocales.locales
end
|
#body_classes ⇒ Object
118
119
120
|
# File 'app/helpers/application_helper.rb', line 118
def body_classes
@body_classes ||= []
end
|
#clean(url) ⇒ Object
69
70
71
72
|
# File 'app/helpers/application_helper.rb', line 69
def clean(url)
uri = URI.parse(url)
uri.path.gsub(%r{/+}, '/').gsub(%r{/$}, '')
end
|
#current_item?(item) ⇒ Boolean
45
46
47
48
49
50
51
52
|
# File 'app/helpers/application_helper.rb', line 45
def current_item?(item)
if item.tab&.many? { |i| current_url?(i.relative_url) }
current_page?(item.url)
else
current_url?(item.relative_url)
end
end
|
#current_tab?(tab) ⇒ Boolean
54
55
56
57
|
# File 'app/helpers/application_helper.rb', line 54
def current_tab?(tab)
@current_tab ||= tab if tab.any? { |item| current_url?(item.relative_url) }
@current_tab == tab
end
|
#current_url?(options) ⇒ Boolean
59
60
61
62
63
64
65
66
67
|
# File 'app/helpers/application_helper.rb', line 59
def current_url?(options)
url = case options
when Hash
url_for options
else
options.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
78
79
80
|
# File 'app/helpers/application_helper.rb', line 78
def designer?
current_user and (current_user.designer? or current_user.admin?)
end
|
#image(name, options = {}) ⇒ Object
110
111
112
|
# File 'app/helpers/application_helper.rb', line 110
def image(name, options = {})
image_tag(append_image_extension("admin/#{name}"), options)
end
|
#javascript_overrides ⇒ Object
142
143
144
145
146
147
148
|
# File 'app/helpers/application_helper.rb', line 142
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
|
102
103
104
|
# File 'app/helpers/application_helper.rb', line 102
def meta_errors?
false
end
|
106
107
108
|
# File 'app/helpers/application_helper.rb', line 106
def meta_label
meta_errors? ? 'Less' : 'More'
end
|
#nav_tabs ⇒ Object
122
123
124
|
# File 'app/helpers/application_helper.rb', line 122
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
|
returns the usual set of pagination links. options are passed through to will_paginate and a ‘show all’ depagination link is added if relevant.
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/helpers/application_helper.rb', line 153
def (list, options = {})
if list.respond_to? :total_pages
options = {
max_per_page: @trusty_config['pagination.max_per_page'] || 500,
depaginate: true,
}.merge(options.symbolize_keys)
depaginate = options.delete(:depaginate)
= options.delete(:max_per_page)
html = will_paginate(list, will_paginate_options.merge(options))
if depaginate && list.total_pages > 1 && (!.blank? || list.total_entries <= .to_i)
html << content_tag(:div, link_to(t('show_all'), pp: 'all'), class: 'depaginate')
elsif depaginate && list.total_entries > .to_i
html = content_tag(:div, link_to('paginate', p: 1), class: 'pagination')
end
html
end
end
|
41
42
43
|
# File 'app/helpers/application_helper.rb', line 41
def save_model_and_continue_editing_button(_model)
submit_tag t('buttons.save_and_continue'), name: 'continue', class: 'button', accesskey: 's', id: 'save-and-continue-button'
end
|
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/helpers/application_helper.rb', line 29
def save_model_button(model, options = {})
model_name = model.class.name.underscore
human_model_name = model_name.humanize.titlecase
options[: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')
options[:class] ||= 'button'
options[:accesskey] ||= 'S'
options[:id] ||= 'save-button'
submit_tag options.delete(:label), options
end
|
#stylesheet_overrides ⇒ Object
134
135
136
137
138
139
140
|
# File 'app/helpers/application_helper.rb', line 134
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
97
98
99
100
|
# File 'app/helpers/application_helper.rb', line 97
def timestamp(time)
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
126
127
128
|
# File 'app/helpers/application_helper.rb', line 126
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'app/helpers/application_helper.rb', line 82
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
|