Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes #1457 #1700

Merged
merged 5 commits into from

3 participants

Philip Arndt Rob Yurkowski Don't Add Me To Your Organization a.k.a The Travis Bot
Philip Arndt
Owner

No description provided.

Rob Yurkowski
Collaborator

:+1: :heart:

Rob Yurkowski robyurkowski merged commit 6fcbef7 into from
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged b2a9a84 into 33878c5).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged bf0c7b0 into 33878c5).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 7c2d0a7 into 33878c5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 25, 2012
  1. Philip Arndt

    Added support for @canonical in pages_controller.

    parndt authored
    Fixes #1472
    
    Conflicts:
    
    	pages/app/models/refinery/page.rb
  2. Philip Arndt
  3. Philip Arndt

    Added Refinery::Page#canonical_slug to allow us to have the same slug…

    parndt authored
    … for multiple translations of a page.
    
    * We won't be needing home.css.scss anymore; Use #home-page
  4. Philip Arndt

    Documented canonical_slug

    parndt authored
  5. Philip Arndt
This page is out of date. Refresh to see the latest.
2  changelog.md
View
@@ -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]
3  core/app/assets/stylesheets/refinery/home.css.scss
View
@@ -1,3 +0,0 @@
-/*
- These only apply to the homepage of your site.
-*/
12 core/app/views/refinery/_content_page.html.erb
View
@@ -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>
6 core/app/views/refinery/_head.html.erb
View
@@ -2,9 +2,9 @@
<meta charset='<%= Rails.application.config.encoding %>' />
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><![endif]-->
<title><%= browser_title(yield(:title)) %></title>
- <%= raw(%(<meta name="description" content="#{@meta.meta_description}" />)) if @meta.meta_description.present? -%>
- <%= raw(%(<meta name="keywords" content="#{@meta.meta_keywords}">)) if @meta.meta_keywords.present? -%>
- <%= raw(%(<link rel="canonical" content="#{@canonical}" />)) if @canonical.present? -%>
+ <%= raw %(<meta name="description" content="#{@meta.meta_description}" />) if @meta.meta_description.present? -%>
+ <%= raw %(<meta name="keywords" content="#{@meta.meta_keywords}">) if @meta.meta_keywords.present? -%>
+ <%= raw %(<link rel="canonical" content="#{@canonical}" />) if @canonical.present? -%>
<%= csrf_meta_tags if Refinery::Core.authenticity_token_on_frontend -%>
<%= yield :meta %>
2  doc/guides/1 - Getting Started/2 - Getting Started.textile
View
@@ -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.
6 pages/app/controllers/refinery/pages_controller.rb
View
@@ -1,6 +1,6 @@
module Refinery
class PagesController < ::ApplicationController
- before_filter :find_page, :except => [:preview]
+ before_filter :find_page, :set_canonical, :except => [:preview]
# Save whole Page after delivery
after_filter { |c| c.write_cache? }
@@ -94,6 +94,10 @@ def render_with_templates?(render_options = {})
render render_options if render_options.any?
end
+ def set_canonical
+ @canonical = refinery.url_for @page.canonical if @page.present?
+ end
+
def write_cache?
if Refinery::Pages.cache_pages_full && !refinery_user?
cache_page(response.body, File.join('', 'refinery', 'cache', 'pages', request.path.sub("//", "/")).to_s)
41 pages/app/models/refinery/page.rb
View
@@ -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?
@@ -144,7 +145,7 @@ def different_frontend_locale?
# Returns how many pages per page should there be when paginating pages
def per_page(dialog = false)
- dialog ? Pages.pages_per_dialog : Pages.config.pages_per_admin_index
+ dialog ? Pages.pages_per_dialog : Pages.pages_per_admin_index
end
def expire_page_caching
@@ -159,10 +160,23 @@ def expire_page_caching
end
end
+ # The canonical page for this particular page.
+ # Consists of:
+ # * The default locale's translated slug
+ 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
- custom_slug.presence || menu_title.presence || title.presence
+ custom_slug.presence || menu_title.presence || title
end
# Am I allowed to delete this page?
@@ -256,7 +270,7 @@ def link_url_localised?
# For example, this might evaluate to /about for the "About" page.
def url_marketable
# :id => nil is important to prevent any other params[:id] from interfering with this route.
- url_normal.merge(:path => nested_url, :id => nil)
+ url_normal.merge :path => nested_url, :id => nil
end
# Returns a url suitable to be used in url_for in Rails (such as link_to).
@@ -267,26 +281,23 @@ def url_normal
# If the current locale is set to something other than the default locale
# then the :locale attribute will be set on the url hash, otherwise it won't be.
- def with_locale_param(url_hash)
- if self.class.different_frontend_locale?
- url_hash.update(:locale => (::Refinery::I18n.current_frontend_locale if Refinery.i18n_enabled?))
- end
+ def with_locale_param(url_hash, locale = nil)
+ locale ||= ::Refinery::I18n.current_frontend_locale if self.class.different_frontend_locale?
+ url_hash.update :locale => locale if locale
url_hash
end
+ def uncached_nested_url
+ [parent.try(:uncached_nested_url), to_param.to_s].compact.flatten
+ end
+
# Returns an array with all ancestors to_param, allow with its own
# Ex: with an About page and a Mission underneath,
# ::Refinery::Page.find('mission').nested_url would return:
#
# ['about', 'mission']
#
- def nested_url
- Rails.cache.fetch(url_cache_key) { uncached_nested_url }
- end
-
- def uncached_nested_url
- [parent.try(:nested_url), to_param.to_s].compact.flatten
- end
+ alias_method :nested_url, :uncached_nested_url
# Returns the string version of nested_url, i.e., the path that should be generated
# by the router
10 pages/app/views/refinery/admin/pages/_page.html.erb
View
@@ -11,11 +11,9 @@
<% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
<span class='preview'>
<% page.translations.each do |translation| %>
- <% if translation.title.present? %>
- <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
- refinery.edit_admin_page_path(page, :switch_locale => translation.locale),
- :class => 'locale' %>
- <% end %>
+ <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
+ refinery.edit_admin_page_path(page, :switch_locale => translation.locale),
+ :class => 'locale' if translation.title.present? %>
<% end %>
</span>
<% end %>
@@ -23,7 +21,7 @@
<span class='actions'>
<%= link_to refinery_icon_tag('application_go.png'),
- refinery.page_path(page),
+ refinery.page_path(page.uncached_nested_url),
:target => "_blank",
:title => t('.view_live_html') %>
<%= link_to refinery_icon_tag('page_add.png'),
1  pages/app/views/refinery/pages/home.html.erb
View
@@ -1,2 +1 @@
-<% content_for :stylesheets, stylesheet_link_tag('refinery/home') %>
<%= render '/refinery/content_page' %>
63 pages/spec/models/refinery/page_spec.rb
View
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'spec_helper'
module Refinery
@@ -103,6 +104,68 @@ def turn_on_marketable_urls
end
end
+ 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])
+ ::Refinery::I18n.stub(:current_frontend_locale).and_return(Refinery::I18n.default_frontend_locale)
+
+ page.save
+ end
+ let(:page_title) { 'team' }
+ let(:child_title) { 'about' }
+ let(:ru_page_title) { 'Новости' }
+
+ 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 '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
+
+ 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
+
+ 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
+
context 'custom slugs' do
let(:custom_page_slug) { 'custom-page-slug' }
let(:custom_child_slug) { 'custom-child-slug' }
Something went wrong with that request. Please try again.