Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed Page#[] for Page#content_for() and refactored internals of pa…

…ge. Documented some changes so far.
  • Loading branch information...
commit edc09a840177553e669e3e82cf51c399cbd9c23c 1 parent ed72ab3
@parndt parndt authored
View
6 changelog.md
@@ -1,3 +1,9 @@
+## 1.1.0 [unreleased]
+
+* Finally removed `Page#[]` in favour of `Page#content_for` so instead of `@page[:body]` it's `@page.content_for(:body)`. [Philip Arndt](https://github.com/parndt)
+* Migrated to [Kaminari](https://github.com/amatsuda/kaminari) for pagination. [Uģis Ozols](https://github.com/ugisozols)
+* Moved everything under Refinery namespace. [wakeless](https://github.com/wakeless)
+
## 0.9.9.22 [22 May 2011]
* Fixed issue introduced with `rake 0.9.0`. [Philip Arndt](https://github.com/parndt)
View
2  core/lib/refinery/helpers/image_helper.rb
@@ -3,7 +3,7 @@ module Helpers
module ImageHelper
# replace all system images with a thumbnail version of them (handy for all images inside a page part)
- # for example, <%= content_fu(@page[:body], '96x96#c') %> converts all /system/images to a 96x96 cropped thumbnail
+ # for example, <%= content_fu(@page.content_for(:body), '96x96#c') %> converts all /system/images to a 96x96 cropped thumbnail
def content_fu(content, thumbnail)
content.gsub(%r{<img.+?src=['"](/system/images/.+?)/.+?/>}) do |image_match|
begin
View
6 doc/guides/1 - Getting Started/1 - Getting Started with Refinery.textile
@@ -205,10 +205,10 @@ Replace the contents of +app/views/pages/show.html.erb+ with this:
<erb>
<section id='body_content'>
- <%=raw @page[:body] %>
+ <%=raw @page.content_for(:body) %>
</section>
<section id='side_body_content'>
- <%=raw @page[:side_body] %>
+ <%=raw @page.content_for(:side_body) %>
</section>
</erb>
@@ -223,7 +223,7 @@ When you edit the about page you'll see something like this:
You'll notice two tabs on the page "Body" and "Side Body". These are +Page Parts+, or in other words a single piece of content attached to this page that you can render in your view. There is a "Body" tab with some content on this screen, to render that same content in your view you put:
<erb>
-<%=raw @page[:body] %>
+<%=raw @page.content_for(:body) %>
</erb>
h4. Styling your views
View
2  doc/guides/4 - Customising your Design/1 - How to change Page Parts.textile
@@ -47,7 +47,7 @@ NOTE: Your "middle body" content won't show on the front end yet. You need to ou
Now in your +app/views/pages/home.html.erb+ view you'll be able to put:
<erb>
-<%= @page[:middle_body] %>
+<%= @page.content_for(:middle_body) %>
</erb>
to output this new content area in the view.
View
2  doc/images.md
@@ -24,7 +24,7 @@ If I wanted to replace all the images inside a content section without the user
having to resize images in the editor then I would use the built in ``content_fu``
command like this in my view:
- <%= content_fu @page[:body], '400x300' %>
+ <%= content_fu @page.content_for(:body), '400x300' %>
``content_fu`` is a command we have created that automatically changes all images
with the url /system/images to use a particular size.
View
53 pages/app/models/refinery/page.rb
@@ -7,13 +7,12 @@ class Page < ActiveRecord::Base
translates :title, :custom_title, :meta_keywords, :meta_description, :browser_title, :include => :seo_meta
# Set up support for meta tags through translations.
- if defined?(::Page::Translation)
+ if self.respond_to?(:translation_class)
attr_accessible :title
# set allowed attributes for mass assignment
- ::Page::Translation.send :attr_accessible, :browser_title, :meta_description,
- :meta_keywords, :locale
+ self.translation_class.send :attr_accessible, :browser_title, :meta_description, :meta_keywords, :locale
- if ::Page::Translation.table_exists?
+ if self.translation_class.table_exists?
def translation
if @translation.nil? or @translation.try(:locale) != ::Globalize.locale
@translation = translations.with_locale(::Globalize.locale).first
@@ -23,8 +22,8 @@ def translation
@translation
end
- # Instruct the Translation model to have meta tags.
- ::Page::Translation.send :is_seo_meta
+ # Instruct the translation_class model to have meta tags.
+ self.translation_class.send :is_seo_meta
fields = ::SeoMeta.attributes.keys.reject{|f|
self.column_names.map(&:to_sym).include?(f)
@@ -32,6 +31,17 @@ def translation
delegate *(fields << {:to => :translation})
after_save proc {|m| m.translation.save}
end
+
+ # Wrap up the logic of finding the pages based on the translations table.
+ def self.with_globalize(conditions = {})
+ conditions = {:locale => Globalize.locale}.merge(conditions)
+ where(:id => translation_class.where(conditions).select('page_id AS id')).includes(:children, :slugs)
+ end
+ else
+ # No translations, just default to normal behaviour.
+ def self.with_globalize(conditions = {})
+ where(conditions).includes(:children, :slugs)
+ end
end
before_create :ensure_locale, :if => proc { |c|
@@ -59,11 +69,11 @@ def translation
:strip_non_ascii => RefinerySetting.find_or_set(:strip_non_ascii, false, :scoping => "pages")
has_many :parts,
- :class_name => "PagePart",
+ :class_name => "::Refinery::PagePart",
:order => "position ASC",
:inverse_of => :page,
:dependent => :destroy,
- :include => ((:translations) if defined?(::PagePart::Translation))
+ :include => ((:translations) if ::Refinery::PagePart.respond_to?(:translation_class))
accepts_nested_attributes_for :parts, :allow_destroy => true
@@ -75,18 +85,6 @@ def translation
after_save :reposition_parts!, :invalidate_child_cached_url, :expire_page_caching
after_destroy :expire_page_caching
- # Wrap up the logic of finding the pages based on the translations table.
- if defined?(::Page::Translation)
- def self.with_globalize(conditions = {})
- conditions = {:locale => Globalize.locale}.merge(conditions)
- where(:id => ::Page::Translation.where(conditions).select('page_id AS id')).includes(:children, :slugs)
- end
- else
- def self.with_globalize(conditions = {})
- where(conditions).includes(:children, :slugs)
- end
- end
-
scope :live, where(:draft => false)
scope :by_title, proc {|t| with_globalize(:title => t)}
@@ -197,7 +195,7 @@ def url_marketable
end
def url_normal
- {:controller => '/pages', :action => 'show', :path => nil, :id => to_param}
+ {:controller => '/refinery/pages', :action => 'show', :path => nil, :id => to_param}
end
def with_locale_param(url_hash)
@@ -301,13 +299,10 @@ def expire_page_caching
# Accessor method to get a page part from a page.
# Example:
#
- # Page.first[:body]
+ # Page.first.content_for(:body)
#
# Will return the body page part of the first page.
- def [](part_title)
- # Allow for calling attributes with [] shorthand (eg page[:parent_id])
- return super if self.attributes.has_key?(part_title.to_s)
-
+ def content_for(part_title)
# the way that we call page parts seems flawed, will probably revert to page.parts[:title] in a future release.
# self.parts is already eager loaded so we can now just grab the first element matching the title we specified.
part = self.parts.detect do |part|
@@ -322,13 +317,13 @@ def [](part_title)
# In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
def title_with_meta
title = if self.title.nil?
- [::Page::Translation.where(:page_id => self.id, :locale => Globalize.locale).first.try(:title).to_s]
+ [self.class.with_globalize(:page_id => self.id).first.try(:title).to_s]
else
[self.title.to_s]
end
- title << "<em>(#{::I18n.t('hidden', :scope => 'admin.pages.page')})</em>" unless show_in_menu?
- title << "<em>(#{::I18n.t('draft', :scope => 'admin.pages.page')})</em>" if draft?
+ title << "<em>(#{::I18n.t('hidden', :scope => 'refinery.admin.pages.page')})</em>" unless show_in_menu?
+ title << "<em>(#{::I18n.t('draft', :scope => 'refinery.admin.pages.page')})</em>" if draft?
title.join(' ')
end
View
6 pages/app/views/refinery/admin/pages/_page_part_field.html.erb
@@ -1,5 +1,5 @@
<div class='page_part' id='<%= new_part ? "page_part_new_#{part_index}" : part.to_param %>'>
- <%= hidden_field_tag "page[parts_attributes][#{part_index}][title]", part.title if new_part %>
- <%= text_area_tag "page[parts_attributes][#{part_index}][body]", part.body, :rows => 20, :class => 'wymeditor widest' %>
- <%= hidden_field_tag "page[parts_attributes][#{part_index}][position]", part_index if new_part %>
+ <%= hidden_field_tag "page[parts_attributes)[#{part_index}][title]", part.title if new_part %>
+ <%= text_area_tag "page[parts_attributes)[#{part_index}][body]", part.body, :rows => 20, :class => 'wymeditor widest' %>
+ <%= hidden_field_tag "page[parts_attributes)[#{part_index}][position]", part_index if new_part %>
</div>
View
4 pages/lib/refinery/pages/admin/instance_methods.rb
@@ -8,8 +8,8 @@ def error_404(exception=nil)
params[:action] = 'error_404'
# change any links in the copy to the refinery_admin_root_path
# and any references to "home page" to "Dashboard"
- part_symbol = Page.default_parts.first.to_sym
- @page[part_symbol] = @page[part_symbol].to_s.gsub(
+ part_symbol = ::Refinery::Page.default_parts.first.to_sym
+ @page.content_for(part_symbol) = @page.content_for(part_symbol).to_s.gsub(
/href=(\'|\")\/(\'|\")/, "href='#{refinery_admin_root_path}'"
).gsub("home page", "Dashboard")
Please sign in to comment.
Something went wrong with that request. Please try again.