trusty-reorder-extension 1.0.0
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/README.md +32 -0
- data/Rakefile +120 -0
- data/app/assets/images/admin/move_higher.png +0 -0
- data/app/assets/images/admin/move_lower.png +0 -0
- data/app/assets/images/admin/move_to_bottom.png +0 -0
- data/app/assets/images/admin/move_to_top.png +0 -0
- data/app/assets/stylesheets/admin/reorder.scss +3 -0
- data/app/views/admin/pages/_header.html.haml +1 -0
- data/app/views/admin/pages/_order.html.haml +11 -0
- data/app/views/admin/pages/_order_header.html.haml +1 -0
- data/config/routes.rb +11 -0
- data/db/migrate/01_add_position_to_pages.rb +24 -0
- data/lib/reorder/engine.rb +5 -0
- data/lib/reorder/page_extensions.rb +12 -0
- data/lib/reorder/page_helper.rb +11 -0
- data/lib/reorder/pages_controller_extensions.rb +12 -0
- data/lib/reorder/tag_extensions.rb +11 -0
- data/lib/tasks/reorder_extension_tasks.rake +28 -0
- data/lib/trusty-reorder-extension.rb +1 -0
- data/reorder_extension.rb +18 -0
- data/spec/controllers/pages_controller_extensions_spec.rb +45 -0
- data/spec/datasets/pages_with_positions.rb +18 -0
- data/spec/model/page_extensions_spec.rb +67 -0
- data/spec/model/tag_extensions_spec.rb +27 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +42 -0
- data/trusty-reorder-extension.gemspec +30 -0
- metadata +110 -0
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= Reorder
|
2
|
+
|
3
|
+
Created by Sean Cribbs, October 2007. Inspired by Adam Williams' original
|
4
|
+
reorder extension.
|
5
|
+
|
6
|
+
Allows pages to be arbitrarily ordered underneath their parent. This is useful
|
7
|
+
for creating navigations based on children of a given page. Buttons are added
|
8
|
+
to the sitemap that allow you to move individual pages higher or lower in the
|
9
|
+
ordering, or to the top or bottom of the list.
|
10
|
+
|
11
|
+
No drag-and-drop for now! Keeping it simple.
|
12
|
+
|
13
|
+
Included images are slightly modified from FamFamFam Silk Icons by Mark James:
|
14
|
+
http://www.famfamfam.com/lab/icons/silk/
|
15
|
+
|
16
|
+
== Installation
|
17
|
+
|
18
|
+
1) Unpack/checkout/export the extension into vendor/extensions of your project.
|
19
|
+
|
20
|
+
2) Run the extension migrations.
|
21
|
+
|
22
|
+
$ rake production radiant:extensions:reorder:migrate
|
23
|
+
|
24
|
+
3) Run the extension update task.
|
25
|
+
|
26
|
+
$ rake production radiant:extensions:reorder:update
|
27
|
+
|
28
|
+
4) Restart your server and edit the order of the pages from the admin interface.
|
29
|
+
To bypass the ordering system simply supply a "by" option to the finder tags.
|
30
|
+
|
31
|
+
== Compatibility
|
32
|
+
The 0.7.1 tag is compatible with Radiant 0.7.1. Edge is currently compatible with Radiant 0.9.0RC1.
|
data/Rakefile
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# I think this is the one that should be moved to the extension Rakefile template
|
2
|
+
|
3
|
+
# In rails 1.2, plugins aren't available in the path until they're loaded.
|
4
|
+
# Check to see if the rspec plugin is installed first and require
|
5
|
+
# it if it is. If not, use the gem version.
|
6
|
+
|
7
|
+
# Determine where the RSpec plugin is by loading the boot
|
8
|
+
unless defined? RADIANT_ROOT
|
9
|
+
ENV["RAILS_ENV"] = "test"
|
10
|
+
case
|
11
|
+
when ENV["RADIANT_ENV_FILE"]
|
12
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
13
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
14
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
15
|
+
else
|
16
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake'
|
21
|
+
require 'rdoc/task'
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
25
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
26
|
+
require 'spec/rake/spectask'
|
27
|
+
# require 'spec/translator'
|
28
|
+
|
29
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
30
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
31
|
+
|
32
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
task :stats => "spec:statsetup"
|
36
|
+
|
37
|
+
desc "Run all specs in spec directory"
|
38
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
39
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
40
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :spec do
|
44
|
+
desc "Run all specs in spec directory with RCov"
|
45
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
46
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
47
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
48
|
+
t.rcov = true
|
49
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Print Specdoc for all specs"
|
53
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
54
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
55
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
56
|
+
end
|
57
|
+
|
58
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
59
|
+
desc "Run the specs under spec/#{sub}"
|
60
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
61
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
62
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Hopefully no one has written their extensions in pre-0.9 style
|
67
|
+
# desc "Translate specs from pre-0.9 to 0.9 style"
|
68
|
+
# task :translate do
|
69
|
+
# translator = ::Spec::Translator.new
|
70
|
+
# dir = RAILS_ROOT + '/spec'
|
71
|
+
# translator.translate(dir, dir)
|
72
|
+
# end
|
73
|
+
|
74
|
+
# Setup specs for stats
|
75
|
+
task :statsetup do
|
76
|
+
require 'code_statistics'
|
77
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
78
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
79
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
80
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
81
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
82
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
83
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
84
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
85
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
86
|
+
end
|
87
|
+
|
88
|
+
namespace :db do
|
89
|
+
namespace :fixtures do
|
90
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
91
|
+
task :load => :environment do
|
92
|
+
require 'active_record/fixtures'
|
93
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
94
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
95
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
desc 'Generate documentation for the upcoming_events extension.'
|
103
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
104
|
+
rdoc.rdoc_dir = 'rdoc'
|
105
|
+
rdoc.title = 'UpcomingEventsExtension'
|
106
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
107
|
+
rdoc.rdoc_files.include('README')
|
108
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
109
|
+
end
|
110
|
+
|
111
|
+
# For extensions that are in transition
|
112
|
+
desc 'Test the upcoming_events extension.'
|
113
|
+
Rake::TestTask.new(:test) do |t|
|
114
|
+
t.libs << 'lib'
|
115
|
+
t.pattern = 'test/**/*_test.rb'
|
116
|
+
t.verbose = true
|
117
|
+
end
|
118
|
+
|
119
|
+
# Load any custom rakefiles for extension
|
120
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
= stylesheet_link_tag 'admin/reorder'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- unless simple
|
2
|
+
%td.order
|
3
|
+
- if level > 0
|
4
|
+
= link_to(image_tag("admin/move_to_top.png", :alt => "Move To Top"),
|
5
|
+
admin_page_page_move_to_top_url(page.id), {:id => page, :method => :post})
|
6
|
+
= link_to(image_tag("admin/move_higher.png", :alt => "Move Higher"),
|
7
|
+
admin_page_page_move_higher_url(page.id), {:id => page, :method => :post})
|
8
|
+
= link_to(image_tag("admin/move_lower.png", :alt => "Move Lower"),
|
9
|
+
admin_page_page_move_lower_url(page.id), {:id => page, :method => :post})
|
10
|
+
= link_to(image_tag("admin/move_to_bottom.png", :alt => "Move To Bottom"),
|
11
|
+
admin_page_page_move_to_bottom_url(page.id), {:id => page, :method => :post})
|
@@ -0,0 +1 @@
|
|
1
|
+
%th.order Order
|
data/config/routes.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
TrustyCms::Application.routes.draw do
|
2
|
+
namespace :admin do
|
3
|
+
resources :pages do
|
4
|
+
post "/move_lower" => :move_lower, as: :page_move_lower
|
5
|
+
post "/move_higher" => :move_higher, as: :page_move_higher
|
6
|
+
post "/move_to_bottom" => :move_to_bottom, as: :page_move_to_bottom
|
7
|
+
post "/move_to_top" => :move_to_top, as: :page_move_to_top
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class AddPositionToPages < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :pages, :position, :integer
|
4
|
+
Page.reset_column_information
|
5
|
+
say_with_time("Putting all pages in a default order...") do
|
6
|
+
ActiveRecord::Base.record_timestamps = false
|
7
|
+
Page.find_all_by_parent_id(nil).each do |p|
|
8
|
+
put_children_into_list(p)
|
9
|
+
end
|
10
|
+
ActiveRecord::Base.record_timestamps = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
remove_column :pages, :position
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.put_children_into_list(page)
|
19
|
+
page.children.find(:all, :order => "title asc").each_with_index do |pg, idx|
|
20
|
+
pg.update_attribute('position', idx + 1)
|
21
|
+
put_children_into_list(pg)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Reorder::PageExtensions
|
2
|
+
def self.included(base)
|
3
|
+
base.class_eval {
|
4
|
+
acts_as_list :scope => :parent_id
|
5
|
+
self.reflections[:children].options[:order] = "position ASC"
|
6
|
+
}
|
7
|
+
|
8
|
+
if defined?(Page::NONDRAFT_FIELDS)
|
9
|
+
Page::NONDRAFT_FIELDS << 'position'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Reorder::PageHelper
|
2
|
+
def order_links(page)
|
3
|
+
String.new.tap do |output|
|
4
|
+
%w{move_to_top move_higher move_lower move_to_bottom}.each do |action|
|
5
|
+
output << link_to(image("#{action}.png", :alt => action.humanize),
|
6
|
+
self.send("admin_page_#{action}_url", :id => page),
|
7
|
+
:method => :post)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Reorder::PagesControllerExtensions
|
2
|
+
|
3
|
+
%w{move_higher move_lower move_to_top move_to_bottom}.each do |action|
|
4
|
+
define_method action do
|
5
|
+
@page = Page.find(params[:page_id])
|
6
|
+
@page.parent.reload.children.reload
|
7
|
+
@page.send(action)
|
8
|
+
response_for :update
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Reorder::TagExtensions
|
2
|
+
def self.included(base)
|
3
|
+
base.class_eval { alias_method_chain :children_find_options, :reorder }
|
4
|
+
end
|
5
|
+
|
6
|
+
def children_find_options_with_reorder(tag)
|
7
|
+
options = children_find_options_without_reorder(tag)
|
8
|
+
options[:order].sub!(/published_at/i, 'position') unless tag.attr['by']
|
9
|
+
options
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :reorder do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Reorder extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
ReorderExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
else
|
11
|
+
ReorderExtension.migrator.migrate
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Copies public assets of the Reorder to the instance public/ directory."
|
16
|
+
task :update => :environment do
|
17
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
18
|
+
Dir[ReorderExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
19
|
+
path = file.sub(ReorderExtension.root, '')
|
20
|
+
directory = File.dirname(path)
|
21
|
+
puts "Copying #{path}..."
|
22
|
+
mkdir_p RAILS_ROOT + directory
|
23
|
+
cp file, RAILS_ROOT + path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Nothing to see here
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
2
|
+
require_dependency 'application_controller'
|
3
|
+
|
4
|
+
class ReorderExtension < TrustyCms::Extension
|
5
|
+
version "0.2.1"
|
6
|
+
description "Allows (re)ordering of pages in the page tree."
|
7
|
+
url "http://dev.radiantcms.org/"
|
8
|
+
|
9
|
+
def activate
|
10
|
+
admin.page.index.add :sitemap_head, "order_header"
|
11
|
+
admin.page.index.add :node, "order"
|
12
|
+
admin.page.index.add :top, 'header'
|
13
|
+
Page.send :include, Reorder::PageExtensions
|
14
|
+
Admin::PagesController.send :include, Reorder::PagesControllerExtensions
|
15
|
+
Admin::PagesController.send :helper, Reorder::PageHelper
|
16
|
+
StandardTags.send :include, Reorder::TagExtensions
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::PagesController do
|
4
|
+
dataset :users, :pages_with_positions
|
5
|
+
|
6
|
+
before do
|
7
|
+
login_as :existing
|
8
|
+
@page = pages(:documentation)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should move higher" do
|
12
|
+
lambda {
|
13
|
+
post :move_higher, :id => @page.id
|
14
|
+
@page.reload
|
15
|
+
}.should change(@page, :position).by -1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should move lower" do
|
19
|
+
lambda {
|
20
|
+
post :move_lower, :id => @page.id
|
21
|
+
@page.reload
|
22
|
+
}.should change(@page, :position).by 1
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should move to top" do
|
26
|
+
post :move_to_top, :id => @page.id
|
27
|
+
@page.reload
|
28
|
+
@page.position.should eql(1)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should move to bottom" do
|
32
|
+
post :move_to_bottom, :id => @page.id
|
33
|
+
@page.reload
|
34
|
+
@page.position.should == @page.parent.children.size
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should require login" do
|
38
|
+
logout
|
39
|
+
%w{move_higher move_lower move_to_top move_to_bottom}.each do |action|
|
40
|
+
post action, :id => @page.id
|
41
|
+
response.should redirect_to(login_url)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class PagesWithPositionsDataset < Dataset::Base
|
2
|
+
uses :home_page
|
3
|
+
|
4
|
+
def load
|
5
|
+
create_page "Documentation", :position => 2
|
6
|
+
create_page "Page A", :position => 1
|
7
|
+
create_page "Page B", :position => 3
|
8
|
+
create_page "Page C", :position => 4
|
9
|
+
create_page "Page Y", :position => 5
|
10
|
+
create_page "Page Z", :position => 6
|
11
|
+
end
|
12
|
+
|
13
|
+
helpers do
|
14
|
+
def order_map(coll)
|
15
|
+
coll.map {|r| [r.position, r.title]}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Reorder::PageExtensions do
|
4
|
+
dataset :pages_with_positions
|
5
|
+
|
6
|
+
before do
|
7
|
+
@page = Page.new
|
8
|
+
@pages = pages(:home).children
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should add acts as list methods" do
|
12
|
+
[:position, :move_higher, :move_lower, :move_to_top, :move_to_bottom].each do |m|
|
13
|
+
@page.should respond_to(m)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should reorder children by position" do
|
18
|
+
Page.reflections[:children].options[:order].should eql("position ASC")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should scope list to parent id" do
|
22
|
+
@page.should respond_to(:scope_condition)
|
23
|
+
@page.scope_condition.should eql("parent_id IS NULL")
|
24
|
+
@page.parent_id = 2
|
25
|
+
@page.scope_condition.should eql("parent_id = 2")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return children in position order" do
|
29
|
+
pages(:home).children.sort_by(&:position).should == pages(:home).children
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should swap with top when next to top" do
|
33
|
+
order_map(@pages.to_a)[0..1].should == [[1, "Page A"], [2, "Documentation"]]
|
34
|
+
@page = pages(:documentation)
|
35
|
+
@page.move_higher
|
36
|
+
@pages.reload
|
37
|
+
order_map(@pages.to_a)[0..1].should == [[1, "Documentation"], [2, "Page A"]]
|
38
|
+
@pages[1..-1].all? {|p| p.position.to_i != 1}.should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should swap with top when next to top and moving to top" do
|
42
|
+
order_map(@pages.to_a)[0..1].should == [[1, "Page A"], [2, "Documentation"]]
|
43
|
+
@page = pages(:documentation)
|
44
|
+
@page.move_to_top
|
45
|
+
@pages.reload
|
46
|
+
order_map(@pages.to_a)[0..1].should == [[1, "Documentation"], [2, "Page A"]]
|
47
|
+
@pages[1..-1].all? {|p| p.position.to_i != 1}.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should swap with bottom when next to bottom" do
|
51
|
+
order_map(@pages.to_a)[-2..-1].should == [[5, "Page Y"], [6, "Page Z"]]
|
52
|
+
@page = pages(:page_y)
|
53
|
+
@page.move_lower
|
54
|
+
@pages.reload
|
55
|
+
order_map(@pages.to_a)[-2..-1].should == [[5, "Page Z"], [6, "Page Y"]]
|
56
|
+
@pages[0..-2].all? {|p| p.position.to_i != 6}.should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should swap with bottom when next to bottom and moving to bottom" do
|
60
|
+
order_map(@pages.to_a)[-2..-1].should == [[5, "Page Y"], [6, "Page Z"]]
|
61
|
+
@page = pages(:page_y)
|
62
|
+
@page.move_to_bottom
|
63
|
+
@pages.reload
|
64
|
+
order_map(@pages.to_a)[-2..-1].should == [[5, "Page Z"], [6, "Page Y"]]
|
65
|
+
@pages[0..-2].all? {|p| p.position.to_i != 6}.should be_true
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe Reorder::TagExtensions do
|
5
|
+
before do
|
6
|
+
@tag = OpenStruct.new
|
7
|
+
@tag.attr = { :status => 'all' }
|
8
|
+
@children_find_options = Page.new.method(:children_find_options)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should override default options" do
|
12
|
+
opts = @children_find_options.call(@tag)
|
13
|
+
opts[:order].should match(/position/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not override when 'by' is specified" do
|
17
|
+
@tag.attr['by'] = "created_at"
|
18
|
+
opts = @children_find_options.call(@tag)
|
19
|
+
opts[:order].should_not match(/position/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be independent of order attributes" do
|
23
|
+
@tag.attr['order'] = 'desc'
|
24
|
+
opts = @children_find_options.call(@tag)
|
25
|
+
opts[:order].should match(/position/)
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
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
|
+
# Include any datasets from loaded extensions
|
16
|
+
Radiant::Extension.descendants.each do |extension|
|
17
|
+
if File.directory?(extension.root + "/spec/datasets")
|
18
|
+
Dataset::Resolver.default << (extension.root + "/spec/datasets")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
23
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Runner.configure do |config|
|
27
|
+
# config.use_transactional_fixtures = true
|
28
|
+
# config.use_instantiated_fixtures = false
|
29
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
30
|
+
|
31
|
+
# You can declare fixtures for each behaviour like this:
|
32
|
+
# describe "...." do
|
33
|
+
# fixtures :table_a, :table_b
|
34
|
+
#
|
35
|
+
# Alternatively, if you prefer to declare them only once, you can
|
36
|
+
# do so here, like so ...
|
37
|
+
#
|
38
|
+
# config.global_fixtures = :table_a, :table_b
|
39
|
+
#
|
40
|
+
# If you declare global fixtures, be aware that they will be declared
|
41
|
+
# for all of your examples, even those that don't use them.
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "trusty-reorder-extension"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "trusty-reorder-extension"
|
7
|
+
s.version = "1.0.0"
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.authors = ["Eric Sipple"]
|
10
|
+
s.date = %q{2014-10-07}
|
11
|
+
s.description = %q{Extends Trusty CMS to allow page ordering}
|
12
|
+
s.email = %q{sipple@trustarts.org}
|
13
|
+
s.homepage = %q{https://github.com/pgharts/trusty-reorder-extension}
|
14
|
+
s.summary = %q{Extends Trusty CMS to allow page ordering}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
|
19
|
+
ignores = if File.exist?('.gitignore')
|
20
|
+
File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
s.files = Dir['**/*'] - ignores
|
25
|
+
s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
|
26
|
+
# s.executables = Dir['bin/*'] - ignores
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.add_dependency "acts_as_list", "0.4.0"
|
29
|
+
s.add_dependency "trusty-cms", "~> 1.0.1"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trusty-reorder-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Sipple
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: acts_as_list
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.4.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: trusty-cms
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.1
|
46
|
+
description: Extends Trusty CMS to allow page ordering
|
47
|
+
email: sipple@trustarts.org
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files:
|
51
|
+
- README.md
|
52
|
+
files:
|
53
|
+
- app/assets/images/admin/move_higher.png
|
54
|
+
- app/assets/images/admin/move_lower.png
|
55
|
+
- app/assets/images/admin/move_to_bottom.png
|
56
|
+
- app/assets/images/admin/move_to_top.png
|
57
|
+
- app/assets/stylesheets/admin/reorder.scss
|
58
|
+
- app/views/admin/pages/_header.html.haml
|
59
|
+
- app/views/admin/pages/_order.html.haml
|
60
|
+
- app/views/admin/pages/_order_header.html.haml
|
61
|
+
- config/routes.rb
|
62
|
+
- db/migrate/01_add_position_to_pages.rb
|
63
|
+
- lib/reorder/engine.rb
|
64
|
+
- lib/reorder/page_extensions.rb
|
65
|
+
- lib/reorder/page_helper.rb
|
66
|
+
- lib/reorder/pages_controller_extensions.rb
|
67
|
+
- lib/reorder/tag_extensions.rb
|
68
|
+
- lib/tasks/reorder_extension_tasks.rake
|
69
|
+
- lib/trusty-reorder-extension.rb
|
70
|
+
- Rakefile
|
71
|
+
- README.md
|
72
|
+
- reorder_extension.rb
|
73
|
+
- spec/controllers/pages_controller_extensions_spec.rb
|
74
|
+
- spec/datasets/pages_with_positions.rb
|
75
|
+
- spec/model/page_extensions_spec.rb
|
76
|
+
- spec/model/tag_extensions_spec.rb
|
77
|
+
- spec/spec.opts
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- trusty-reorder-extension.gemspec
|
80
|
+
homepage: https://github.com/pgharts/trusty-reorder-extension
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.29
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Extends Trusty CMS to allow page ordering
|
104
|
+
test_files:
|
105
|
+
- spec/controllers/pages_controller_extensions_spec.rb
|
106
|
+
- spec/datasets/pages_with_positions.rb
|
107
|
+
- spec/model/page_extensions_spec.rb
|
108
|
+
- spec/model/tag_extensions_spec.rb
|
109
|
+
- spec/spec.opts
|
110
|
+
- spec/spec_helper.rb
|