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.

Conflicts:

	changelog.md
	pages/app/models/refinery/page.rb
  • Loading branch information
parndt authored and ugisozols committed Aug 1, 2012
1 parent 49257e5 commit 1aac1b2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
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
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
Expand Up @@ -420,21 +420,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 << "<em>(#{::I18n.t('hidden', :scope => 'refinery.admin.pages.page')})</em>" unless show_in_menu?
title << "<em>(#{::I18n.t('draft', :scope => 'refinery.admin.pages.page')})</em>" 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
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
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 1aac1b2

Please sign in to comment.