Skip to content

Commit

Permalink
Merge pull request #1847 from resolve/backend_separate_meta_informati…
Browse files Browse the repository at this point in the history
…on_from_page_title

Placed view logic in the view.
  • Loading branch information
ugisozols committed Jul 30, 2012
2 parents f1b6717 + 576545c commit 97f897d
Show file tree
Hide file tree
Showing 7 changed files with 89 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
49 changes: 49 additions & 0 deletions pages/spec/helpers/refinery/pages/admin/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,55 @@ module Admin
end
end
end

describe "#page_meta_information" do
let(:page) { FactoryGirl.build(:page) }

context "when show_in_menu is false" do
it "adds 'hidden' label" do
page.show_in_menu = false

helper.page_meta_information(page).should eq("<span class=\"label\">hidden</span>")
end
end

context "when draft is true" do
it "adds 'draft' label" do
page.draft = true

helper.page_meta_information(page).should eq("<span class=\"label notice\">draft</span>")
end
end
end

describe "#page_title_with_translations" do
let(:page) { FactoryGirl.build(:page) }

before do
Globalize.with_locale(:en) do
page.title = "draft"
page.save!
end

Globalize.with_locale(:lv) do
page.title = "melnraksts"
page.save!
end
end

context "when title is present" do
it "returns it" do
helper.page_title_with_translations(page).should eq("draft")
end
end

context "when title for current locale isn't available" do
it "returns existing title from translations" do
Refinery::Page::Translation.where(:locale => :en).first.delete
helper.page_title_with_translations(page).should eq("melnraksts")
end
end
end
end
end
end

0 comments on commit 97f897d

Please sign in to comment.