diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d9d5819..32691ea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,13 +9,36 @@ module ApplicationHelper # Get title in this order: # 1. string argument - # 2. class variable @title, typically assigned in the Controller - # 3. controller.controller_name - site.name - def title(new_title = "" ) - title = new_title.present? ? - new_title : - @title || - "#{ controller.controller_name.titleize } - #{ site.name }" + # 2. @title instance variable + # 3. Title based on variables set by the Controller + # 4. controller.controller_name - site.name + # + # Options: + # append_site_name:: Append the Site name to the title, ie, "Title - Example Site". Defaults to false + # + def title(new_title = "", options = {}) + title = if new_title.present? + new_title + elsif @title + @title + elsif @contents + container ? + t(:other_in_container, :scope => controller.controller_name.singularize) : + t(:other, :scope => controller.controller_name.singularize) + elsif @resources + t(:other, :scope => controller.controller_name.singularize) + elsif @resource + if @resource.new_record? + t(:new, :scope => @resource.class.to_s.underscore) + elsif controller.action_name == 'edit' || @resource.errors.any? + t(:editing, :scope => @resource.class.to_s.underscore) + else + @resource.title + end + else + controller.controller_name.titleize + end + title << " - #{ site.name }" if options[:append_site_name] sanitize(title) end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 52470fc..34b6cb2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,7 +2,7 @@ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> - <%= title %> + <%= title :append_site_name => true %>