radiant-index_page-extension 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ == MIT License
2
+
3
+ Copyright (c) 2008-2011, Benny Degezelle, Michael Kessler.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,84 @@
1
+ Radiant *Index Page* Extension
2
+ ==============================
3
+
4
+ <table>
5
+ <tr>
6
+ <td>Author</td>
7
+ <td>Benny Degezelle - <a href="http://www.gorilla-webdesign.be">Gorilla Webdesign</a></td>
8
+ </tr>
9
+ <tr>
10
+ <td>Version</td>
11
+ <td>0.1.0</td>
12
+ </tr>
13
+ <tr>
14
+ <td>Contact:</td>
15
+ <td>benny AT gorilla-webdesign DOT be</td>
16
+ </tr>
17
+ </table>
18
+
19
+
20
+ About
21
+ -----
22
+
23
+ This is for indexes that have no content for themselve.
24
+
25
+ For example, a site may be structured like so to keep things organised and clean:
26
+
27
+ /about
28
+ /about/history
29
+ /about/team
30
+ /about/objective
31
+
32
+ Now it is very possible that there is no content for the 'index' page on /about.
33
+
34
+ With this extension you just make the page on /about an IndexPage, which will...
35
+
36
+ * redirect your visitors to it's first published child (default setting)
37
+ * renders the content of the first published child under the parent url
38
+
39
+ Settings
40
+ --------
41
+
42
+ Per default an index page redirects to it's first published child.
43
+
44
+ The above example with the default setting:
45
+
46
+ /about -> Redirect to /about/history and thus show history page
47
+ /about/history -> Show history page
48
+ /about/team -> Show team page
49
+ /about/objective -> Show objective page
50
+
51
+ You can change this behaviour by setting the 'index.page' configuration to 'include'.
52
+
53
+ Radiant::Config["index.page"] = 'include'
54
+
55
+ This renders the first published child under
56
+
57
+ * its own url
58
+ * under the url of its parent
59
+
60
+ The above example with the default setting:
61
+
62
+ /about -> Show history page
63
+ /about/history -> Show history page
64
+ /about/team -> Show team page
65
+ /about/objective -> Show objective page
66
+
67
+ Contributors
68
+ ------------
69
+
70
+ * [Michael Kessler](http://blog.netzpiraten.ch/)
71
+
72
+ Sponsors
73
+ --------
74
+
75
+ Some work has been kindly sponsored by:
76
+
77
+ * [Gorilla Webdesign](http://www.gorilla-webdesign.be)
78
+ * [Screen Concept](http://www.screenconcept.ch)
79
+
80
+ License
81
+ -------
82
+
83
+ This extension is released under the MIT license, see the [LICENSE](master/LICENSE) for more
84
+ information.
@@ -0,0 +1,117 @@
1
+ # Determine where the RSpec plugin is by loading the boot
2
+ unless defined? RADIANT_ROOT
3
+ ENV["RAILS_ENV"] = "test"
4
+ case
5
+ when ENV["RADIANT_ENV_FILE"]
6
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
7
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
8
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
9
+ else
10
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
11
+ end
12
+ end
13
+
14
+ require 'rake'
15
+ require 'rake/rdoctask'
16
+ require 'rake/testtask'
17
+
18
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
19
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
20
+ require 'spec/rake/spectask'
21
+ require 'cucumber'
22
+ require 'cucumber/rake/task'
23
+
24
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
25
+ Object.send(:remove_const, :RADIANT_ROOT)
26
+
27
+ extension_root = File.expand_path(File.dirname(__FILE__))
28
+
29
+ task :default => :spec
30
+ task :stats => "spec:statsetup"
31
+
32
+ desc "Run all specs in spec directory"
33
+ Spec::Rake::SpecTask.new(:spec) do |t|
34
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
35
+ t.spec_files = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ task :features => 'spec:integration'
39
+
40
+ namespace :spec do
41
+ desc "Run all specs in spec directory with RCov"
42
+ Spec::Rake::SpecTask.new(:rcov) do |t|
43
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
44
+ t.spec_files = FileList['spec/**/*_spec.rb']
45
+ t.rcov = true
46
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
47
+ end
48
+
49
+ desc "Print Specdoc for all specs"
50
+ Spec::Rake::SpecTask.new(:doc) do |t|
51
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
52
+ t.spec_files = FileList['spec/**/*_spec.rb']
53
+ end
54
+
55
+ [:models, :controllers, :views, :helpers].each do |sub|
56
+ desc "Run the specs under spec/#{sub}"
57
+ Spec::Rake::SpecTask.new(sub) do |t|
58
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
59
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
60
+ end
61
+ end
62
+
63
+ desc "Run the Cucumber features"
64
+ Cucumber::Rake::Task.new(:integration) do |t|
65
+ t.fork = true
66
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
67
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
68
+ t.profile = "default"
69
+ end
70
+
71
+ # Setup specs for stats
72
+ task :statsetup do
73
+ require 'code_statistics'
74
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
75
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
76
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
77
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
78
+ ::CodeStatistics::TEST_TYPES << "Model specs"
79
+ ::CodeStatistics::TEST_TYPES << "View specs"
80
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
81
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
82
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
83
+ end
84
+
85
+ namespace :db do
86
+ namespace :fixtures do
87
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
88
+ task :load => :environment do
89
+ require 'active_record/fixtures'
90
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
91
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
92
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ desc 'Generate documentation for the index_page extension.'
100
+ Rake::RDocTask.new(:rdoc) do |rdoc|
101
+ rdoc.rdoc_dir = 'rdoc'
102
+ rdoc.title = 'IndexPageExtension'
103
+ rdoc.options << '--line-numbers' << '--inline-source'
104
+ rdoc.rdoc_files.include('README')
105
+ rdoc.rdoc_files.include('lib/**/*.rb')
106
+ end
107
+
108
+ # For extensions that are in transition
109
+ desc 'Test the index_page extension.'
110
+ Rake::TestTask.new(:test) do |t|
111
+ t.libs << 'lib'
112
+ t.pattern = 'test/**/*_test.rb'
113
+ t.verbose = true
114
+ end
115
+
116
+ # Load any custom rakefiles for extension
117
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,11 @@
1
+ class IndexArchivePage < ArchivePage
2
+ def render
3
+ first_published_child = children.find_by_status_id("100", :order => 'published_at DESC', :conditions => ["published_at <= ?", Time.current])
4
+ super if first_published_child.nil?
5
+ if include_index?
6
+ first_published_child.render
7
+ else
8
+ response.redirect first_published_child.url, 302
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class IndexPage < Page
2
+ def render
3
+ first_published_child = children.find_by_status_id("100", :conditions => ["published_at <= ?", Time.current])
4
+ super if first_published_child.nil?
5
+ if include_index?
6
+ first_published_child.render
7
+ else
8
+ response.redirect first_published_child.url, 302
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,16 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] = "test"
3
+ # Extension root
4
+ extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
5
+ require extension_env+'.rb'
6
+
7
+ Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step}
8
+
9
+ Cucumber::Rails::World.class_eval do
10
+ include Dataset
11
+ datasets_directory "#{RADIANT_ROOT}/spec/datasets"
12
+ Dataset::Resolver.default = Dataset::DirectoryResolver.new("#{RADIANT_ROOT}/spec/datasets", File.dirname(__FILE__) + '/../../spec/datasets', File.dirname(__FILE__) + '/../datasets')
13
+ self.datasets_database_dump_path = "#{Rails.root}/tmp/dataset"
14
+
15
+ # dataset :index_page
16
+ end
@@ -0,0 +1,14 @@
1
+ def path_to(page_name)
2
+ case page_name
3
+
4
+ when /the homepage/i
5
+ root_path
6
+
7
+ when /login/i
8
+ login_path
9
+ # Add more page name => path mappings here
10
+
11
+ else
12
+ raise "Can't find mapping from \"#{page_name}\" to a path."
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency 'application_controller'
3
+ require 'radiant-index_page-extension/version'
4
+ class IndexPageExtension < Radiant::Extension
5
+ version RadiantIndexPageExtension::VERSION
6
+ description "Adds the ability to let a 'blank' parent page redirect to it's first child"
7
+ url "http://github.com/jomz/radiant-index-page-extension"
8
+
9
+ def activate
10
+ IndexPage.send :include, IndexPageMethods
11
+ IndexArchivePage.send :include, IndexPageMethods
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module IndexPageMethods
2
+ def response_code
3
+ response.status
4
+ end
5
+
6
+ private
7
+
8
+ def include_index?
9
+ Radiant::Config["index.page"] && Radiant::Config["index.page"] == 'include'
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ module RadiantIndexPageExtension
2
+ end
@@ -0,0 +1,3 @@
1
+ module RadiantIndexPageExtension
2
+ VERSION = '1.0.1'
3
+ end
@@ -0,0 +1,55 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :index_page do
4
+
5
+ desc "Runs the migration of the Index Page extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ IndexPageExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ IndexPageExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Index Page to the instance public/ directory."
18
+ task :update => :environment do
19
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
+ puts "Copying assets from IndexPageExtension"
21
+ Dir[IndexPageExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(IndexPageExtension.root, '')
23
+ directory = File.dirname(path)
24
+ mkdir_p RAILS_ROOT + directory, :verbose => false
25
+ cp file, RAILS_ROOT + path, :verbose => false
26
+ end
27
+ unless IndexPageExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
+ puts "Copying rake tasks from IndexPageExtension"
29
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
+ mkdir_p local_tasks_path, :verbose => false
31
+ Dir[File.join IndexPageExtension.root, %w(lib tasks *.rake)].each do |file|
32
+ cp file, local_tasks_path, :verbose => false
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Syncs all available translations for this ext to the English ext master"
38
+ task :sync => :environment do
39
+ # The main translation root, basically where English is kept
40
+ language_root = IndexPageExtension.root + "/config/locales"
41
+ words = TranslationSupport.get_translation_keys(language_root)
42
+
43
+ Dir["#{language_root}/*.yml"].each do |filename|
44
+ next if filename.match('_available_tags')
45
+ basename = File.basename(filename, '.yml')
46
+ puts "Syncing #{basename}"
47
+ (comments, other) = TranslationSupport.read_file(filename, basename)
48
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
49
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
50
+ TranslationSupport.write_file(filename, basename, comments, other)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-index_page-extension/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-index_page-extension"
7
+ s.version = RadiantIndexPageExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Benny Degezelle"]
10
+ s.email = ["benny@gorilla-webdesign.be"]
11
+ s.homepage = "http://github.com/jomz/radiant-index-page-extension"
12
+ s.summary = %q{Index Page for Radiant CMS}
13
+ s.description = %q{Makes Radiant better by adding index_page!}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.post_install_message = %{
21
+ Add this to your radiant project with:
22
+ config.gem 'radiant-index_page-extension', :version => '#{RadiantIndexPageExtension::VERSION}'
23
+ }
24
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class IndexPageExtensionTest < Test::Unit::TestCase
4
+
5
+ # Replace this with your real tests.
6
+ def test_this_extension
7
+ flunk
8
+ end
9
+
10
+ def test_initialization
11
+ assert_equal File.join(File.expand_path(RAILS_ROOT), 'vendor', 'extensions', 'index_page'), IndexPageExtension.root
12
+ assert_equal 'Index Page', IndexPageExtension.extension_name
13
+ end
14
+
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ # # Load the environment
3
+ unless defined? RADIANT_ROOT
4
+ ENV["RAILS_ENV"] = "test"
5
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
6
+ end
7
+ require "#{RADIANT_ROOT}/test/test_helper"
8
+
9
+ class Test::Unit::TestCase
10
+
11
+ # Include a helper to make testing Radius tags easier
12
+ test_helper :extension_tags
13
+
14
+ # Add the fixture directory to the fixture path
15
+ self.fixture_path << File.dirname(__FILE__) + "/fixtures"
16
+
17
+ # Add more helper methods to be used by all extension tests here...
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-index_page-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Benny Degezelle
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-15 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Makes Radiant better by adding index_page!
23
+ email:
24
+ - benny@gorilla-webdesign.be
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - LICENSE
33
+ - README.markdown
34
+ - Rakefile
35
+ - app/models/index_archive_page.rb
36
+ - app/models/index_page.rb
37
+ - cucumber.yml
38
+ - features/support/env.rb
39
+ - features/support/paths.rb
40
+ - index_page_extension.rb
41
+ - lib/index_page_methods.rb
42
+ - lib/radiant-index_page-extension.rb
43
+ - lib/radiant-index_page-extension/version.rb
44
+ - lib/tasks/index_page_extension_tasks.rake
45
+ - radiant-index_page-extension.gemspec
46
+ - spec/spec.opts
47
+ - spec/spec_helper.rb
48
+ - test/functional/index_page_extension_test.rb
49
+ - test/test_helper.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/jomz/radiant-index-page-extension
52
+ licenses: []
53
+
54
+ post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-index_page-extension', :version => '1.0.1'\n "
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Index Page for Radiant CMS
84
+ test_files:
85
+ - features/support/env.rb
86
+ - features/support/paths.rb
87
+ - spec/spec.opts
88
+ - spec/spec_helper.rb
89
+ - test/functional/index_page_extension_test.rb
90
+ - test/test_helper.rb