radiant-archive-extension 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ tmp/*
2
+ *.gem
@@ -0,0 +1,23 @@
1
+ module ArchiveMenuRenderer
2
+ def excluded_class_names
3
+ Array(ArchiveMenuRenderer.instance_variable_get(:@excluded_class_names))
4
+ end
5
+ end
6
+
7
+ module ArchiveDayIndexMenuRenderer
8
+ def add_child_disabled?
9
+ true
10
+ end
11
+ end
12
+
13
+ module ArchiveMonthIndexMenuRenderer
14
+ def add_child_disabled?
15
+ true
16
+ end
17
+ end
18
+
19
+ module ArchiveYearIndexMenuRenderer
20
+ def add_child_disabled?
21
+ true
22
+ end
23
+ end
@@ -1,17 +1,17 @@
1
1
  class ArchivePage < Page
2
- cattr_accessor :allowed_children
3
2
  cattr_accessor :single_use_children
4
3
  @@single_use_children = [ArchiveDayIndexPage, ArchiveMonthIndexPage, ArchiveYearIndexPage, FileNotFoundPage]
5
- @@allowed_children = [self.default_child, *@@single_use_children]
6
4
 
7
- def allowed_children
8
- overlap = @@allowed_children & (existing_child_types - [default_child])
5
+ def set_allowed_children_cache
6
+ singles = self.class.single_use_children.map(&:name)
7
+ existing = existing_child_types.map(&:name)
8
+ all = allowed_children_lookup.map(&:name)
9
9
 
10
- (@@allowed_children - overlap)
10
+ self.allowed_children_cache = (all - (singles & existing)).join(',')
11
11
  end
12
12
 
13
13
  def existing_child_types
14
- children(:select => 'DISTINCT class_name, title, virtual', :order => nil).collect{|p| p.class }.uniq
14
+ children(:select => 'DISTINCT class_name, title, virtual', :order => nil).map(&:class_name).compact.map(&:constantize).uniq
15
15
  end
16
16
 
17
17
  description %{
data/archive_extension.rb CHANGED
@@ -9,11 +9,10 @@ class ArchiveExtension < Radiant::Extension
9
9
  def activate
10
10
  # allow bootstrap
11
11
  if Page.table_exists?
12
+ ArchiveMenuRenderer # Initialize the class because it is lazily loaded
13
+ MenuRenderer.exclude 'ArchiveDayIndexPage', 'ArchiveMonthIndexPage', 'ArchiveYearIndexPage'
12
14
  Page.class_eval do
13
- def allowed_children_with_archive
14
- allowed_children_without_archive.reject { |p| p.name =~ /Archive(Day|Month|Year)IndexPage/ }
15
- end
16
- alias_method_chain :allowed_children, :archive
15
+ include PageChildrenCacheUpdates
17
16
  end
18
17
  end
19
18
  end
@@ -0,0 +1,41 @@
1
+ module PageChildrenCacheUpdates
2
+ def self.included(base)
3
+ base.class_eval do
4
+ after_create :remove_from_parent_allowed_children_cache
5
+ after_destroy :add_to_parent_allowed_children_cache
6
+ end
7
+ end
8
+
9
+ private
10
+
11
+ def remove_from_parent_allowed_children_cache
12
+ if parent_allows_this_child_class? && class_is_single_use_for_parent?
13
+ parent.allowed_children_cache = parent_allowed_class_names.delete_if{|child| child == page_class_name }.join(',')
14
+ parent.save
15
+ end
16
+ end
17
+
18
+ def add_to_parent_allowed_children_cache
19
+ if class_is_single_use_for_parent? && !parent_allows_this_child_class?
20
+ parent.allowed_children_cache = (parent_allowed_class_names + [page_class_name]).uniq.join(',')
21
+ parent.save
22
+ true
23
+ end
24
+ end
25
+
26
+ def parent_allows_this_child_class?
27
+ parent? && parent.allowed_children_cache.to_s.split(',').include?(page_class_name)
28
+ end
29
+
30
+ def class_is_single_use_for_parent?
31
+ parent? && parent.class.respond_to?(:single_use_children) && parent.class.single_use_children.map(&:name).include?(page_class_name)
32
+ end
33
+
34
+ def parent_allowed_class_names
35
+ parent.allowed_children_cache.to_s.split(',')
36
+ end
37
+
38
+ def page_class_name
39
+ self.class_name.present? ? self.class_name : 'Page'
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module RadiantArchiveExtension
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -12,14 +12,19 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Archive for Radiant CMS}
13
13
  s.description = %q{Provides page types for news or blog archives.}
14
14
 
15
- ignores = if File.exist?('.gitignore')
16
- File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
17
- else
18
- []
19
- end
20
- s.files = Dir['**/*'] - ignores
21
- s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
22
- # s.executables = Dir['bin/*'] - ignores
15
+ ignoreable_commands = File.read('.gitignore').split("\n").delete_if{|line| line.match(/^##/) || line.empty? }
16
+ ignoreable_files = ignoreable_commands.collect{|line|
17
+ if File.directory?(line)
18
+ line + "/**/*"
19
+ elsif File.file?(line)
20
+ line
21
+ end
22
+ }.compact
23
+
24
+ s.files = Dir['**/*','.gitignore'] - Dir[*ignoreable_files]
25
+
26
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - Dir[*ignoreable_files]
27
+
23
28
  s.require_paths = ["lib"]
24
29
 
25
30
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArchiveMenuRenderer do
4
+ context 'excluding classes from child list' do
5
+ it 'should be retrievable by the extended object' do
6
+ ArchiveMenuRenderer.instance_variable_set(:@excluded_class_names, ['SkippedPage'])
7
+ page = Object.new
8
+ page.extend ArchiveMenuRenderer
9
+ page.excluded_class_names.should include('SkippedPage')
10
+ end
11
+ end
12
+ end
13
+
14
+ describe ArchiveDayIndexMenuRenderer do
15
+ subject{
16
+ page = Object.new
17
+ page.extend ArchiveDayIndexMenuRenderer
18
+ page
19
+ }
20
+ its(:add_child_disabled?){ should be_true }
21
+ end
22
+
23
+ describe ArchiveMonthIndexMenuRenderer do
24
+ subject{
25
+ page = Object.new
26
+ page.extend ArchiveMonthIndexMenuRenderer
27
+ page
28
+ }
29
+ its(:add_child_disabled?){ should be_true }
30
+ end
31
+
32
+ describe ArchiveYearIndexMenuRenderer do
33
+ subject{
34
+ page = Object.new
35
+ page.extend ArchiveYearIndexMenuRenderer
36
+ page
37
+ }
38
+ its(:add_child_disabled?){ should be_true }
39
+ end
@@ -34,23 +34,11 @@ describe ArchivePage do
34
34
  end
35
35
 
36
36
  its(:single_use_children){ should == [ArchiveDayIndexPage, ArchiveMonthIndexPage, ArchiveYearIndexPage, FileNotFoundPage]}
37
- its(:allowed_children){ should == [Page, *ArchivePage.single_use_children]}
38
37
 
39
38
  describe '#existing_child_types' do
40
39
  it 'should return a unique array of classes of the page children' do
41
- archive.existing_child_types.should == archive.children.all(:select => 'DISTINCT class_name, title, virtual').collect{|p| p.class }.uniq
40
+ archive.existing_child_types.should == archive.children(:select => 'DISTINCT class_name, title, virtual', :order => nil).map(&:class_name).compact.map(&:constantize).uniq
42
41
  end
43
42
  end
44
43
 
45
- describe '#allowed_children' do
46
- context 'when no children exist' do
47
- subject{ ArchivePage.new }
48
- its(:allowed_children){ should == ArchivePage.allowed_children }
49
- end
50
- it 'should remove any existing single_use_children from the allowed_children' do
51
- existing_except_default = archive.existing_child_types - [archive.default_child]
52
- used_allowed_children = ArchivePage.allowed_children & existing_except_default
53
- archive.allowed_children.should == (ArchivePage.allowed_children - used_allowed_children)
54
- end
55
- end
56
44
  end
@@ -1,6 +1,27 @@
1
1
  require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  describe Page do
4
- its(:default_child){ should == Page}
5
- its(:allowed_children){ should == [Page, *Page.descendants.sort_by(&:name)].select(&:in_menu?).reject{|p| p.name =~ /Archive(Day|Month|Year)IndexPage/}}
4
+ context 'when the parent page has single_use_children' do
5
+ it 'should remove its class from the parent page allowed_children_cache after create' do
6
+ ArchivePage.stub!(:single_use_children).and_return([ArchiveDayIndexPage])
7
+ parent = ArchivePage.create!(:slug => 'archive', :title => 'archive',
8
+ :breadcrumb => 'archive',
9
+ :allowed_children_cache => 'Page,ArchiveDayIndexPage')
10
+ page = ArchiveDayIndexPage.new(:slug => 'day', :title => 'day', :breadcrumb => 'day')
11
+ page.parent = parent
12
+ page.save!
13
+ parent.allowed_children_cache.should_not include('ArchiveDayIndexPage')
14
+ end
15
+ it 'should add its class to the parent page allowed_children_cache after destroy' do
16
+ ArchivePage.stub!(:single_use_children).and_return([ArchiveDayIndexPage])
17
+ parent = ArchivePage.create!(:slug => 'archive', :title => 'archive',
18
+ :breadcrumb => 'archive',
19
+ :allowed_children_cache => 'Page,ArchiveDayIndexPage')
20
+ page = ArchiveDayIndexPage.new(:slug => 'day', :title => 'day', :breadcrumb => 'day')
21
+ page.parent = parent
22
+ page.save!
23
+ page.destroy
24
+ parent.allowed_children_cache.should include('ArchiveDayIndexPage')
25
+ end
26
+ end
6
27
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-archive-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Radiant CMS Dev Team
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-30 00:00:00 -05:00
19
- default_executable:
18
+ date: 2011-11-05 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: Provides page types for news or blog archives.
@@ -31,6 +30,7 @@ extra_rdoc_files: []
31
30
  files:
32
31
  - app/models/archive_day_index_page.rb
33
32
  - app/models/archive_finder.rb
33
+ - app/models/archive_menu_renderer.rb
34
34
  - app/models/archive_month_index_page.rb
35
35
  - app/models/archive_page.rb
36
36
  - app/models/archive_year_index_page.rb
@@ -46,22 +46,24 @@ files:
46
46
  - features/support/matchers.rb
47
47
  - features/support/paths.rb
48
48
  - lib/archive_index_tags_and_methods.rb
49
+ - lib/page_children_cache_updates.rb
49
50
  - lib/radiant-archive-extension/version.rb
50
51
  - lib/radiant-archive-extension.rb
51
52
  - lib/tasks/archive_extension_tasks.rake
52
- - radiant-archive-extension-1.0.3.gem
53
+ - radiant-archive-extension-1.0.4.gem
53
54
  - radiant-archive-extension.gemspec
54
55
  - Rakefile
55
56
  - README
56
57
  - spec/datasets/archive_dataset.rb
57
58
  - spec/models/archive_day_index_page_spec.rb
59
+ - spec/models/archive_menu_renderer_spec.rb
58
60
  - spec/models/archive_month_index_page_spec.rb
59
61
  - spec/models/archive_page_spec.rb
60
62
  - spec/models/archive_year_index_page_spec.rb
61
63
  - spec/models/page_spec.rb
62
64
  - spec/spec.opts
63
65
  - spec/spec_helper.rb
64
- has_rdoc: true
66
+ - .gitignore
65
67
  homepage: http://radiantcms.org
66
68
  licenses: []
67
69
 
@@ -91,13 +93,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  requirements: []
92
94
 
93
95
  rubyforge_project:
94
- rubygems_version: 1.3.9.3
96
+ rubygems_version: 1.8.10
95
97
  signing_key:
96
98
  specification_version: 3
97
99
  summary: Archive for Radiant CMS
98
100
  test_files:
99
101
  - spec/datasets/archive_dataset.rb
100
102
  - spec/models/archive_day_index_page_spec.rb
103
+ - spec/models/archive_menu_renderer_spec.rb
101
104
  - spec/models/archive_month_index_page_spec.rb
102
105
  - spec/models/archive_page_spec.rb
103
106
  - spec/models/archive_year_index_page_spec.rb