Module: ImplicitPageTitles::PageTitleHelper
- Defined in:
- lib/implicit_page_titles/page_title_helper.rb
Instance Method Summary collapse
- #_current_path ⇒ Object
- #_implicit_variable_title ⇒ Object
- #_path_without_last_segment(path) ⇒ Object
- #default_page_title ⇒ Object
- #page_title(page_title = nil) ⇒ Object
- #path_to_page_title(path = _current_path) ⇒ Object
- #restful_page_title ⇒ Object
Instance Method Details
#_current_path ⇒ Object
34 35 36 |
# File 'lib/implicit_page_titles/page_title_helper.rb', line 34 def _current_path request.try :path end |
#_implicit_variable_title ⇒ Object
44 45 46 47 48 49 |
# File 'lib/implicit_page_titles/page_title_helper.rb', line 44 def _implicit_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 |
#_path_without_last_segment(path) ⇒ Object
38 39 40 41 42 |
# File 'lib/implicit_page_titles/page_title_helper.rb', line 38 def _path_without_last_segment(path) path = path.to_s index = path.rindex("/") index ? path[0, index] : nil end |
#default_page_title ⇒ Object
30 31 32 |
# File 'lib/implicit_page_titles/page_title_helper.rb', line 30 def default_page_title Rails.application.class.to_s.split("::").first.underscore.humanize end |
#page_title(page_title = nil) ⇒ Object
3 4 5 6 |
# File 'lib/implicit_page_titles/page_title_helper.rb', line 3 def page_title(page_title = nil) @page_title = page_title unless page_title.nil? @page_title || restful_page_title || path_to_page_title || default_page_title end |
#path_to_page_title(path = _current_path) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/implicit_page_titles/page_title_helper.rb', line 21 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 |
#restful_page_title ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/implicit_page_titles/page_title_helper.rb', line 8 def restful_page_title case action_name when "show" _implicit_variable_title when "edit" "Edit #{_implicit_variable_title}" when "new" path = _path_without_last_segment(_current_path) title = path_to_page_title(path).to_s.singularize "New #{title}" end end |