cleanup articles sorted in groups

This commit is contained in:
wvengen 2014-01-21 11:55:26 +01:00
parent e88810e4a7
commit f9d2c20aaa
5 changed files with 45 additions and 25 deletions

View file

@ -78,14 +78,17 @@ module ApplicationHelper
# When the 'short' option is true, abbreviations will be used:
# When there is a non-empty model attribute 'foo', it looks for
# the model attribute translation 'foo_short' and use that as
# heading, with an abbreviation title of 'foo'.
# heading, with an abbreviation title of 'foo'. If a translation
# 'foo_desc' is present, that is used instead, but that can be
# be overridden by the option 'desc'.
# Other options are passed through to I18n.
def heading_helper(model, attribute, options = {})
i18nopts = options.select {|a| !['short'].include?(a) }.merge({count: 2})
i18nopts = options.select {|a| !['short', 'desc'].include?(a) }.merge({count: 2})
s = model.human_attribute_name(attribute, i18nopts)
if options[:short]
desc = (options[:desc] or model.human_attribute_name("#{attribute}_desc".to_sym, options.merge({fallback: true, default: '', count: 2})))
sshort = model.human_attribute_name("#{attribute}_short".to_sym, options.merge({fallback: true, default: '', count: 2}))
s = raw "<abbr title='#{s}'>#{sshort}</abbr>" unless sshort.blank?
s = raw "<abbr title='#{desc or s}'>#{sshort}</abbr>" unless sshort.blank?
end
s
end