diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/public_body_helper.rb | 26 | ||||
-rw-r--r-- | app/models/public_body.rb | 25 | ||||
-rw-r--r-- | app/views/public_body/show.html.erb | 2 |
3 files changed, 27 insertions, 26 deletions
diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb index d8a5d57b5..cb4b71cb3 100644 --- a/app/helpers/public_body_helper.rb +++ b/app/helpers/public_body_helper.rb @@ -32,4 +32,30 @@ module PublicBodyHelper reasons.compact end + # Use tags to describe what type of authority a PublicBody is. + # + # public_body - Instance of a PublicBody + # + # Returns a string + def type_of_authority(public_body) + types = public_body.tags.each_with_index.map do |tag, index| + if PublicBodyCategory.get().by_tag().include?(tag.name) + desc = PublicBodyCategory.get().singular_by_tag()[tag.name] + + if index.zero? + desc = desc.sub(/\S/) { |m| Unicode.upcase(m) } + end + link_to(desc, list_public_bodies_path(tag.name)) + end + end + + types.compact! + + if types.any? + types.to_sentence(:last_word_connector => ' and ').html_safe + else + _("A public authority") + end + end + end diff --git a/app/models/public_body.rb b/app/models/public_body.rb index b9519c1aa..0e90a3c16 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -345,31 +345,6 @@ class PublicBody < ActiveRecord::Base end end - - # Use tags to describe what type of thing this is - def type_of_authority - types = tags.each_with_index.map do |tag, index| - if PublicBodyCategory.get().by_tag().include?(tag.name) - desc = PublicBodyCategory.get().singular_by_tag()[tag.name] - - if index.zero? - desc = desc.sub(/\S/) { |m| Unicode.upcase(m) } - end - # TODO: this should call proper route helpers, but is in model sigh - desc = '<a href="/body/list/' + tag.name + '">' + desc + '</a>' - desc - end - end - - types.compact! - - if types.any? - types.to_sentence(:last_word_connector => ' and ').html_safe - else - _("A public authority") - end - end - # Guess home page from the request email, or use explicit override, or nil # if not known. def calculated_home_page diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb index bce396cd8..8d90844c0 100644 --- a/app/views/public_body/show.html.erb +++ b/app/views/public_body/show.html.erb @@ -32,7 +32,7 @@ <h1><%=h(@public_body.name)%></h1> <p class="subtitle"> - <%= @public_body.type_of_authority %><% if not @public_body.short_name.empty? %>, + <%= type_of_authority(@public_body) %><% if not @public_body.short_name.empty? %>, <%= _('also called {{public_body_short_name}}', :public_body_short_name => h(@public_body.short_name))%><% end %> <% if !@user.nil? && @user.admin_page_links? %> (<%= link_to _("admin"), admin_body_path(@public_body) %>) |