Skip to content

Commit 97f897d

Browse files
committed
Merge pull request #1847 from resolve/backend_separate_meta_information_from_page_title
Placed view logic in the view.
2 parents f1b6717 + 576545c commit 97f897d

File tree

7 files changed

+89
-20
lines changed

7 files changed

+89
-20
lines changed

changelog.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
* Refactored wysiwyg fields into a partial. [#1796](https://github.com/resolve/refinerycms/pull/1796). [Rob Yurkowski](https://github.com/robyurkowski)
44
* Shortened all authentication helpers. [#1719](https://github.com/resolve/refinerycms/pull/1719). [Ryan Bigg](https://github.com/radar)
5-
* 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/)
5+
* 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/)
6+
* 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)
67

78
* [See full list](https://github.com/resolve/refinerycms/compare/2-0-stable...master)
89

pages/app/controllers/refinery/admin/pages_dialogs_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module Refinery
44
module Admin
55
class PagesDialogsController < ::Refinery::Admin::DialogsController
66

7+
helper :'refinery/admin/pages'
8+
79
def link_to
810
# Get the switch_local variable to determine the locale we're currently editing
911
# Set up Globalize with our current locale

pages/app/helpers/refinery/admin/pages_helper.rb

+25
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@ def template_options(template_type, current_page)
2222
{ :selected => Refinery::Pages.send("#{template_type}_whitelist").first }
2323
end
2424
end
25+
26+
# In the admin area we use a slightly different title
27+
# to inform the which pages are draft or hidden pages
28+
def page_meta_information(page)
29+
meta_information = ActiveSupport::SafeBuffer.new
30+
meta_information << content_tag(:span, :class => 'label') do
31+
::I18n.t('hidden', :scope => 'refinery.admin.pages.page')
32+
end unless page.show_in_menu?
33+
34+
meta_information << content_tag(:span, :class => 'label notice') do
35+
::I18n.t('draft', :scope => 'refinery.admin.pages.page')
36+
end if page.draft?
37+
38+
meta_information.html_safe
39+
end
40+
41+
# We show the title from the next available locale
42+
# if there is no title for the current locale
43+
def page_title_with_translations(page)
44+
if page.title.present?
45+
page.title
46+
else
47+
page.translations.detect {|t| t.title.present?}.title
48+
end
49+
end
2550
end
2651
end
2752
end

pages/app/models/refinery/page.rb

-15
Original file line numberDiff line numberDiff line change
@@ -383,21 +383,6 @@ def part_with_title(part_title)
383383
end
384384
end
385385

386-
# In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
387-
# We show the title from the next available locale if there is no title for the current locale
388-
def title_with_meta
389-
if self.title.present?
390-
title = [self.title]
391-
else
392-
title = [self.translations.detect {|t| t.title.present?}.title]
393-
end
394-
395-
title << "<span class='label'>#{::I18n.t('hidden', :scope => 'refinery.admin.pages.page')}</span>" unless show_in_menu?
396-
title << "<span class='label notice'>#{::I18n.t('draft', :scope => 'refinery.admin.pages.page')}</span>" if draft?
397-
398-
title.join(' ')
399-
end
400-
401386
# Used to index all the content on this page so it can be easily searched.
402387
def all_page_part_content
403388
parts.map(&:body).join(" ")

pages/app/views/refinery/admin/pages/_page.html.erb

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<% end %>
88

99
<span class='title <%= 'toggle' if page.children.present? %>'>
10-
<%= page.title_with_meta.html_safe %>
10+
<%= page_title_with_translations page %>
11+
<%= page_meta_information page %>
1112
</span>
1213
<% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
1314
<span class='locales'>
@@ -37,7 +38,10 @@
3738
:class => "cancel confirm-delete",
3839
:title => t('delete', :scope => 'refinery.admin.pages'),
3940
:data => {
40-
:confirm => t('message', :scope => 'refinery.admin.delete', :title => page.title_with_meta.gsub(/\ ?<em>.*<\/em>/, ""))
41+
:confirm => t('message',
42+
:scope => 'refinery.admin.delete',
43+
:title => page_title_with_translations(page)
44+
)
4145
},
4246
:method => :delete if page.deletable? %>
4347
</span>

pages/app/views/refinery/admin/pages_dialogs/_page_link.html.erb

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
page_link_url = "#{[request.protocol, request.host_with_port].join}#{page_link_url}" if Refinery::Pages.absolute_page_links
77
-%>
88
<li class='clearfix<%= " child#{child}" if child %><%= " linked" if linked%>' id="<%= dom_id(page_link) -%>">
9-
<%= link_to page_link.title_with_meta.html_safe, page_link_url, {
9+
<%= link_to page_link_url, {
1010
:title => t('.link_to_this_page'),
1111
:rel => page_link.title,
1212
:class => 'page_link'
13-
}.merge(link_args) %>
13+
}.merge(link_args) do %>
14+
<%= page_title_with_translations page_link %>
15+
<%= page_meta_information page_link %>
16+
<% end %>
1417
</li>
1518
<%= render :partial => 'page_link',
1619
:collection => page_link.children,

pages/spec/helpers/refinery/pages/admin/pages_helper_spec.rb

+49
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,55 @@ module Admin
4949
end
5050
end
5151
end
52+
53+
describe "#page_meta_information" do
54+
let(:page) { FactoryGirl.build(:page) }
55+
56+
context "when show_in_menu is false" do
57+
it "adds 'hidden' label" do
58+
page.show_in_menu = false
59+
60+
helper.page_meta_information(page).should eq("<span class=\"label\">hidden</span>")
61+
end
62+
end
63+
64+
context "when draft is true" do
65+
it "adds 'draft' label" do
66+
page.draft = true
67+
68+
helper.page_meta_information(page).should eq("<span class=\"label notice\">draft</span>")
69+
end
70+
end
71+
end
72+
73+
describe "#page_title_with_translations" do
74+
let(:page) { FactoryGirl.build(:page) }
75+
76+
before do
77+
Globalize.with_locale(:en) do
78+
page.title = "draft"
79+
page.save!
80+
end
81+
82+
Globalize.with_locale(:lv) do
83+
page.title = "melnraksts"
84+
page.save!
85+
end
86+
end
87+
88+
context "when title is present" do
89+
it "returns it" do
90+
helper.page_title_with_translations(page).should eq("draft")
91+
end
92+
end
93+
94+
context "when title for current locale isn't available" do
95+
it "returns existing title from translations" do
96+
Refinery::Page::Translation.where(:locale => :en).first.delete
97+
helper.page_title_with_translations(page).should eq("melnraksts")
98+
end
99+
end
100+
end
52101
end
53102
end
54103
end

0 commit comments

Comments
 (0)