refinerycms-pages 0.9.9.19 → 0.9.9.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ module Admin
4
4
  crudify :page,
5
5
  :conditions => nil,
6
6
  :order => "lft ASC",
7
- :include => [:slugs, :translations],
7
+ :include => [:slugs, :translations, :children],
8
8
  :paging => false
9
9
 
10
10
  rescue_from FriendlyId::ReservedError, :with => :show_errors_for_reserved_slug
@@ -20,7 +20,7 @@ class PagesController < ApplicationController
20
20
 
21
21
  if @page.try(:live?) || (refinery_user? && current_user.authorized_plugins.include?("refinery_pages"))
22
22
  # if the admin wants this to be a "placeholder" page which goes to its first child, go to that instead.
23
- if @page.skip_to_first_child && (first_live_child = @page.children.order('lft ASC').where(:draft=>false).first).present?
23
+ if @page.skip_to_first_child && (first_live_child = @page.children.order('lft ASC').live.first).present?
24
24
  redirect_to first_live_child.url
25
25
  elsif @page.link_url.present?
26
26
  redirect_to @page.link_url and return
@@ -2,47 +2,52 @@ require 'globalize3'
2
2
 
3
3
  class Page < ActiveRecord::Base
4
4
 
5
- translates :title, :meta_keywords, :meta_description, :browser_title, :custom_title if self.respond_to?(:translates)
5
+ if self.respond_to?(:translates)
6
+ translates :title, :custom_title, :meta_keywords, :meta_description, :browser_title, :include => :seo_meta
6
7
 
7
- attr_accessible :id, :deletable, :link_url, :menu_match, :meta_keywords,
8
- :skip_to_first_child, :position, :show_in_menu, :draft,
9
- :parts_attributes, :browser_title, :meta_description,
10
- :custom_title_type, :parent_id, :custom_title,
11
- :created_at, :updated_at, :page_id
12
-
13
- # Set up support for meta tags through translations.
14
- if defined?(::Page::Translation)
15
- attr_accessible :title
16
- # set allowed attributes for mass assignment
17
- ::Page::Translation.module_eval do
18
- attr_accessible :browser_title, :meta_description, :meta_keywords,
19
- :locale
20
- end
21
- if ::Page::Translation.table_exists?
22
- def translation
23
- if @translation.nil? or @translation.try(:locale) != ::Globalize.locale
24
- @translation = translations.with_locale(::Globalize.locale).first
25
- @translation ||= translations.build(:locale => ::Globalize.locale)
8
+ # Set up support for meta tags through translations.
9
+ if defined?(::Page::Translation)
10
+ attr_accessible :title
11
+ # set allowed attributes for mass assignment
12
+ ::Page::Translation.send :attr_accessible, :browser_title, :meta_description,
13
+ :meta_keywords, :locale
14
+
15
+ if ::Page::Translation.table_exists?
16
+ def translation
17
+ if @translation.nil? or @translation.try(:locale) != ::Globalize.locale
18
+ @translation = translations.with_locale(::Globalize.locale).first
19
+ @translation ||= translations.build(:locale => ::Globalize.locale)
20
+ end
21
+
22
+ @translation
26
23
  end
27
24
 
28
- @translation
29
- end
25
+ # Instruct the Translation model to have meta tags.
26
+ ::Page::Translation.send :is_seo_meta
30
27
 
31
- # Instruct the Translation model to have meta tags.
32
- ::Page::Translation.send :is_seo_meta
33
-
34
- # Delegate all SeoMeta attributes to the active translation.
35
- fields = ::SeoMeta.attributes.keys.map{|a| [a, :"#{a}="]}.flatten
36
- fields << {:to => :translation}
37
- delegate *fields
38
- after_save proc {|m| m.translation.save}
28
+ fields = ::SeoMeta.attributes.keys.reject{|f|
29
+ self.column_names.map(&:to_sym).include?(f)
30
+ }.map{|a| [a, :"#{a}="]}.flatten
31
+ delegate *(fields << {:to => :translation})
32
+ after_save proc {|m| m.translation.save}
33
+ end
39
34
  end
35
+
36
+ before_create :ensure_locale, :if => proc { |c|
37
+ defined?(::Refinery::I18n) && ::Refinery::I18n.enabled?
38
+ }
40
39
  end
41
40
 
41
+ attr_accessible :id, :deletable, :link_url, :menu_match, :meta_keywords,
42
+ :skip_to_first_child, :position, :show_in_menu, :draft,
43
+ :parts_attributes, :browser_title, :meta_description,
44
+ :custom_title_type, :parent_id, :custom_title,
45
+ :created_at, :updated_at, :page_id
46
+
42
47
  attr_accessor :locale # to hold temporarily
