module AutomaticPageTitles::PageTitleHelper

Public Instance Methods

admin_prefix() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 77
def admin_prefix
  current_path = request.try :path
  return '' unless current_path.to_s.match?(%r{\/admin\/})
  "Administrator - "
end
automatic_variable_title() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 65
def automatic_variable_title
  return unless controller && controller_name
  var_name = "@" + controller_name.singularize
  variable = controller.instance_variable_get(var_name)
  variable.try(:title) || variable.try(:name)
end
controller_title() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 33
def controller_title
  controller_name.titleize
end
controller_title_singular() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 37
def controller_title_singular
  controller_title.singularize
end
current_path() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 55
def current_path
  request.try :path
end
custom_action_page_title() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 25
def custom_action_page_title
  if params[:id].present?
    "#{action_name.titleize} #{controller_title_singular}#{padded_automatic_variable_title}"
  else
    "#{action_name.titleize} #{controller_title}"
  end
end
default_page_title() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 51
def default_page_title
  Rails.application.class.to_s.split("::").first.underscore.humanize
end
padded_automatic_variable_title() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 72
def padded_automatic_variable_title
  return "" if automatic_variable_title.blank?
  ": #{automatic_variable_title}"
end
page_title(page_title = nil) click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 3
def page_title(page_title = nil)
  "#{admin_prefix}#{page_title_no_admin_prefix(page_title)}"
end
page_title_no_admin_prefix(page_title = nil) click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 7
def page_title_no_admin_prefix(page_title = nil)
  @page_title = page_title unless page_title.nil?
  @page_title || restful_page_title || custom_action_page_title
end
path_to_page_title(path = current_path) click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 42
def path_to_page_title(path = current_path)
  title = path.to_s.split("/").last
  return nil if title.nil?

  title = title.gsub(/[-_]/, " ")
  title = title.gsub(/\s+/, " ").strip
  title.humanize
end
path_without_last_segment(path) click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 59
def path_without_last_segment(path)
  path  = path.to_s
  index = path.rindex("/")
  index ? path[0, index] : nil
end
restful_page_title() click to toggle source
# File lib/automatic_page_titles/page_title_helper.rb, line 12
def restful_page_title
  case action_name
  when "index"
    controller_title
  when "show"
    "#{controller_title_singular}#{padded_automatic_variable_title}"
  when "edit", "update"
    "Edit #{controller_title_singular}#{padded_automatic_variable_title}"
  when "new", "create"
    "New #{controller_title_singular}"
  end
end