Skip to content

Commit

Permalink
Moved view method Page#title_with_meta into the view.
Browse files Browse the repository at this point in the history
New Helpers:
* page_title_with_translations(page)
* page_meta_information(page)

These helpers apply to the Refinery backend when conventionally invoked.
  • Loading branch information
parndt committed Jul 30, 2012
1 parent 1d3bee2 commit 7dca437
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pages/app/helpers/refinery/admin/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 0 additions & 15 deletions pages/app/models/refinery/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")
Expand Down
8 changes: 6 additions & 2 deletions pages/app/views/refinery/admin/pages/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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'>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7dca437

Please sign in to comment.