jakewendt-pages 0.1.2
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.rdoc +55 -0
- data/app/controllers/locales_controller.rb +15 -0
- data/app/controllers/pages_controller.rb +138 -0
- data/app/models/page.rb +99 -0
- data/app/models/page_sweeper.rb +74 -0
- data/app/views/pages/_child.html.erb +23 -0
- data/app/views/pages/_form.html.erb +44 -0
- data/app/views/pages/_page.html.erb +35 -0
- data/app/views/pages/edit.html.erb +9 -0
- data/app/views/pages/index.html.erb +28 -0
- data/app/views/pages/new.html.erb +9 -0
- data/app/views/pages/show.html.erb +29 -0
- data/app/views/pages/translate.js.erb +42 -0
- data/config/routes.rb +9 -0
- data/generators/pages/USAGE +0 -0
- data/generators/pages/pages_generator.rb +66 -0
- data/generators/pages/templates/functional/locales_controller_test.rb +59 -0
- data/generators/pages/templates/functional/pages_controller_test.rb +248 -0
- data/generators/pages/templates/images/drag.gif +0 -0
- data/generators/pages/templates/javascripts/pages.js +39 -0
- data/generators/pages/templates/migrations/create_pages.rb +26 -0
- data/generators/pages/templates/stylesheets/page.css +17 -0
- data/generators/pages/templates/stylesheets/pages.css +22 -0
- data/generators/pages/templates/unit/page_test.rb +185 -0
- data/generators/pages/templates/unit/redcloth_extension_test.rb +64 -0
- data/lib/pages.rb +42 -0
- data/lib/pages/factories.rb +6 -0
- data/lib/pages/pending.rb +72 -0
- data/lib/pages/redcloth/formatters/html.rb +23 -0
- data/lib/pages/tasks.rb +1 -0
- metadata +349 -0
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
var initial_page_order;
|
2
|
+
jQuery(function(){
|
3
|
+
jQuery('#pages').sortable({
|
4
|
+
axis:'y',
|
5
|
+
dropOnEmpty:false,
|
6
|
+
handle:'img.handle',
|
7
|
+
update:function(event,ui){compare_page_order()},
|
8
|
+
items:'tr.page.row'
|
9
|
+
});
|
10
|
+
|
11
|
+
jQuery('#save_order').disable();
|
12
|
+
|
13
|
+
initial_page_order = page_order();
|
14
|
+
|
15
|
+
jQuery('form#order_pages').submit(function(){
|
16
|
+
if( initial_page_order == page_order() ) {
|
17
|
+
/*
|
18
|
+
Shouldn't get here as button should
|
19
|
+
be disabled if not different!
|
20
|
+
*/
|
21
|
+
alert("Page order hasn't changed. Nothing to save.");
|
22
|
+
return false
|
23
|
+
}
|
24
|
+
})
|
25
|
+
|
26
|
+
});
|
27
|
+
|
28
|
+
function page_order() {
|
29
|
+
return jQuery('#pages').sortable('serialize',{key:'pages[]'});
|
30
|
+
}
|
31
|
+
|
32
|
+
function compare_page_order(){
|
33
|
+
if( initial_page_order == page_order() ) {
|
34
|
+
jQuery('#save_order').disable();
|
35
|
+
} else {
|
36
|
+
jQuery('#save_order').highlight(4000);
|
37
|
+
jQuery('#save_order').enable();
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreatePages < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :pages do |t|
|
4
|
+
t.integer :position
|
5
|
+
t.integer :parent_id
|
6
|
+
t.boolean :hide_menu, :default => false
|
7
|
+
t.string :path
|
8
|
+
t.string :title_en
|
9
|
+
t.string :title_es
|
10
|
+
t.string :menu_en
|
11
|
+
t.string :menu_es
|
12
|
+
t.text :body_en
|
13
|
+
t.text :body_es
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
add_index :pages, :path, :unique => true
|
17
|
+
add_index :pages, :parent_id
|
18
|
+
# acts_as_list doesn't like the uniqueness
|
19
|
+
# when it reorders, positions are temporarily not unique
|
20
|
+
# add_index :pages, :position, :unique => true, :name => 'by_position'
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
drop_table :pages
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
.page img.handle {
|
2
|
+
}
|
3
|
+
.page .position {
|
4
|
+
font-weight:bold;
|
5
|
+
text-align:center;
|
6
|
+
}
|
7
|
+
.page .path {
|
8
|
+
width: 140px;
|
9
|
+
}
|
10
|
+
.page .menu {
|
11
|
+
width: 140px;
|
12
|
+
}
|
13
|
+
.page .title {
|
14
|
+
width: 140px;
|
15
|
+
}
|
16
|
+
.page .manage {
|
17
|
+
text-align:right;
|
18
|
+
}
|
19
|
+
|
20
|
+
.page.row.ui-sortable-helper {
|
21
|
+
border: 1px dashed #E7C254;
|
22
|
+
}
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class Pages::PageTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
assert_should_require(:path,:menu_en,:title_en,:body_en,
|
6
|
+
:model => 'Page')
|
7
|
+
assert_should_require_unique(:path,:menu_en,
|
8
|
+
:model => 'Page')
|
9
|
+
|
10
|
+
test "should create page" do
|
11
|
+
assert_difference 'Page.count' do
|
12
|
+
page = create_page
|
13
|
+
assert !page.new_record?,
|
14
|
+
"#{page.errors.full_messages.to_sentence}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "should require path begin with slash" do
|
19
|
+
assert_no_difference 'Page.count' do
|
20
|
+
page = create_page(:path => 'Hey')
|
21
|
+
assert page.errors.on(:path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should require 1 char path" do
|
26
|
+
assert_no_difference 'Page.count' do
|
27
|
+
page = create_page(:path => '')
|
28
|
+
assert page.errors.on(:path)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should require 4 char menu_en" do
|
33
|
+
assert_no_difference 'Page.count' do
|
34
|
+
page = create_page(:menu_en => 'Hey')
|
35
|
+
assert page.errors.on(:menu_en)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test "should require 4 char title_en" do
|
40
|
+
assert_no_difference 'Page.count' do
|
41
|
+
page = create_page(:title_en => 'Hey')
|
42
|
+
assert page.errors.on(:title_en)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test "should require 4 char body_en" do
|
47
|
+
assert_no_difference 'Page.count' do
|
48
|
+
page = create_page(:body_en => 'Hey')
|
49
|
+
assert page.errors.on(:body_en)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test "should filter out multiple continguous slashes" do
|
54
|
+
page = create_page(:path => "///a//b///c" )
|
55
|
+
assert_equal "/a/b/c", page.path
|
56
|
+
end
|
57
|
+
|
58
|
+
test "should downcase path" do
|
59
|
+
page = create_page(:path => "/A/B/C")
|
60
|
+
assert_equal "/a/b/c", page.path
|
61
|
+
end
|
62
|
+
|
63
|
+
test "can have a parent" do
|
64
|
+
parent = create_page
|
65
|
+
page = create_page( :parent_id => parent.id )
|
66
|
+
assert_equal page.reload.parent, parent
|
67
|
+
end
|
68
|
+
|
69
|
+
test "should return self as root with no parent" do
|
70
|
+
page = create_page
|
71
|
+
assert_equal page, page.root
|
72
|
+
end
|
73
|
+
|
74
|
+
test "should return parent as root with parent" do
|
75
|
+
parent = create_page
|
76
|
+
page = create_page( :parent_id => parent.id )
|
77
|
+
assert_equal parent, page.reload.root
|
78
|
+
end
|
79
|
+
|
80
|
+
test "should nullify parent_id of children when parent destroyed" do
|
81
|
+
parent = create_page
|
82
|
+
child = create_page( :parent_id => parent.id )
|
83
|
+
assert_equal child.reload.parent_id, parent.id
|
84
|
+
parent.destroy
|
85
|
+
assert_nil child.reload.parent_id
|
86
|
+
end
|
87
|
+
|
88
|
+
test "should return false if page is not home" do
|
89
|
+
page = create_page
|
90
|
+
assert !page.is_home?
|
91
|
+
end
|
92
|
+
|
93
|
+
test "should return true if page is home" do
|
94
|
+
page = create_page(:path => '/')
|
95
|
+
assert page.is_home?
|
96
|
+
end
|
97
|
+
|
98
|
+
test "should create page with hide_menu true" do
|
99
|
+
assert_difference('Page.count',1){
|
100
|
+
assert_difference('Page.roots.count',0){
|
101
|
+
page = create_page(:hide_menu => true)
|
102
|
+
# assert_equal 1, Page.count
|
103
|
+
# assert_equal 0, Page.roots.count
|
104
|
+
assert_not_nil Page.find(page)
|
105
|
+
assert_not_nil Page.find(page.id)
|
106
|
+
assert_not_nil Page.find_by_path(page.path)
|
107
|
+
} }
|
108
|
+
end
|
109
|
+
|
110
|
+
test "should find page by path" do
|
111
|
+
p = create_page
|
112
|
+
page = Page.by_path(p.path)
|
113
|
+
assert_equal p, page
|
114
|
+
end
|
115
|
+
|
116
|
+
test "should return english menu without locale" do
|
117
|
+
p = create_page
|
118
|
+
assert_equal p.menu, p.menu_en
|
119
|
+
end
|
120
|
+
|
121
|
+
test "should return english title without locale" do
|
122
|
+
p = create_page
|
123
|
+
assert_equal p.title, p.title_en
|
124
|
+
end
|
125
|
+
|
126
|
+
test "should return english body without locale" do
|
127
|
+
p = create_page
|
128
|
+
assert_equal p.body, p.body_en
|
129
|
+
end
|
130
|
+
|
131
|
+
test "should return english menu with locale" do
|
132
|
+
p = create_page
|
133
|
+
assert_equal p.menu('en'), p.menu_en
|
134
|
+
end
|
135
|
+
|
136
|
+
test "should return english title with locale" do
|
137
|
+
p = create_page
|
138
|
+
assert_equal p.title('en'), p.title_en
|
139
|
+
end
|
140
|
+
|
141
|
+
test "should return english body with locale" do
|
142
|
+
p = create_page
|
143
|
+
assert_equal p.body('en'), p.body_en
|
144
|
+
end
|
145
|
+
|
146
|
+
test "should return spanish menu with locale" do
|
147
|
+
p = create_page(:menu_es => 'spanish menu')
|
148
|
+
assert_equal p.menu('es'), p.menu_es
|
149
|
+
end
|
150
|
+
|
151
|
+
test "should return spanish title with locale" do
|
152
|
+
p = create_page(:title_es => 'spanish title')
|
153
|
+
assert_equal p.title('es'), p.title_es
|
154
|
+
end
|
155
|
+
|
156
|
+
test "should return spanish body with locale" do
|
157
|
+
p = create_page(:body_es => 'spanish body')
|
158
|
+
assert_equal p.body('es'), p.body_es
|
159
|
+
end
|
160
|
+
|
161
|
+
test "should return english menu with missing spanish locale" do
|
162
|
+
p = create_page(:menu_es => '')
|
163
|
+
assert_equal p.menu('es'), p.menu_en
|
164
|
+
end
|
165
|
+
|
166
|
+
test "should return english title with missing spanish locale" do
|
167
|
+
p = create_page(:title_es => '')
|
168
|
+
assert_equal p.title('es'), p.title_en
|
169
|
+
end
|
170
|
+
|
171
|
+
test "should return english body with missing spanish locale" do
|
172
|
+
p = create_page(:body_es => '')
|
173
|
+
assert_equal p.body('es'), p.body_en
|
174
|
+
end
|
175
|
+
|
176
|
+
protected
|
177
|
+
|
178
|
+
def create_page(options = {})
|
179
|
+
record = Factory.build(:page,options)
|
180
|
+
record.save
|
181
|
+
record
|
182
|
+
end
|
183
|
+
alias_method :create_object, :create_page
|
184
|
+
|
185
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class Pages::RedClothExtensionTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
teardown :destroy_relative_url_root
|
6
|
+
|
7
|
+
test "should NOT add relative url root to link when blank" do
|
8
|
+
html = textilize('"Link Text":/link/path')
|
9
|
+
#=> "<p><a href=\"/link/path\">Link Text</a></p>"
|
10
|
+
assert_match(/a href="\/link\/path"/,html)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should add relative url root to link when not blank" do
|
14
|
+
ActionController::Base.relative_url_root = "/prefix"
|
15
|
+
html = textilize('"Link Text":/link/path')
|
16
|
+
#=> "<p><a href=\"/prefix/link/path\">Link Text</a></p>"
|
17
|
+
assert_match(/a href="\/prefix\/link\/path"/,html)
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should NOT add relative url root to image href when blank" do
|
21
|
+
html = textilize('!/path/to/image.jpg!:/link/path')
|
22
|
+
#=> "<p><a href=\"/link/path\">
|
23
|
+
# <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
|
24
|
+
assert_match(/a href="\/link\/path"/,html)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should add relative url root to image href when not blank" do
|
28
|
+
ActionController::Base.relative_url_root = "/prefix"
|
29
|
+
html = textilize('!/path/to/image.jpg!:/link/path')
|
30
|
+
#=> "<p><a href=\"/link/path\">
|
31
|
+
# <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
|
32
|
+
assert_match(/a href="\/prefix\/link\/path"/,html)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "should NOT add relative url root to image src when blank" do
|
36
|
+
html = textilize('!/path/to/image.jpg!:/link/path')
|
37
|
+
#=> "<p><a href=\"/link/path\">
|
38
|
+
# <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
|
39
|
+
assert_match(/img src="\/path\/to\/image\.jpg"/,html)
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should add relative url root to image src when not blank" do
|
43
|
+
ActionController::Base.relative_url_root = "/prefix"
|
44
|
+
html = textilize('!/path/to/image.jpg!:/link/path')
|
45
|
+
#=> "<p><a href=\"/link/path\">
|
46
|
+
# <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
|
47
|
+
assert_match(/img src="\/prefix\/path\/to\/image\.jpg"/,html)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Add tests for when
|
52
|
+
# relative_url_root is nil
|
53
|
+
# paths are absolute
|
54
|
+
# paths are relative to current location ('../......')
|
55
|
+
# there is no path, just the file
|
56
|
+
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def destroy_relative_url_root
|
61
|
+
ActionController::Base.relative_url_root = nil #''
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/lib/pages.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'ruby_extension'
|
2
|
+
require 'rails_helpers'
|
3
|
+
require 'authorized'
|
4
|
+
require 'gravatar'
|
5
|
+
require 'calnet_authenticated'
|
6
|
+
require 'acts_as_list'
|
7
|
+
module Pages
|
8
|
+
# predefine namespace
|
9
|
+
end
|
10
|
+
|
11
|
+
# This doesn't seem necessary
|
12
|
+
%w{models controllers}.each do |dir|
|
13
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), '../app', dir))
|
14
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
15
|
+
ActiveSupport::Dependencies.autoload_once_paths << path
|
16
|
+
end
|
17
|
+
|
18
|
+
HTML::WhiteListSanitizer.allowed_attributes.merge(%w(
|
19
|
+
id class style
|
20
|
+
))
|
21
|
+
|
22
|
+
require 'pages/redcloth/formatters/html'
|
23
|
+
|
24
|
+
if !defined?(RAILS_ENV) || RAILS_ENV == 'test'
|
25
|
+
require 'active_support'
|
26
|
+
require 'active_support/test_case'
|
27
|
+
require 'factory_girl'
|
28
|
+
require 'assert_this_and_that'
|
29
|
+
require 'pages/factories'
|
30
|
+
require 'pages/pending'
|
31
|
+
end
|
32
|
+
|
33
|
+
ActionController::Routing::Routes.add_configuration_file(
|
34
|
+
File.expand_path(
|
35
|
+
File.join(
|
36
|
+
File.dirname(__FILE__), '../config/routes.rb')))
|
37
|
+
|
38
|
+
ActionController::Base.view_paths <<
|
39
|
+
File.expand_path(
|
40
|
+
File.join(
|
41
|
+
File.dirname(__FILE__), '../app/views'))
|
42
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Some code from jeremymcanally's "pending"
|
2
|
+
# http://github.com/jeremymcanally/pending/tree/master
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
module Testing
|
6
|
+
module Pending
|
7
|
+
|
8
|
+
unless defined?(Spec)
|
9
|
+
|
10
|
+
@@pending_cases = []
|
11
|
+
@@at_exit = false
|
12
|
+
|
13
|
+
def pending(description = "", &block)
|
14
|
+
if description.is_a?(Symbol)
|
15
|
+
is_pending = $tags[description]
|
16
|
+
return block.call unless is_pending
|
17
|
+
end
|
18
|
+
|
19
|
+
if block_given?
|
20
|
+
failed = false
|
21
|
+
|
22
|
+
begin
|
23
|
+
block.call
|
24
|
+
rescue Exception
|
25
|
+
failed = true
|
26
|
+
end
|
27
|
+
|
28
|
+
flunk("<#{description}> did not fail.") unless failed
|
29
|
+
end
|
30
|
+
|
31
|
+
caller[0] =~ (/(.*):(.*):in `(.*)'/)
|
32
|
+
#puts caller.inspect
|
33
|
+
|
34
|
+
# looks like we lose the name of the 'method' in 1.9.1
|
35
|
+
#"/Users/jakewendt/github_repo/jakewendt/ucb_ccls_homex/test/unit/subject_test.rb:145:in `block in <class:SubjectTest>'",
|
36
|
+
|
37
|
+
# @@pending_cases << "#{$3} at #{$1}, line #{$2}"
|
38
|
+
# Gotta remember these as the next Regex will overwrite them.
|
39
|
+
filename = $1
|
40
|
+
linenumber = $2
|
41
|
+
# ruby 1.8.7
|
42
|
+
# Hx/Addresses Controller should NOT create new address with employee login and invalid address:
|
43
|
+
# ruby 1.9.1
|
44
|
+
#Hx/Addresses Controller block (2 levels) in <class:AddressesControllerTest>:
|
45
|
+
testmethod = $3
|
46
|
+
|
47
|
+
model = self.class.to_s.gsub(/Test$/,'').titleize
|
48
|
+
method = testmethod.gsub(/_/,' ').gsub(/^test /,'')
|
49
|
+
@@pending_cases << "#{model} #{method}:\n.\t#{filename} line #{linenumber}"
|
50
|
+
# @@pending_cases << "#{testmethod} at #{filename}, line #{linenumber}"
|
51
|
+
print "P"
|
52
|
+
|
53
|
+
@@at_exit ||= begin
|
54
|
+
at_exit do
|
55
|
+
# For some reason, special characters don't always
|
56
|
+
# print the way you would expect. Leading white space (tabs)
|
57
|
+
# and some carriage returns just weren't happening?
|
58
|
+
# Is this at_exit doing some parsing??
|
59
|
+
puts "\nPending Cases:"
|
60
|
+
@@pending_cases.each do |test_case|
|
61
|
+
puts test_case
|
62
|
+
end
|
63
|
+
puts " \n"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
ActiveSupport::TestCase.send(:include, ActiveSupport::Testing::Pending)
|