radiant-featured_pages-extension 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/HELP.md +10 -0
- data/HELP_designer.md +36 -0
- data/LICENSE +21 -0
- data/README +8 -0
- data/Rakefile +117 -0
- data/TODO +2 -0
- data/app/views/admin/dashboard/_featured_pages.html.haml +17 -0
- data/app/views/admin/pages/_featured_page_meta.html.haml +9 -0
- data/config/locales/en.yml +3 -0
- data/config/routes.rb +5 -0
- data/cucumber.yml +1 -0
- data/db/migrate/001_create_featured_pages.rb +11 -0
- data/db/migrate/20101103202832_add_featured_date_to_pages.rb +21 -0
- data/featured_pages_extension.rb +21 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/featured_pages_tags.rb +119 -0
- data/lib/radiant-featured_pages-extension.rb +2 -0
- data/lib/radiant-featured_pages-extension/page_extensions.rb +9 -0
- data/lib/radiant-featured_pages-extension/version.rb +3 -0
- data/lib/tasks/featured_pages_extension_tasks.rake +55 -0
- data/radiant-featured_pages-extension.gemspec +24 -0
- data/spec/lib/featured_pages_tags_spec.rb +87 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- metadata +98 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/HELP.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Featured Pages
|
2
|
+
|
3
|
+
When setting pages as featured, you specify a 'Featured Date' when editing your page.
|
4
|
+
This date will be used to sort or display the pages when used in your templates.
|
5
|
+
|
6
|
+
If you no longer want a page to be featured you may:
|
7
|
+
|
8
|
+
* clear the Featured Date and save the page
|
9
|
+
* set the Featured Date to a date outside the range you will display
|
10
|
+
* set the page status to Hidden
|
data/HELP_designer.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Featured Pages
|
2
|
+
|
3
|
+
When listing your featured pages, you have flexible options.
|
4
|
+
|
5
|
+
## Code Samples
|
6
|
+
|
7
|
+
Basic list:
|
8
|
+
|
9
|
+
<r:featured_pages:each>
|
10
|
+
<r:title />
|
11
|
+
</r:featured_pages:each>
|
12
|
+
|
13
|
+
Set a limit:
|
14
|
+
|
15
|
+
<r:featured_pages:each>
|
16
|
+
<r:title />
|
17
|
+
</r:featured_pages:each>
|
18
|
+
|
19
|
+
Today's features:
|
20
|
+
|
21
|
+
<r:featured_pages:each date="today">
|
22
|
+
<r:title />
|
23
|
+
</r:featured_pages:each>
|
24
|
+
|
25
|
+
Features from one month ago:
|
26
|
+
|
27
|
+
<r:featured_pages:each date="today" offset="-1 month">
|
28
|
+
<r:title />
|
29
|
+
</r:featured_pages:each>
|
30
|
+
|
31
|
+
Features from one week ago till one month forward:
|
32
|
+
|
33
|
+
<r:featured_pages:each date="today" offset="-1 week" window="+1 month">
|
34
|
+
<r:title />
|
35
|
+
</r:featured_pages:each>
|
36
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
== MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008-2010, Jim Gay, Saturn Flyer LLC.
|
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.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -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 featured_pages extension.'
|
100
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
101
|
+
rdoc.rdoc_dir = 'rdoc'
|
102
|
+
rdoc.title = 'FeaturedPagesExtension'
|
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 featured_pages 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 }
|
data/TODO
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
- @featured_pages = Page.featured.all(:order => 'featured_date DESC')
|
2
|
+
.unit.size1of2
|
3
|
+
#featured_pages.dashboard_module
|
4
|
+
%h2 Featured Pages
|
5
|
+
- unless @featured_pages.blank?
|
6
|
+
%ul
|
7
|
+
- @featured_pages.each do |page|
|
8
|
+
%li
|
9
|
+
%span
|
10
|
+
- link_to page.url do
|
11
|
+
= %{#{page.title} #{page.featured_date.to_date.to_formatted_s(:long)}}
|
12
|
+
= "Updated by #{updater_name_for(page)} #{time_ago_in_words page.updated_at.to_time} ago."
|
13
|
+
.modifications
|
14
|
+
= link_to "Edit", edit_admin_page_path(page), :class => 'update'
|
15
|
+
= link_to "Remove", remove_admin_page_path(page), :class => 'delete'
|
16
|
+
- else
|
17
|
+
%p There are currently no Featured Pages.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
%p
|
2
|
+
= f.label :featured_date, 'Featured Date'
|
3
|
+
= f.text_field :featured_date, :class => "date", :value => (@page.featured_date? ? I18n.localize(@page.featured_date.to_date, :format =>:long) : nil)
|
4
|
+
- content_for :page_css do
|
5
|
+
-# this is how all div.row should be, but we'll be conservative and just set this one
|
6
|
+
:sass
|
7
|
+
#featured
|
8
|
+
clear: left
|
9
|
+
overflow: hidden
|
data/config/routes.rb
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --format progress features --tags ~@proposed,~@in_progress
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateFeaturedPages < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :pages, :featured_page, :boolean, :default => false
|
4
|
+
Page.reset_column_information
|
5
|
+
Page.update_all(['featured_page = ?',false])
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
remove_column :pages, :featured_page
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class AddFeaturedDateToPages < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :pages, :featured_date, :datetime
|
4
|
+
Page.reset_column_information
|
5
|
+
Page.find_in_batches(:conditions => {:featured_page => true}) do |group|
|
6
|
+
group.each do |page|
|
7
|
+
page.update_attribute(:featured_date, (page.published_at || page.created_at))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
remove_column :pages, :featured_page
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
add_column :pages, :featured_page, :boolean, :default => false
|
15
|
+
Page.reset_column_information
|
16
|
+
Page.find_in_batches(:conditions => ["featured_date is NOT NULL or featured_date != ''"]) do |group|
|
17
|
+
page.update_attribute(:featured_page, true)
|
18
|
+
end
|
19
|
+
remove_column :pages, :featured_date
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'radiant-featured_pages-extension'
|
2
|
+
class FeaturedPagesExtension < Radiant::Extension
|
3
|
+
version RadiantFeaturedPagesExtension::VERSION
|
4
|
+
description "Adds featured_date field to all pages to allow listing of pages marked regardless of their nesting within parent pages."
|
5
|
+
url "http://www.saturnflyer.com/"
|
6
|
+
|
7
|
+
def activate
|
8
|
+
Page.class_eval {
|
9
|
+
include FeaturedPagesTags
|
10
|
+
include RadiantFeaturedPagesExtension::PageExtensions
|
11
|
+
}
|
12
|
+
admin.page.edit.add :layout, "featured_page_meta"
|
13
|
+
if admin.respond_to?(:dashboard)
|
14
|
+
admin.dashboard.index.add :extensions, 'featured_pages'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def deactivate
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -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 :featured_pages
|
16
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module FeaturedPagesTags
|
2
|
+
include Radiant::Taggable
|
3
|
+
|
4
|
+
desc %{
|
5
|
+
Sets the scope for featured pages.
|
6
|
+
|
7
|
+
*Usage:*
|
8
|
+
<pre><code><r:featured_pages>...</r:featured_pages></code></pre>
|
9
|
+
}
|
10
|
+
tag 'featured_pages' do |tag|
|
11
|
+
tag.expand
|
12
|
+
end
|
13
|
+
|
14
|
+
desc %{
|
15
|
+
Loops over individual pages from the featured_pages scope.
|
16
|
+
Accepts these parameters:
|
17
|
+
|
18
|
+
* order - 'featured_date ASC' default
|
19
|
+
* limit - '10' defaults to no limit
|
20
|
+
* date - no default
|
21
|
+
* format - used only with the date parameters to specify the format of the date you are using
|
22
|
+
* window - '+3 days' no default, allows you to add(+n) or subtract(-n) days, weeks, months, years
|
23
|
+
* offset - '-1 month' no default, allows you to offset the actual date from the date given
|
24
|
+
|
25
|
+
*Usage:*
|
26
|
+
<pre><code><r:featured_pages:each [limit="1" order="published_at ASC"]>...</r:featured_pages:each></code></pre>
|
27
|
+
}
|
28
|
+
tag 'featured_pages:each' do |tag|
|
29
|
+
find_options = {:conditions => ["virtual = ?",false]}
|
30
|
+
|
31
|
+
order = tag.attr["order"] || 'featured_date DESC'
|
32
|
+
find_options.merge!(:order => order) if order
|
33
|
+
|
34
|
+
limit = tag.attr["limit"] || nil
|
35
|
+
find_options.merge!(:limit => limit) if limit
|
36
|
+
|
37
|
+
date = tag.attr["date"] || nil
|
38
|
+
@i18n_date_formats ||= (I18n.config.backend.send(:translations)[I18n.locale][:date][:formats] rescue {})
|
39
|
+
format = tag.attr['format']
|
40
|
+
if format
|
41
|
+
format = @i18n_date_formats.keys.include?(format.to_sym) ? format.to_sym : format
|
42
|
+
else
|
43
|
+
format = "%m/%d/%Y"
|
44
|
+
end
|
45
|
+
|
46
|
+
offset_pair = change_pairs(tag.attr['offset'])
|
47
|
+
window_pair = change_pairs(tag.attr['window'])
|
48
|
+
|
49
|
+
if date
|
50
|
+
date_finder = case date
|
51
|
+
when /today/
|
52
|
+
Rails.env.test? ? Time.zone.now - 1.second : Time.zone.now
|
53
|
+
else
|
54
|
+
I18n.l(date, :format => format).in_time_zone
|
55
|
+
end
|
56
|
+
date_with_offset = date_finder.in_time_zone + offset_pair.first.send(offset_pair.last)
|
57
|
+
|
58
|
+
if window_pair.first >= 0
|
59
|
+
find_options[:conditions].first << ' and featured_date >= ?'
|
60
|
+
else
|
61
|
+
find_options[:conditions].first << ' and featured_date <= ?'
|
62
|
+
end
|
63
|
+
find_options[:conditions] << date_with_offset
|
64
|
+
|
65
|
+
date_with_window = date_with_offset + window_pair.first.send(window_pair.last)
|
66
|
+
|
67
|
+
if window_pair.first == 0
|
68
|
+
find_options[:conditions].first << ' and featured_date < ?'
|
69
|
+
find_options[:conditions] << date_with_window.end_of_day
|
70
|
+
else
|
71
|
+
if window_pair.first > 0
|
72
|
+
find_options[:conditions].first << ' and featured_date < ?'
|
73
|
+
elsif window_pair.first < 0
|
74
|
+
find_options[:conditions].first << ' and featured_date > ?'
|
75
|
+
end
|
76
|
+
find_options[:conditions] << date_with_window
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
tag.locals.featured_pages = Page.featured.all(find_options)
|
81
|
+
|
82
|
+
result = []
|
83
|
+
tag.locals.featured_pages.each do |p|
|
84
|
+
tag.locals.page = p
|
85
|
+
result << tag.expand
|
86
|
+
end
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
desc %{
|
91
|
+
Displays it's contents for the first page from the featured_pages scope
|
92
|
+
|
93
|
+
*Usage:*
|
94
|
+
<pre><code><r:featured_pages:each><r:if_first>...</r:if_first></r:featured_pages:each></code></pre>
|
95
|
+
}
|
96
|
+
tag 'featured_pages:each:if_first' do |tag|
|
97
|
+
tag.expand if tag.locals.page == tag.locals.featured_pages.first
|
98
|
+
end
|
99
|
+
|
100
|
+
desc %{
|
101
|
+
Displays it's contents for all pages that are not the first page in the featured_pages scope.
|
102
|
+
|
103
|
+
*Usage:*
|
104
|
+
<pre><code><r:featured_pages:each><r:unless_first>...</r:unless_first></r:featured_pages:each></code></pre>
|
105
|
+
}
|
106
|
+
tag 'featured_pages:each:unless_first' do |tag|
|
107
|
+
tag.expand unless tag.locals.page == tag.locals.featured_pages.first
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def change_pairs(text='')
|
113
|
+
text ||= ''
|
114
|
+
change_parts = text.split(' ')
|
115
|
+
num = change_parts.first.to_i
|
116
|
+
unit = change_parts.last =~ /^(second|minute|hour|day|week|month|year)s?$/ ? change_parts.last : 'days'
|
117
|
+
[num, unit]
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :featured_pages do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Featured Pages extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
FeaturedPagesExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
Rake::Task['db:schema:dump'].invoke
|
11
|
+
else
|
12
|
+
FeaturedPagesExtension.migrator.migrate
|
13
|
+
Rake::Task['db:schema:dump'].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies public assets of the Featured Pages 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 FeaturedPagesExtension"
|
21
|
+
Dir[FeaturedPagesExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
22
|
+
path = file.sub(FeaturedPagesExtension.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 FeaturedPagesExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
|
28
|
+
puts "Copying rake tasks from FeaturedPagesExtension"
|
29
|
+
local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
|
30
|
+
mkdir_p local_tasks_path, :verbose => false
|
31
|
+
Dir[File.join FeaturedPagesExtension.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 = FeaturedPagesExtension.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-featured_pages-extension/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "radiant-featured_pages-extension"
|
7
|
+
s.version = RadiantFeaturedPagesExtension::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jim Gay"]
|
10
|
+
s.email = ["jim@saturnflyer.com"]
|
11
|
+
s.homepage = "http://github.com/saturnflyer/radiant-featured_pages-extension"
|
12
|
+
s.summary = %q{Featured Pages Extension for Radiant CMS}
|
13
|
+
s.description = %q{Allows you to provide a featured_date for any page and list it with <r:featured_pages>}
|
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-featured_pages-extension', :version => '#{RadiantFeaturedPagesExtension::VERSION}'
|
23
|
+
}
|
24
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Page do
|
4
|
+
let(:page){
|
5
|
+
Page.new(:featured_date => Time.zone.now, :slug => 'page', :breadcrumb => 'page', :title => 'page')}
|
6
|
+
let(:minus_1_week){
|
7
|
+
Page.new(:featured_date => (Time.zone.now - 1.week), :slug => 'minus_1_week', :breadcrumb => 'minus_1_week', :title => 'minus_1_week')}
|
8
|
+
let(:plus_1_day){
|
9
|
+
Page.new(:featured_date => (Time.zone.now + 1.day), :slug => 'plus_1_day', :breadcrumb => 'plus_1_day', :title => 'plus_1_day')}
|
10
|
+
let(:plus_2_days){
|
11
|
+
Page.new(:featured_date => (Time.zone.now + 2.days), :slug => 'plus_2_days', :breadcrumb => 'plus_2_days', :title => 'plus_2_days', :virtual => true)}
|
12
|
+
let(:plus_2_weeks){
|
13
|
+
Page.new(:featured_date => (Time.zone.now + 2.weeks), :slug => 'plus_2_weeks', :breadcrumb => 'plus_2_weeks', :title => 'plus_2_weeks')}
|
14
|
+
let(:plus_2_months){
|
15
|
+
Page.new(:featured_date => (Time.zone.now + 2.months), :slug => 'plus_2_months', :breadcrumb => 'plus_2_months', :title => 'plus_2_months')}
|
16
|
+
let(:plus_2_years){
|
17
|
+
Page.new(:featured_date => (Time.zone.now + 2.years), :slug => 'plus_2_years', :breadcrumb => 'plus_2_years', :title => 'plus_2_years')}
|
18
|
+
|
19
|
+
def save_pages
|
20
|
+
# saving with false so it still saves when other extensions are present
|
21
|
+
page.save(false) and
|
22
|
+
minus_1_week.save(false) and
|
23
|
+
plus_1_day.save(false) and
|
24
|
+
plus_2_days.save(false) and
|
25
|
+
plus_2_weeks.save(false) and
|
26
|
+
plus_2_months.save(false) and
|
27
|
+
plus_2_years.save(false)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "<r:featured_pages>" do
|
31
|
+
it "should truncate the contents to the given length" do
|
32
|
+
page.should render('<r:featured_pages>Featured!</r:featured_pages>').as('Featured!')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "<r:featured_pages:each>" do
|
37
|
+
before do
|
38
|
+
save_pages
|
39
|
+
end
|
40
|
+
it "should output the contents for each featured page" do
|
41
|
+
page.should render('<r:featured_pages:each><r:title /> </r:featured_pages:each>').as('plus_2_years plus_2_months plus_2_weeks plus_1_day page minus_1_week ')
|
42
|
+
end
|
43
|
+
it "should not find virtual pages" do
|
44
|
+
page.should render('<r:featured_pages:each><r:title /> </r:featured_pages:each>').as('plus_2_years plus_2_months plus_2_weeks plus_1_day page minus_1_week ')
|
45
|
+
end
|
46
|
+
it "should limit the pages by the 'limit' attribute" do
|
47
|
+
page.should render('<r:featured_pages:each limit="1"><r:title /> </r:featured_pages:each>').as('plus_2_years ')
|
48
|
+
end
|
49
|
+
it "should order the pages by the 'order' attribute" do
|
50
|
+
page.should render('<r:featured_pages:each order="featured_date DESC"><r:title /> </r:featured_pages:each>').as('plus_2_years plus_2_months plus_2_weeks plus_1_day page minus_1_week ')
|
51
|
+
end
|
52
|
+
it "should find pages featured on a given 'date'" do
|
53
|
+
page.should render('<r:featured_pages:each date="today"><r:title /> </r:featured_pages:each>').as('page ')
|
54
|
+
end
|
55
|
+
it "should find pages featured today when the given 'date' is 'today'" do
|
56
|
+
page.should render('<r:featured_pages:each date="today"><r:title /> </r:featured_pages:each>').as('page ')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should find pages featured between the given 'date' and and that date plus the 'window'" do
|
60
|
+
page.should render('<r:featured_pages:each date="today" window="1 month"><r:title /> </r:featured_pages:each>').as('plus_2_weeks plus_1_day page ')
|
61
|
+
end
|
62
|
+
it "should find pages featured between the given 'date' plus the 'offset'" do
|
63
|
+
page.should render('<r:featured_pages:each date="today" offset="-7 days"><r:title /> </r:featured_pages:each>').as('minus_1_week ')
|
64
|
+
end
|
65
|
+
it "should find pages featured limited in number by the given 'limit'" do
|
66
|
+
page.should render('<r:featured_pages:each date="today" limit="2" window="2 years"><r:title /> </r:featured_pages:each>').as('plus_2_months plus_2_weeks ')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "<r:featured_pages:each:if_first>" do
|
71
|
+
before do
|
72
|
+
save_pages
|
73
|
+
end
|
74
|
+
it "should expand contents if the page is the first in the collection" do
|
75
|
+
page.should render('<r:featured_pages:each><r:if_first><r:title /> </r:if_first></r:featured_pages:each>').as('plus_2_years ')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "<r:featured_pages:each:unless_first>" do
|
80
|
+
before do
|
81
|
+
save_pages
|
82
|
+
end
|
83
|
+
it "should expand contents if the page is not the first in the collection" do
|
84
|
+
page.should render('<r:featured_pages:each><r:unless_first><r:title /> </r:unless_first></r:featured_pages:each>').as('plus_2_months plus_2_weeks plus_1_day page minus_1_week ')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -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
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-featured_pages-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jim Gay
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-08 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Allows you to provide a featured_date for any page and list it with <r:featured_pages>
|
23
|
+
email:
|
24
|
+
- jim@saturnflyer.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- HELP.md
|
35
|
+
- HELP_designer.md
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- Rakefile
|
39
|
+
- TODO
|
40
|
+
- app/views/admin/dashboard/_featured_pages.html.haml
|
41
|
+
- app/views/admin/pages/_featured_page_meta.html.haml
|
42
|
+
- config/locales/en.yml
|
43
|
+
- config/routes.rb
|
44
|
+
- cucumber.yml
|
45
|
+
- db/migrate/001_create_featured_pages.rb
|
46
|
+
- db/migrate/20101103202832_add_featured_date_to_pages.rb
|
47
|
+
- featured_pages_extension.rb
|
48
|
+
- features/support/env.rb
|
49
|
+
- features/support/paths.rb
|
50
|
+
- lib/featured_pages_tags.rb
|
51
|
+
- lib/radiant-featured_pages-extension.rb
|
52
|
+
- lib/radiant-featured_pages-extension/page_extensions.rb
|
53
|
+
- lib/radiant-featured_pages-extension/version.rb
|
54
|
+
- lib/tasks/featured_pages_extension_tasks.rake
|
55
|
+
- radiant-featured_pages-extension.gemspec
|
56
|
+
- spec/lib/featured_pages_tags_spec.rb
|
57
|
+
- spec/spec.opts
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/saturnflyer/radiant-featured_pages-extension
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-featured_pages-extension', :version => '2.0.0'\n "
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_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
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Featured Pages Extension for Radiant CMS
|
93
|
+
test_files:
|
94
|
+
- features/support/env.rb
|
95
|
+
- features/support/paths.rb
|
96
|
+
- spec/lib/featured_pages_tags_spec.rb
|
97
|
+
- spec/spec.opts
|
98
|
+
- spec/spec_helper.rb
|