Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 7228 Bytes
1 | module ApplicationHelper |
2 | include LocalTime |
3 | include Admin::RegionsHelper |
4 | include Radiant::LegacyRoutes |
5 | |
6 | def config |
7 | Radiant::Config |
8 | end |
9 | |
10 | def default_page_title |
11 | title + ' - ' + subtitle |
12 | end |
13 | |
14 | def title |
15 | config['admin.title'] || 'Radiant CMS' |
16 | end |
17 | |
18 | def subtitle |
19 | config['admin.subtitle'] || 'Publishing for Small Teams' |
20 | end |
21 | |
22 | def logged_in? |
23 | !current_user.nil? |
24 | end |
25 | |
26 | def onsubmit_status(model) |
27 | model.new_record? ? t('creating_status', :model => t(model.class.name.downcase)) : "#{I18n.t('saving_changes')}…" |
28 | end |
29 | |
30 | def save_model_button(model, options = {}) |
31 | model_name = model.class.name.underscore |
32 | human_model_name = model_name.humanize.titlecase |
33 | options[:label] ||= model.new_record? ? |
34 | t('buttons.create', :name => t(model_name, :default => human_model_name), :default => 'Create ' + human_model_name) : |
35 | t('buttons.save_changes', :default => 'Save Changes') |
36 | options[:class] ||= "button" |
37 | options[:accesskey] ||= 'S' |
38 | submit_tag options.delete(:label), options |
39 | end |
40 | |
41 | def save_model_and_continue_editing_button(model) |
42 | submit_tag t('buttons.save_and_continue'), :name => 'continue', :class => 'button', :accesskey => "s" |
43 | end |
44 | |
45 | # Redefine pluralize() so that it doesn't put the count at the beginning of |
46 | # the string. |
47 | def pluralize(count, singular, plural = nil) |
48 | if count == 1 |
49 | singular |
50 | elsif plural |
51 | plural |
52 | else |
53 | ActiveSupport::Inflector.pluralize(singular) |
54 | end |
55 | end |
56 | |
57 | def current_item?(item) |
58 | if item.tab && item.tab.many? {|i| current_url?(i.relative_url) } |
59 | # Accept only stricter URL matches if more than one matches |
60 | current_page?(item.url) |
61 | else |
62 | current_url?(item.relative_url) |
63 | end |
64 | end |
65 | |
66 | def current_tab?(tab) |
67 | @current_tab ||= tab if tab.any? {|item| current_url?(item.relative_url) } |
68 | @current_tab == tab |
69 | end |
70 | |
71 | def current_url?(options) |
72 | url = case options |
73 | when Hash |
74 | url_for options |
75 | else |
76 | options.to_s |
77 | end |
78 | request.request_uri =~ Regexp.new('^' + Regexp.quote(clean(url))) |
79 | end |
80 | |
81 | def clean(url) |
82 | uri = URI.parse(url) |
83 | uri.path.gsub(%r{/+}, '/').gsub(%r{/$}, '') |
84 | end |
85 | |
86 | def nav_link_to(name, options) |
87 | if current_url?(options) |
88 | %{<strong>#{ link_to translate_with_default(name), options }</strong>} |
89 | else |
90 | link_to translate_with_default(name), options |
91 | end |
92 | end |
93 | |
94 | def admin? |
95 | current_user and current_user.admin? |
96 | end |
97 | |
98 | def designer? |
99 | current_user and (current_user.designer? or current_user.admin?) |
100 | end |
101 | |
102 | def focus(field_name) |
103 | javascript_tag "Field.activate('#{field_name}');" |
104 | end |
105 | |
106 | def updated_stamp(model) |
107 | unless model.new_record? |
108 | updated_by = (model.updated_by || model.created_by) |
109 | name = updated_by ? updated_by.name : nil |
110 | time = (model.updated_at || model.created_at) |
111 | if name or time |
112 | html = %{<p class="updated_line">#{t('timestamp.last_updated')} } |
113 | html << %{#{t('timestamp.by')} <strong>#{name}</strong> } if name |
114 | html << %{#{t('timestamp.at')} #{timestamp(time)}} if time |
115 | html << %{</p>} |
116 | html |
117 | end |
118 | end |
119 | end |
120 | |
121 | def timestamp(time) |
122 | # time.strftime("%I:%M %p on %B %e, %Y").sub("AM", 'am').sub("PM", 'pm') |
123 | I18n.localize(time, :format => :timestamp) |
124 | end |
125 | |
126 | def meta_visible(symbol) |
127 | v = case symbol |
128 | when :meta_more |
129 | not meta_errors? |
130 | when :meta, :meta_less |
131 | meta_errors? |
132 | end |
133 | v ? {} : {:style => "display: none"} |
134 | end |
135 | |
136 | def meta_errors? |
137 | false |
138 | end |
139 | |
140 | def meta_label |
141 | meta_errors? ? 'Less' : 'More' |
142 | end |
143 | |
144 | def toggle_javascript_for(id) |
145 | "Element.toggle('#{id}'); Element.toggle('more-#{id}'); Element.toggle('less-#{id}'); return false;" |
146 | end |
147 | |
148 | def image(name, options = {}) |
149 | image_tag(append_image_extension("admin/#{name}"), options) |
150 | end |
151 | |
152 | def image_submit(name, options = {}) |
153 | image_submit_tag(append_image_extension("admin/#{name}"), options) |
154 | end |
155 | |
156 | def admin |
157 | Radiant::AdminUI.instance |
158 | end |
159 | |
160 | def filter_options_for_select(selected=nil) |
161 | options_for_select([[t('select.none'), '']] + TextFilter.descendants.map { |s| s.filter_name }.sort, selected) |
162 | end |
163 | |
164 | def body_classes |
165 | @body_classes ||= [] |
166 | end |
167 | |
168 | def nav_tabs |
169 | admin.nav |
170 | end |
171 | |
172 | def translate_with_default(name) |
173 | t(name.underscore.downcase, :default => name) |
174 | end |
175 | |
176 | def available_locales_select |
177 | [[t('select.default'),'']] + Radiant::AvailableLocales.locales |
178 | end |
179 | |
180 | def stylesheet_and_javascript_overrides |
181 | overrides = '' |
182 | if File.exist?("#{Rails.root}/public/stylesheets/admin/overrides.css") || File.exist?("#{Rails.root}/public/stylesheets/sass/admin/overrides.sass") |
183 | overrides << stylesheet_link_tag('admin/overrides') |
184 | end |
185 | if File.exist?("#{Rails.root}/public/javascripts/admin/overrides.js") |
186 | overrides << javascript_include_tag('admin/overrides') |
187 | end |
188 | overrides |
189 | end |
190 | |
191 | # Returns a Gravatar URL associated with the email parameter. |
192 | # See: http://douglasfshearer.com/blog/gravatar-for-ruby-and-ruby-on-rails |
193 | def gravatar_url(email, options={}) |
194 | # Default to highest rating. Rating can be one of G, PG, R X. |
195 | options[:rating] ||= "G" |
196 | |
197 | # Default size of the image. |
198 | options[:size] ||= "32px" |
199 | |
200 | # Default image url to be used when no gravatar is found |
201 | # or when an image exceeds the rating parameter. |
202 | default_avatar_url = "#{request.protocol}#{request.host_with_port}/images/admin/avatar_#{([options[:size].to_i] * 2).join('x')}.png" |
203 | options[:default] ||= default_avatar_url |
204 | |
205 | unless email.blank? |
206 | # Build the Gravatar url. |
207 | url = 'http://www.gravatar.com/avatar.php?' |
208 | url << "gravatar_id=#{Digest::MD5.new.update(email)}" |
209 | url << "&rating=#{options[:rating]}" if options[:rating] |
210 | url << "&size=#{options[:size]}" if options[:size] |
211 | url << "&default=#{options[:default]}" if options[:default] |
212 | url |
213 | else |
214 | default_avatar_url |
215 | end |
216 | end |
217 | |
218 | # returns the usual set of pagination links. |
219 | # options are passed through to will_paginate |
220 | # and a 'show all' depagination link is added if relevant. |
221 | def pagination_for(list, options={}) |
222 | if list.respond_to? :total_pages |
223 | options = { |
224 | :max_per_page => config['pagination.max_per_page'] || 500, |
225 | :depaginate => true |
226 | }.merge(options.symbolize_keys) |
227 | depaginate = options.delete(:depaginate) # supply :depaginate => false to omit the 'show all' link |
228 | depagination_limit = options.delete(:max_per_page) # supply :max_per_page => false to include the 'show all' link no matter how large the collection |
229 | html = will_paginate(list, will_paginate_options.merge(options)) |
230 | if depaginate && list.total_pages > 1 && (!depagination_limit.blank? || list.total_entries <= depagination_limit.to_i) |
231 | html << content_tag(:div, link_to("show all", :pp => list.total_entries), :class => 'depaginate') |
232 | end |
233 | html |
234 | end |
235 | end |
236 | |
237 | private |
238 | |
239 | def append_image_extension(name) |
240 | unless name =~ /\.(.*?)$/ |
241 | name + '.png' |
242 | else |
243 | name |
244 | end |
245 | end |
246 | |
247 | end |