Skip to content

Commit

Permalink
Merge pull request #1700 from resolve/issue_1457
Browse files Browse the repository at this point in the history
Fixes #1457
  • Loading branch information
robyurkowski committed May 25, 2012
2 parents c763641 + 7c2d0a7 commit 6fcbef7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 26 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 2.1.0 [unreleased]

* Added `Refinery::Page#canonical_slug` to allow us to retrieve a consistent slug across multiple translations of a page. Useful for CSS selectors. [#1457](https://github.com/resolve/refinerycms/issues/1457) [Philip Arndt](https://github.com/parndt)

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

## 2.0.5 [unreleased]
Expand Down
3 changes: 0 additions & 3 deletions core/app/assets/stylesheets/refinery/home.css.scss

This file was deleted.

12 changes: 7 additions & 5 deletions core/app/views/refinery/_content_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%= render_content_page(@page, {
:hide_sections => local_assigns[:hide_sections],
:can_use_fallback => !local_assigns[:show_empty_sections] && !local_assigns[:remove_automatic_sections]
}) %>
<%= render :partial => '/refinery/draft_page_message' unless @page.nil? or @page.live? -%>
<section id='<%= [@page.try(:canonical_slug), 'page'].compact.join('-') %>'>
<%= render_content_page(@page, {
:hide_sections => local_assigns[:hide_sections],
:can_use_fallback => !local_assigns[:show_empty_sections] && !local_assigns[:remove_automatic_sections]
}) %>
<%= render :partial => '/refinery/draft_page_message' unless @page.try(:live?) -%>
</section>
2 changes: 1 addition & 1 deletion doc/guides/1 - Getting Started/2 - Getting Started.textile
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ body {
}
</erb>

TIP: When on the home page of your site, Refinery automatically loads an extra stylesheet located in +app/assets/stylesheets/home.css.scss+ as often sites have a different style on the home page.
TIP: You can add CSS for specific pages by using their slug with -page. The default for the home page is 'home-page'.

Now when you view your front end at "http://localhost:3000":http://localhost:3000 you'll notice your site has a grey background, with a horizontal menu and two white content areas.

Expand Down
9 changes: 8 additions & 1 deletion pages/app/models/refinery/page.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Encoding: utf-8
require 'refinerycms-core'
require 'acts_as_indexed'
require 'friendly_id'

module Refinery
class Page < Refinery::Core::BaseModel
class Page < Core::BaseModel
extend FriendlyId

# when collecting the pages path how is each of the pages seperated?
Expand Down Expand Up @@ -166,6 +167,12 @@ def canonical
Globalize.with_locale(::Refinery::I18n.default_frontend_locale){ url }
end

# The canonical slug for this particular page.
# This is the slug for the default frontend locale.
def canonical_slug
Globalize.with_locale(::Refinery::I18n.default_frontend_locale) { slug }
end

# Returns in cascading order: custom_slug or menu_title or title depending on
# which attribute is first found to be present for this page.
def custom_slug_or_title
Expand Down
1 change: 0 additions & 1 deletion pages/app/views/refinery/pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<% content_for :stylesheets, stylesheet_link_tag('refinery/home') %>
<%= render '/refinery/content_page' %>
57 changes: 42 additions & 15 deletions pages/spec/models/refinery/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def turn_on_marketable_urls
end
end

describe '#canonical' do
context 'canonicals' do
before do
::Refinery::I18n.stub(:default_frontend_locale).and_return(:en)
::Refinery::I18n.stub(:frontend_locales).and_return([Refinery::I18n.default_frontend_locale, :ru])
Expand All @@ -115,26 +115,53 @@ def turn_on_marketable_urls
let(:page_title) { 'team' }
let(:child_title) { 'about' }
let(:ru_page_title) { 'Новости' }
let!(:default_canonical) {
Globalize.with_locale(::Refinery::I18n.default_frontend_locale) {
page.canonical

describe '#canonical' do
let!(:default_canonical) {
Globalize.with_locale(::Refinery::I18n.default_frontend_locale) {
page.canonical
}
}
}

specify 'page returns itself' do
page.canonical.should == page.url
end
specify 'page returns itself' do
page.canonical.should == page.url
end

specify 'default canonical matches page#canonical' do
default_canonical.should == page.canonical
specify 'default canonical matches page#canonical' do
default_canonical.should == page.canonical
end

specify 'translated page returns master page' do
Globalize.with_locale(:ru) do
page.title = ru_page_title
page.save

page.canonical.should == default_canonical
end
end
end

specify 'translated page returns master page' do
Globalize.with_locale(:ru) do
page.title = ru_page_title
page.save
describe '#canonical_slug' do
let!(:default_canonical_slug) {
Globalize.with_locale(::Refinery::I18n.default_frontend_locale) {
page.canonical_slug
}
}
specify 'page returns its own slug' do
page.canonical_slug.should == page.slug
end

page.canonical.should == default_canonical
specify 'default canonical_slug matches page#canonical' do
default_canonical_slug.should == page.canonical_slug
end

specify "translated page returns master page's slug'" do
Globalize.with_locale(:ru) do
page.title = ru_page_title
page.save

page.canonical_slug.should == default_canonical_slug
end
end
end
end
Expand Down

0 comments on commit 6fcbef7

Please sign in to comment.