diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2012-06-20 10:46:57 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2012-06-20 10:46:57 +0100 |
commit | 6c4c822ef7a4491bf821326af779e5be9118c0a1 (patch) | |
tree | 39cf3564b1b2fb6be26499eda2a41be7ba59ad65 /app/helpers/application_helper.rb | |
parent | ea977a0b9e86bc99a84de8577fa4ce1d304ac489 (diff) | |
parent | 08dac0261325cd757b7146f9626f3c7b48cc672c (diff) |
Merge branch 'release/0.6'0.6
Conflicts:
locale/bs/app.po
locale/ca/app.po
locale/cs/app.po
locale/cy/app.po
locale/de/app.po
locale/en_IE/app.po
locale/es/app.po
locale/eu/app.po
locale/fr/app.po
locale/ga_IE/app.po
locale/gl/app.po
locale/hu_HU/app.po
locale/id/app.po
locale/pt_BR/app.po
locale/sq/app.po
locale/sr@latin/app.po
spec/fixtures/locale/en/app.po
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r-- | app/helpers/application_helper.rb | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a0f16dfaf..cb6615199 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -17,6 +17,9 @@ module ApplicationHelper # Site-wide access to configuration settings include ConfigHelper + # Useful for sending emails + include MailerHelper + # Copied from error_messages_for in active_record_helper.rb def foi_error_messages_for(*params) options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {} @@ -32,14 +35,14 @@ module ApplicationHelper html[key] = 'errorExplanation' end end - + error_messages = [] for object in objects object.errors.each do |attr, message| error_messages << content_tag(:li, message) end end - + content_tag(:div, content_tag(:ul, error_messages), html @@ -48,7 +51,7 @@ module ApplicationHelper '' end end - + # Highlight words, also escapes HTML (other than spans that we add) def highlight_words(t, words, html = true) if html @@ -70,10 +73,10 @@ module ApplicationHelper t = highlight_words(t, words, html) return t end - + def locale_name(locale) return LanguageNames::get_language_name(locale) - end + end # Use our own algorithm for finding path of cache def foi_cache(name = {}, options = nil, &block) @@ -100,11 +103,11 @@ module ApplicationHelper def sanitized_object_name(object_name) object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") end - + def sanitized_method_name(method_name) method_name.sub(/\?$/, "") end - + def form_tag_id(object_name, method_name, locale=nil) if locale.nil? return "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" @@ -113,5 +116,21 @@ module ApplicationHelper end end + def admin_value(v) + if v.nil? + nil + elsif v.instance_of?(Time) + admin_date(v) + else + h(v) + end + end + + def admin_date(date) + ago_text = _('{{length_of_time}} ago', :length_of_time => time_ago_in_words(date)) + exact_date = I18n.l(date, :format => "%e %B %Y %H:%M:%S") + return "#{exact_date} (#{ago_text})" + end + end |