43
48
  validates :title, :presence => true
44
49
 
45
- acts_as_nested_set
50
+ acts_as_nested_set :dependent => :destroy # rather than :delete_all
46
51
 
47
52
  # Docs for friendly_id http://github.com/norman/friendly_id
48
53
  has_friendly_id :title, :use_slug => true,
@@ -56,7 +61,7 @@ class Page < ActiveRecord::Base
56
61
  :order => "position ASC",
57
62
  :inverse_of => :page,
58
63
  :dependent => :destroy,
59
- :include => :translations
64
+ :include => ((:translations) if defined?(::PagePart::Translation))
60
65
 
61
66
  accepts_nested_attributes_for :parts, :allow_destroy => true
62
67
 
@@ -69,12 +74,12 @@ class Page < ActiveRecord::Base
69
74
  after_destroy :expire_page_caching
70
75
 
71
76
  # Wrap up the logic of finding the pages based on the translations table.
72
- scope :with_globalize, lambda {|t|
77
+ scope :with_globalize, lambda {|conditions|
73
78
  if defined?(::Page::Translation)
74
- t = {:locale => Globalize.locale}.merge(t || {})
75
- where(:id => ::Page::Translation.where(t).select('page_id AS id'))
79
+ conditions = {:locale => Globalize.locale}.merge(conditions || {})
80
+ where(:id => ::Page::Translation.where(conditions).select('page_id AS id')).includes(:translations)
76
81
  else
77
- where(t)
82
+ where(conditions)
78
83
  end
79
84
  }
80
85
 
@@ -355,6 +360,12 @@ private
355
360
  end
356
361
  end
357
362
 
363
+ def ensure_locale
364
+ unless self.translations.present?
365
+ self.translations.build :locale => ::Refinery::I18n.default_frontend_locale
366
+ end
367
+ end
368
+
358
369
  def expire_page_caching
359
370
  self.class.expire_page_caching
360
371
  end
@@ -3,7 +3,7 @@
3
3
  <span class='title'>
4
4
  <%= page.title_with_meta.html_safe %>
5
5
  <% if defined?(::Refinery::I18n) and ::Refinery::I18n.frontend_locales.many? and
6
- (locales = page.translations.collect{|t| t.locale}).present? %>
6
+ (locales = page.translations.map(&:locale)).present? %>
7
7
  <span class='preview'>
8
8
  <% locales.each do |locale| %>
9
9
  <%= link_to refinery_icon_tag("flags/#{locale}.png", :size => '16x11'),
@@ -29,7 +29,7 @@
29
29
  </div>
30
30
  <ul class='nested'>
31
31
  <%= render :partial => 'page',
32
- :collection => collection.select{|p| p.parent_id == page.id},
32
+ :collection => page.children,
33
33
  :locals => {
34
34
  :collection => collection
35
35
  } if page.has_descendants? %>
@@ -25,8 +25,11 @@ Gem::Specification.new do |s|
25
25
  }.map{|d| d.relative_path_from(gempath)}.uniq.sort.join("',\n '")}'
26
26
  ]
27
27
 
28
- s.add_dependency 'refinerycms-core', '= #{::Refinery::Version}'
29
- s.add_dependency 'seo_meta', '~> 1.0.4'
28
+ s.add_dependency 'refinerycms-core', '= #{::Refinery::Version}'
29
+ s.add_dependency 'friendly_id_globalize3', '~> 3.2.1'
30
+ s.add_dependency 'globalize3', '>= 0.1.0.beta'
31
+ s.add_dependency 'moretea-awesome_nested_set', '~> 1.4'
32
+ s.add_dependency 'seo_meta', '~> 1.0.5'
30
33
  end
31
34
  EOF
32
35
 
@@ -3,7 +3,7 @@ module Refinery
3
3
  module InstanceMethods
4
4
 
5
5
  def error_404(exception=nil)
6
- if (@page = Page.where(:menu_match => "^/404$").includes(:parts, :slugs).first).present?
6
+ if (@page = ::Page.where(:menu_match => "^/404$").includes(:parts, :slugs).first).present?
7
7
  # render the application's custom 404 page with layout and meta.
8
8
  render :template => "/pages/show",
9
9
  :format => 'html',
@@ -15,7 +15,7 @@ module Refinery
15
15
 
16
16
  protected
17
17
  def find_pages_for_menu
18
- @menu_pages = Page.live.in_menu.order('lft ASC').includes(:slugs)
18
+ @menu_pages = ::Page.live.in_menu.order('lft ASC').includes(:slugs, :children)
19
19
  end
