Skip to content
Browse files

Merge pull request #1700 from resolve/issue_1457

Fixes #1457
  • Loading branch information...
2 parents c763641 + 7c2d0a7 commit 6fcbef7af25b4ecd31c1efdd7a3446293b2ca79c @robyurkowski robyurkowski committed
View
2 changelog.md
@@ -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]
View
3 core/app/assets/stylesheets/refinery/home.css.scss
@@ -1,3 +0,0 @@
-/*
- These only apply to the homepage of your site.
-*/
View
12 core/app/views/refinery/_content_page.html.erb
@@ -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>
View
2 doc/guides/1 - Getting Started/2 - Getting Started.textile
@@ -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.
View
9 pages/app/models/refinery/page.rb
@@ -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?
@@ -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
View
1 pages/app/views/refinery/pages/home.html.erb
@@ -1,2 +1 @@
-<% content_for :stylesheets, stylesheet_link_tag('refinery/home') %>
<%= render '/refinery/content_page' %>
View
57 pages/spec/models/refinery/page_spec.rb
@@ -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])
@@ -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

0 comments on commit 6fcbef7

Please sign in to comment.
Something went wrong with that request. Please try again.