Permalink
Browse files

Moved view method Page#title_with_meta into the view.

New Helpers:
* page_title_with_translations(page)
* page_meta_information(page)

These helpers apply to the Refinery backend when conventionally invoked.
  • Loading branch information...
1 parent 1d3bee2 commit 7dca4374087b067f7b6fa562c8123db8a0e5526e @parndt parndt committed Jul 30, 2012
View
@@ -2,7 +2,8 @@
* Refactored wysiwyg fields into a partial. [#1796](https://github.com/resolve/refinerycms/pull/1796). [Rob Yurkowski](https://github.com/robyurkowski)
* Shortened all authentication helpers. [#1719](https://github.com/resolve/refinerycms/pull/1719). [Ryan Bigg](https://github.com/radar)
-* Added canonical page id to body to allow CSS selectors to target specific pages instead of including special CSS files. [#1700](https://github.com/resolve/refinerycms/pull/1700) & [#1828](https://github.com/resolve/refinerycms/pull/1828). [Philip Arndy](https://github.com/parndt) & [Graham Wagener](https://github.com/gwagener/)
+* Added canonical page id to body to allow CSS selectors to target specific pages instead of including special CSS files. [#1700](https://github.com/resolve/refinerycms/pull/1700) & [#1828](https://github.com/resolve/refinerycms/pull/1828). [Philip Arndt](https://github.com/parndt) & [Graham Wagener](https://github.com/gwagener/)
+* Removed Refinery::Page#title_with_meta in favour of view helpers. [#1847](https://github.com/resolve/refinerycms/pull/1847). [Philip Arndt](https://github.com/parndt)
* [See full list](https://github.com/resolve/refinerycms/compare/2-0-stable...master)
@@ -4,6 +4,8 @@ module Refinery
module Admin
class PagesDialogsController < ::Refinery::Admin::DialogsController
+ helper :'refinery/admin/pages'
+
def link_to
# Get the switch_local variable to determine the locale we're currently editing
# Set up Globalize with our current locale
@@ -22,6 +22,31 @@ def template_options(template_type, current_page)
{ :selected => Refinery::Pages.send("#{template_type}_whitelist").first }
end
end
+
+ # In the admin area we use a slightly different title
+ # to inform the which pages are draft or hidden pages
+ def page_meta_information(page)
+ meta_information = ActiveSupport::SafeBuffer.new
+ meta_information << content_tag(:span, :class => 'label') do
+ ::I18n.t('hidden', :scope => 'refinery.admin.pages.page')
+ end unless page.show_in_menu?
+
+ meta_information << content_tag(:span, :class => 'label notice') do
+ ::I18n.t('draft', :scope => 'refinery.admin.pages.page')
+ end if page.draft?
+
+ meta_information.html_safe
+ end
+
+ # We show the title from the next available locale
+ # if there is no title for the current locale
+ def page_title_with_translations(page)
+ if page.title.present?
+ page.title
+ else
+ page.translations.detect {|t| t.title.present?}.title
+ end
+ end
end
end
end
@@ -383,21 +383,6 @@ def part_with_title(part_title)
end
end
- # In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
- # We show the title from the next available locale if there is no title for the current locale
- def title_with_meta
- if self.title.present?
- title = [self.title]
- else
- title = [self.translations.detect {|t| t.title.present?}.title]
- end
-
- title << "<span class='label'>#{::I18n.t('hidden', :scope => 'refinery.admin.pages.page')}</span>" unless show_in_menu?
- title << "<span class='label notice'>#{::I18n.t('draft', :scope => 'refinery.admin.pages.page')}</span>" if draft?
-
- title.join(' ')
- end
-
# Used to index all the content on this page so it can be easily searched.
def all_page_part_content
parts.map(&:body).join(" ")
@@ -7,7 +7,8 @@
<% end %>
<span class='title <%= 'toggle' if page.children.present? %>'>
- <%= page.title_with_meta.html_safe %>
+ <%= page_title_with_translations page %>
+ <%= page_meta_information page %>
</span>
<% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
<span class='locales'>
@@ -37,7 +38,10 @@
:class => "cancel confirm-delete",
:title => t('delete', :scope => 'refinery.admin.pages'),
:data => {
- :confirm => t('message', :scope => 'refinery.admin.delete', :title => page.title_with_meta.gsub(/\ ?<em>.*<\/em>/, ""))
+ :confirm => t('message',
+ :scope => 'refinery.admin.delete',
+ :title => page_title_with_translations(page)
+ )
},
:method => :delete if page.deletable? %>
</span>
@@ -6,11 +6,14 @@
page_link_url = "#{[request.protocol, request.host_with_port].join}#{page_link_url}" if Refinery::Pages.absolute_page_links
-%>
<li class='clearfix<%= " child#{child}" if child %><%= " linked" if linked%>' id="<%= dom_id(page_link) -%>">
- <%= link_to page_link.title_with_meta.html_safe, page_link_url, {
+ <%= link_to page_link_url, {
:title => t('.link_to_this_page'),
:rel => page_link.title,
:class => 'page_link'
- }.merge(link_args) %>
+ }.merge(link_args) do %>
+ <%= page_title_with_translations page_link %>
+ <%= page_meta_information page_link %>
+ <% end %>
</li>
<%= render :partial => 'page_link',
:collection => page_link.children,

0 comments on commit 7dca437

Please sign in to comment.