20
20
 
21
21
  def render(*args)
@@ -1,6 +1,7 @@
1
1
  require 'refinerycms-core'
2
2
  require 'awesome_nested_set'
3
3
  require 'globalize3'
4
+ require 'friendly_id'
4
5
  require 'seo_meta'
5
6
 
6
7
  module Refinery
@@ -2,10 +2,10 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{refinerycms-pages}
5
- s.version = %q{0.9.9.19}
5
+ s.version = %q{0.9.9.20}
6
6
  s.summary = %q{Pages engine for Refinery CMS}
7
7
  s.description = %q{The default content engine of Refinery CMS. This engine handles the administration and display of user-editable pages.}
8
- s.date = %q{2011-04-22}
8
+ s.date = %q{2011-04-28}
9
9
  s.email = %q{info@refinerycms.com}
10
10
  s.homepage = %q{http://refinerycms.com}
11
11
  s.rubyforge_project = %q{refinerycms}
@@ -117,6 +117,9 @@ Gem::Specification.new do |s|
117
117
  'spec/models/page_spec.rb'
118
118
  ]
119
119
 
120
- s.add_dependency 'refinerycms-core', '= 0.9.9.19'
121
- s.add_dependency 'seo_meta', '~> 1.0.4'
120
+ s.add_dependency 'refinerycms-core', '= 0.9.9.20'
121
+ s.add_dependency 'friendly_id_globalize3', '~> 3.2.1'
122
+ s.add_dependency 'globalize3', '>= 0.1.0.beta'
123
+ s.add_dependency 'moretea-awesome_nested_set', '~> 1.4'
124
+ s.add_dependency 'seo_meta', '~> 1.0.5'
122
125
  end
@@ -51,7 +51,7 @@ describe Page do
51
51
 
52
52
  context "page urls" do
53
53
 
54
- it "should return a full path" do
54
+ it "return a full path" do
55
55
  page.path.should == 'RSpec is great for testing too'
56
56
  end
57
57
 
@@ -63,29 +63,29 @@ describe Page do
63
63
  child.path({:reversed => false}).should == 'The child page - RSpec is great for testing too'
64
64
  end
65
65
 
66
- it "should return its url" do
66
+ it "returns its url" do
67
67
  page.link_url = '/contact'
68
68
  page.url.should == '/contact'
69
69
  end
70
70
 
71
- it "should return its path with marketable urls" do
71
+ it "returns its path with marketable urls" do
72
72
  page.url[:id].should be_nil
73
73
  page.url[:path].should == ["rspec-is-great-for-testing-too"]
74
74
  end
75
75
 
76
- it "should return its path underneath its parent with marketable urls" do
76
+ it "returns its path underneath its parent with marketable urls" do
77
77
  child.url[:id].should be_nil
78
78
  child.url[:path].should == [page.url[:path].first, 'the-child-page']
79
79
  end
80
80
 
81
- it "should not have a path without marketable urls" do
81
+ it "no path parameter without marketable urls" do
82
82
  turn_off_marketable_urls
83
83
  page.url[:path].should be_nil
84
84
  page.url[:id].should == "rspec-is-great-for-testing-too"
85
85
  turn_on_marketable_urls
86
86
  end
87
87
 
88
- it "should not mention its parent without marketable urls" do
88
+ it "doesn't mention its parent without marketable urls" do
89
89
  turn_off_marketable_urls
90
90
  child.url[:id].should == 'the-child-page'
91
91
  child.url[:path].should be_nil
@@ -94,12 +94,12 @@ describe Page do
94
94
  end
95
95
 
96
96
  context "home page" do
97
- it "should respond as the home page" do
97
+ it "responds as the home page" do
98
98
  page.link_url = '/'
99
99
  page.home?.should == true
100
100
  end
101
101
 
102
- it "should not respond as the home page" do
102
+ it "responds as a normal page when not set to home page" do
103
103
  page.home?.should == false
104
104
  end
105
105
  end
@@ -107,16 +107,16 @@ describe Page do
107
107
  context "content sections (page parts)" do
108
108
  before { create_page_parts }
109
109
 
110
- it "should return the content when using []" do
110
+ it "return the content when using []" do
111
111
  page[:body].should == "<p>I'm the first page part for this page.</p>"
112
112
  page["BoDY"].should == "<p>I'm the first page part for this page.</p>"
113
113
  end
114
114
 
115
- it "should return all page part content" do
115
+ it "return all page part content" do
116
116
  page.all_page_part_content.should == "<p>I'm the first page part for this page.</p> <p>Closely followed by the second page part.</p>"
