radiant-page_list_view-extension 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/HELP.textile +23 -0
- data/README.textile +51 -0
- data/Rakefile +136 -0
- data/app/helpers/admin/list_view_helper.rb +63 -0
- data/app/views/admin/pages/_page.html.haml +18 -0
- data/app/views/admin/pages/page_list_view.html.haml +44 -0
- data/config/routes.rb +3 -0
- data/lib/page_list_view/admin_page_controller_extensions.rb +17 -0
- data/lib/page_list_view/page_extensions.rb +18 -0
- data/lib/tasks/page_list_view_extension_tasks.rake +28 -0
- data/page_list_view_extension.rb +18 -0
- data/pkg/radiant-page_list_view-extension-0.9.1.gem +0 -0
- data/public/images/admin/application_cascade.png +0 -0
- data/public/images/admin/application_side_tree.png +0 -0
- data/public/images/admin/application_view_detail.png +0 -0
- data/public/images/admin/application_view_list.png +0 -0
- data/public/javascripts/admin/tablekit.js +926 -0
- data/radiant-page_list_view-extension.gemspec +65 -0
- data/spec/controllers/admin_page_controller_extensions_spec.rb +63 -0
- data/spec/models/page_extensions_spec.rb +25 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +39 -0
- metadata +107 -0
data/.gitmodules
ADDED
data/HELP.textile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
The *Page List View* extension, as its name implies, enables you to view all pages on your site in a list view, sortable by attribute.
|
2
|
+
|
3
|
+
h2. Usage
|
4
|
+
|
5
|
+
h3. Display the Page List
|
6
|
+
|
7
|
+
Click on the 'Page List' tab, to the right of 'Pages' under 'Content' The list can be sorted in ascending or descending order by any of the column heading attributes
|
8
|
+
|
9
|
+
h3. Selecting Column Headings
|
10
|
+
|
11
|
+
To select column headings you want to display, add @page_list_view.display_attributes@ to the @Radiant::Config@ (config) table. Enter the value space-delimited attributes, e.g. "title parent_title slug template_name status_name updated_by_name updated_at". If you use the settings extension, you can do this via the admin panel.
|
12
|
+
|
13
|
+
h3. Pagination
|
14
|
+
|
15
|
+
To configure lines (listed pages) per page, add a setting to the @Radiant::Config@ (config) table. The value must be a whole number. If not entered the default is 50. If you use the settings extension, you can do this via the admin panel.
|
16
|
+
|
17
|
+
h4. Radiant >= 0.9.1
|
18
|
+
|
19
|
+
Use the built-in @admin.pagination.per_page@ setting
|
20
|
+
|
21
|
+
h4. Radiant < 0.9.1
|
22
|
+
|
23
|
+
Use the @page_list_view.per_page@ setting
|
data/README.textile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
h2. Page List View
|
2
|
+
|
3
|
+
Created by: Andrew vonderLuft and Sean Cribbs, August 2008, in Portland Oregon
|
4
|
+
|
5
|
+
Enables viewing site pages in a list view sortable by attribute.
|
6
|
+
|
7
|
+
h2. Revision History
|
8
|
+
|
9
|
+
* 0.9.1 - 4/2011 - updated for Radiant >= 0.9.1, using built-in pagination, move Page List to tab
|
10
|
+
* 0.9.0 - adjusted views and css for 0.9.0 compatibility, fixed spec
|
11
|
+
* 0.8.2 - 6/2010 - tagging 0.8.2, adjusting version to correspond with radiant version compatibility
|
12
|
+
* 1.3 - 1/2010 - Radiant 0.8 compatible, added configurable column heading
|
13
|
+
* 1.2 - 2/2009 - Radiant 0.7 compatible, including Rails 2.2
|
14
|
+
* 1.1 - 1/2009 - added pagination / full list options for CMSs with lots of pages
|
15
|
+
* 1.0 - 8/2008 - initial release
|
16
|
+
|
17
|
+
h2. Requirements
|
18
|
+
|
19
|
+
h3. Radiant >= 0.9.1
|
20
|
+
|
21
|
+
none. will_paginate is included
|
22
|
+
|
23
|
+
h3. Radiant < 0.9.1
|
24
|
+
|
25
|
+
With older version you will need the will_paginate plugin - add Mislav's will_paginate plugin to your vendor/plugins directory. See https://github.com/mislav/will_paginate/tree/master
|
26
|
+
|
27
|
+
To install this plugin, from extension root:
|
28
|
+
<pre>
|
29
|
+
$ git submodule init
|
30
|
+
$ git submodule update
|
31
|
+
</pre>
|
32
|
+
|
33
|
+
h2. Installation
|
34
|
+
|
35
|
+
From your RADIANT_ROOT:
|
36
|
+
|
37
|
+
<pre>
|
38
|
+
$ script/extension install page_list_view
|
39
|
+
</pre>
|
40
|
+
|
41
|
+
Restart your radiant app, and you should be good to go.
|
42
|
+
|
43
|
+
NOTE: This _should_ add the submodules for older versions, described above in requirements, but if not follow the directions indicated.
|
44
|
+
|
45
|
+
h2. Usage
|
46
|
+
|
47
|
+
See the Help doc.
|
48
|
+
|
49
|
+
h2. Acknowledgments
|
50
|
+
|
51
|
+
As usual, Sean Cribbs helped out a lot with the finer points of Ruby, Rails and Radiant
|
data/Rakefile
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "radiant-page_list_view-extension"
|
5
|
+
gem.summary = %Q{Page List View Extension for Radiant CMS}
|
6
|
+
gem.description = %Q{Enables viewing site pages in a list sortable by attibute.}
|
7
|
+
gem.email = "avonderluft@avlux.net"
|
8
|
+
gem.homepage = "https://github.com/avonderluft/radiant-page_list_view-extension"
|
9
|
+
gem.authors = ['Andrew vonderLuft','Sean Cribbs']
|
10
|
+
gem.add_dependency 'radiant', ">=0.9.1"
|
11
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler (or a dependency) not available. This is only required if you plan to package banner_rotator as a gem."
|
15
|
+
end
|
16
|
+
|
17
|
+
# I think this is the one that should be moved to the extension Rakefile template
|
18
|
+
|
19
|
+
# In rails 1.2, plugins aren't available in the path until they're loaded.
|
20
|
+
# Check to see if the rspec plugin is installed first and require
|
21
|
+
# it if it is. If not, use the gem version.
|
22
|
+
|
23
|
+
# Determine where the RSpec plugin is by loading the boot
|
24
|
+
unless defined? RADIANT_ROOT
|
25
|
+
ENV["RAILS_ENV"] = "test"
|
26
|
+
case
|
27
|
+
when ENV["RADIANT_ENV_FILE"]
|
28
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
29
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
30
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
31
|
+
else
|
32
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rake'
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
require 'rake/testtask'
|
39
|
+
|
40
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
41
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
42
|
+
require 'spec/rake/spectask'
|
43
|
+
# require 'spec/translator'
|
44
|
+
|
45
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
46
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
47
|
+
|
48
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
49
|
+
|
50
|
+
task :default => :spec
|
51
|
+
task :stats => "spec:statsetup"
|
52
|
+
|
53
|
+
desc "Run all specs in spec directory"
|
54
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
55
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
56
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
57
|
+
end
|
58
|
+
|
59
|
+
namespace :spec do
|
60
|
+
desc "Run all specs in spec directory with RCov"
|
61
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
62
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
63
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
64
|
+
t.rcov = true
|
65
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Print Specdoc for all specs"
|
69
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
70
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
71
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
72
|
+
end
|
73
|
+
|
74
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
75
|
+
desc "Run the specs under spec/#{sub}"
|
76
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
77
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
78
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Hopefully no one has written their extensions in pre-0.9 style
|
83
|
+
# desc "Translate specs from pre-0.9 to 0.9 style"
|
84
|
+
# task :translate do
|
85
|
+
# translator = ::Spec::Translator.new
|
86
|
+
# dir = RAILS_ROOT + '/spec'
|
87
|
+
# translator.translate(dir, dir)
|
88
|
+
# end
|
89
|
+
|
90
|
+
# Setup specs for stats
|
91
|
+
task :statsetup do
|
92
|
+
require 'code_statistics'
|
93
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
94
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
95
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
96
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
97
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
98
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
99
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
100
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
101
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
102
|
+
end
|
103
|
+
|
104
|
+
namespace :db do
|
105
|
+
namespace :fixtures do
|
106
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
107
|
+
task :load => :environment do
|
108
|
+
require 'active_record/fixtures'
|
109
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
110
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
111
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
desc 'Generate documentation for the page_list_view extension.'
|
119
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
120
|
+
rdoc.rdoc_dir = 'rdoc'
|
121
|
+
rdoc.title = 'PageListViewExtension'
|
122
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
123
|
+
rdoc.rdoc_files.include('README')
|
124
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
125
|
+
end
|
126
|
+
|
127
|
+
# For extensions that are in transition
|
128
|
+
desc 'Test the page_list_view extension.'
|
129
|
+
Rake::TestTask.new(:test) do |t|
|
130
|
+
t.libs << 'lib'
|
131
|
+
t.pattern = 'test/**/*_test.rb'
|
132
|
+
t.verbose = true
|
133
|
+
end
|
134
|
+
|
135
|
+
# Load any custom rakefiles for extension
|
136
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Admin::ListViewHelper
|
2
|
+
|
3
|
+
def link_or_span_unless_current(params, text, url, options)
|
4
|
+
if options[:id] == params[:view]
|
5
|
+
content_tag(:span, text)
|
6
|
+
else
|
7
|
+
link_to text, url, options
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_display_attributes
|
12
|
+
display_atts = []
|
13
|
+
unless config['page_list_view.display_attributes'].nil?
|
14
|
+
config['page_list_view.display_attributes'].split.each do |att|
|
15
|
+
display_atts << att if Page.column_names.include?("#{att}") || Page.instance_methods.include?("#{att}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
display_atts = %w{title parent_title slug class_name status_name updated_by_name updated_at} if display_atts.empty?
|
19
|
+
@list_display_attributes ||= returning display_atts do |atts|
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def shorten_display(value, max_length)
|
24
|
+
value.length > max_length + 3 ? value.slice(0,max_length) + "..." : value
|
25
|
+
end
|
26
|
+
|
27
|
+
def nicify(key,value)
|
28
|
+
value = "" if value.nil?
|
29
|
+
case value
|
30
|
+
when String
|
31
|
+
key=="title" ? shorten_display(value,24) : shorten_display(value,12)
|
32
|
+
when ActiveSupport::TimeWithZone || Time
|
33
|
+
value.strftime(fmt="%m/%d/%Y at %I:%M %p")
|
34
|
+
else
|
35
|
+
shorten_display(value.to_s,12)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def attribute_header_class(att)
|
40
|
+
@saved_order ||= if cookies['table_kit_order']
|
41
|
+
ActiveSupport::JSON.decode(CGI.unescape(cookies['table_kit_order']))
|
42
|
+
else
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
returning %W{page-#{att}} do |classes|
|
46
|
+
classes << 'date-us-civil' if att =~ /(updated|created)_(at|on)/
|
47
|
+
if @saved_order[0] && @list_display_attributes.index(att) == @saved_order[0]
|
48
|
+
direction = @saved_order[1].to_i < 0 ? "desc" : "asc"
|
49
|
+
classes << "sortfirst#{direction}"
|
50
|
+
end
|
51
|
+
end.join(" ")
|
52
|
+
end
|
53
|
+
|
54
|
+
def attribute_header_id(att)
|
55
|
+
"#{att}-header"
|
56
|
+
end
|
57
|
+
|
58
|
+
def attribute_cell_class(att)
|
59
|
+
returning %w{page} do |classes|
|
60
|
+
# classes << 'date-short' if att =~ /(updated|created)_(at|on)/
|
61
|
+
end.join(" ")
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
%tr.level_2.page
|
2
|
+
- list_display_attributes.each do |att|
|
3
|
+
- case att
|
4
|
+
- when 'title'
|
5
|
+
%td.name{:title => page.title, :style=>"white-space:nowrap"}
|
6
|
+
= image('page', :alt => '')
|
7
|
+
= link_to nicify(att,page.send(att)), edit_admin_page_url(page)
|
8
|
+
- when 'parent_title'
|
9
|
+
- unless page.parent.blank?
|
10
|
+
%td.name{:title => page.parent.title, :style => "font-size: 90%;white-space:nowrap"}
|
11
|
+
= image('page', :alt => '', :height => '20px')
|
12
|
+
= link_to nicify(att,page.send(att)), edit_admin_page_url(page.parent)
|
13
|
+
- else
|
14
|
+
%td.status{:title => "No parent", :style => "font-size: 90%;padding-left:30px"}= "(none)"
|
15
|
+
- when 'slug'
|
16
|
+
%td.status{:title => page.url}= nicify(att,page.send(att))
|
17
|
+
- else
|
18
|
+
%td.status{:title => page.send(att)}= nicify(att,page.send(att))
|
@@ -0,0 +1,44 @@
|
|
1
|
+
- include_javascript 'admin/tablekit'
|
2
|
+
- include_javascript 'admin/ruledtable'
|
3
|
+
- @page_title = t('pages') + ' - ' + default_page_title
|
4
|
+
|
5
|
+
.outset
|
6
|
+
= render_region :top
|
7
|
+
%table.index.sortable{:summary=>"Sortable list of pages"}
|
8
|
+
%thead
|
9
|
+
%tr
|
10
|
+
- list_display_attributes.each do |att|
|
11
|
+
%th{:class => attribute_header_class(att), :id => attribute_header_id(att) }
|
12
|
+
%a
|
13
|
+
%span.w1= att.humanize
|
14
|
+
%tbody
|
15
|
+
- if @pages.any?
|
16
|
+
= render :partial => 'page', :collection => @pages
|
17
|
+
- else
|
18
|
+
%tr
|
19
|
+
%td.empty{:colspan => list_display_attributes.length}= t('no_pages')
|
20
|
+
#actions
|
21
|
+
= pagination_for(@pages)
|
22
|
+
%ul
|
23
|
+
- unless @pages.any?
|
24
|
+
%li= link_to image('plus') + " " + t("new_homepage"), new_admin_page_path, :class => 'action_button'
|
25
|
+
|
26
|
+
- content_for :page_css do
|
27
|
+
:sass
|
28
|
+
#content
|
29
|
+
table.index.sortable
|
30
|
+
th
|
31
|
+
padding: 2px 14px
|
32
|
+
background-position: 98% center
|
33
|
+
background-repeat: no-repeat
|
34
|
+
&.sortasc
|
35
|
+
background-image: url(/images/admin/move_lower.png)
|
36
|
+
background-color: #ccc
|
37
|
+
&.sortdesc
|
38
|
+
background-image: url(/images/admin/move_higher.png)
|
39
|
+
background-color: #ccc
|
40
|
+
a
|
41
|
+
color: white
|
42
|
+
text-decoration: underline
|
43
|
+
&:hover
|
44
|
+
text-decoration: none
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module PageListView::AdminPageControllerExtensions
|
2
|
+
def self.included(base)
|
3
|
+
base.class_eval {
|
4
|
+
alias_method_chain :index, :page_list_view
|
5
|
+
model_class Page
|
6
|
+
paginate_models
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
def index_with_page_list_view
|
11
|
+
if params[:view] && params[:view] == 'list'
|
12
|
+
render :action => "page_list_view" and return
|
13
|
+
else
|
14
|
+
index_without_page_list_view
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PageListView::PageExtensions
|
2
|
+
def parent_title
|
3
|
+
parent.title if parent
|
4
|
+
end
|
5
|
+
|
6
|
+
def group_name
|
7
|
+
group.name if group
|
8
|
+
end
|
9
|
+
|
10
|
+
def updated_by_name
|
11
|
+
updated_by.name if updated_by
|
12
|
+
end
|
13
|
+
|
14
|
+
def status_name
|
15
|
+
status.name if status
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :page_list_view do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Page List View extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
PageListViewExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
else
|
11
|
+
PageListViewExtension.migrator.migrate
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Copies public assets of the Page List View to the instance public/ directory."
|
16
|
+
task :update => :environment do
|
17
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
18
|
+
Dir[PageListViewExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
19
|
+
path = file.sub(PageListViewExtension.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,18 @@
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
2
|
+
require_dependency 'application_controller'
|
3
|
+
|
4
|
+
class PageListViewExtension < Radiant::Extension
|
5
|
+
version "#{File.read(File.expand_path(File.dirname(__FILE__)) + '/VERSION')}"
|
6
|
+
description "Enables viewing site pages in a list sortable by attibute"
|
7
|
+
url "https://github.com/avonderluft/radiant-page_list_view-extension"
|
8
|
+
|
9
|
+
def activate
|
10
|
+
tab "Content" do
|
11
|
+
add_item "Page List", '/admin/pages/list', :after => "Pages"
|
12
|
+
end
|
13
|
+
Page.send :include, PageListView::PageExtensions
|
14
|
+
Admin::PagesController.send :include, PageListView::AdminPageControllerExtensions
|
15
|
+
Admin::PagesController.send :helper, Admin::ListViewHelper
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
Binary file
|
Binary file
|