117
117
  end
118
118
 
119
- it "should reposition correctly" do
119
+ it "reposition correctly" do
120
120
  page.parts.first.position = 6
121
121
  page.parts.last.position = 4
122
122
 
@@ -131,12 +131,12 @@ describe Page do
131
131
  end
132
132
 
133
133
  context "draft pages" do
134
- it "should not be a live page when set to draft" do
134
+ it "not live when set to draft" do
135
135
  page.draft = true
136
136
  page.live?.should_not be
137
137
  end
138
138
 
139
- it "should be a live page when not set to draft" do
139
+ it "live when not set to draft" do
140
140
  page.draft = false
141
141
  page.live?.should be
142
142
  end
@@ -163,4 +163,64 @@ describe Page do
163
163
  end
164
164
  end
165
165
 
166
+ context "meta data" do
167
+ context "responds to" do
168
+ it "meta_keywords" do
169
+ page.respond_to?(:meta_keywords)
170
+ end
171
+
172
+ it "meta_description" do
173
+ page.respond_to?(:meta_description)
174
+ end
175
+
176
+ it "browser_title" do
177
+ page.respond_to?(:browser_title)
178
+ end
179
+ end
180
+
181
+ context "allows us to assign to" do
182
+ it "meta_keywords" do
183
+ page.meta_keywords = 'Some, great, keywords'
184
+ page.meta_keywords.should == 'Some, great, keywords'
185
+ end
186
+
187
+ it "meta_description" do
188
+ page.meta_description = 'This is my description of the page for search results.'
189
+ page.meta_description.should == 'This is my description of the page for search results.'
190
+ end
191
+
192
+ it "browser_title" do
193
+ page.browser_title = 'An awesome browser title for SEO'
194
+ page.browser_title.should == 'An awesome browser title for SEO'
195
+ end
196
+ end
197
+
198
+ context "allows us to update" do
199
+ it "meta_keywords" do
200
+ page.meta_keywords = 'Some, great, keywords'
201
+ page.save
202
+
203
+ page.reload
204
+ page.meta_keywords.should == 'Some, great, keywords'
205
+ end
206
+
207
+ it "meta_description" do
208
+ page.meta_description = 'This is my description of the page for search results.'
209
+ page.save
210
+
211
+ page.reload
212
+ page.meta_description.should == 'This is my description of the page for search results.'
213
+ end
214
+
215
+ it "browser_title" do
216
+ page.browser_title = 'An awesome browser title for SEO'
217
+ page.save
218
+
219
+ page.reload
220
+ page.browser_title.should == 'An awesome browser title for SEO'
221
+ end
222
+ end
223
+
224
+ end
225
+
166
226
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: refinerycms-pages
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.9.19
5
+ version: 0.9.9.20
6
6
  platform: ruby
7
7
  authors:
8
8
  - Resolve Digital
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2011-04-22 00:00:00 Z
16
+ date: 2011-04-28 00:00:00 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: refinerycms-core
@@ -23,20 +23,53 @@ dependencies:
23
23
  requirements:
24
24
  - - "="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.9.19
26
+ version: 0.9.9.20
27
27
  type: :runtime
28
28
  version_requirements: *id001
29
29
  - !ruby/object:Gem::Dependency
30
- name: seo_meta
30
+ name: friendly_id_globalize3
31
31
  prerelease: false
32
32
  requirement: &id002 !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.0.4
37
+ version: 3.2.1
38
38
  type: :runtime
39
39
  version_requirements: *id002
40
+ - !ruby/object:Gem::Dependency
41
+ name: globalize3
42
+ prerelease: false
43
+ requirement: &id003 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 0.1.0.beta
49
+ type: :runtime
50
+ version_requirements: *id003
51
+ - !ruby/object:Gem::Dependency
52
+ name: moretea-awesome_nested_set
53
+ prerelease: false
54
+ requirement: &id004 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: "1.4"
60
+ type: :runtime
61
+ version_requirements: *id004
62
+ - !ruby/object:Gem::Dependency
63
+ name: seo_meta
64
+ prerelease: false
65
+ requirement: &id005 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 1.0.5
71
+ type: :runtime
72
+ version_requirements: *id005
40
73
  description: The default content engine of Refinery CMS. This engine handles the administration and display of user-editable pages.
41
74
  email: info@refinerycms.com
42
75
  executables: []
@@ -148,3 +181,4 @@ specification_version: 3
148
181
  summary: Pages engine for Refinery CMS
149
182
  test_files: []
150
183
 
184
+ has_rdoc: