cortex-reaver 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cortex_reaver +7 -2
- data/lib/cortex_reaver.rb +51 -71
- data/lib/cortex_reaver/config.rb +23 -7
- data/lib/cortex_reaver/controller/admin.rb +6 -8
- data/lib/cortex_reaver/controller/comment.rb +17 -17
- data/lib/cortex_reaver/controller/config.rb +3 -2
- data/lib/cortex_reaver/controller/controller.rb +22 -0
- data/lib/cortex_reaver/controller/documentation.rb +1 -3
- data/lib/cortex_reaver/controller/journal.rb +13 -12
- data/lib/cortex_reaver/controller/main.rb +36 -29
- data/lib/cortex_reaver/controller/page.rb +15 -11
- data/lib/cortex_reaver/controller/photograph.rb +21 -15
- data/lib/cortex_reaver/controller/project.rb +16 -13
- data/lib/cortex_reaver/controller/tag.rb +16 -14
- data/lib/cortex_reaver/controller/user.rb +11 -13
- data/lib/cortex_reaver/helper/attachments.rb +18 -12
- data/lib/cortex_reaver/helper/auth.rb +2 -2
- data/lib/cortex_reaver/helper/canonical.rb +2 -2
- data/lib/cortex_reaver/helper/crud.rb +78 -38
- data/lib/cortex_reaver/helper/feeds.rb +2 -5
- data/lib/cortex_reaver/helper/form.rb +1 -1
- data/lib/cortex_reaver/helper/navigation.rb +1 -1
- data/lib/cortex_reaver/helper/photographs.rb +12 -3
- data/lib/cortex_reaver/helper/template.rb +37 -0
- data/lib/cortex_reaver/{view/blank_layout.rhtml → layout/blank.rhtml} +1 -1
- data/lib/cortex_reaver/{view/text_layout.rhtml → layout/text.rhtml} +1 -1
- data/lib/cortex_reaver/migrations/013_draft.rb +17 -0
- data/lib/cortex_reaver/model/comment.rb +64 -53
- data/lib/cortex_reaver/model/journal.rb +23 -21
- data/lib/cortex_reaver/model/model.rb +9 -0
- data/lib/cortex_reaver/model/page.rb +24 -42
- data/lib/cortex_reaver/model/photograph.rb +17 -17
- data/lib/cortex_reaver/model/project.rb +21 -18
- data/lib/cortex_reaver/model/tag.rb +12 -8
- data/lib/cortex_reaver/model/user.rb +79 -41
- data/lib/cortex_reaver/public/css/main.css +4 -0
- data/lib/cortex_reaver/snippets/numeric.rb +15 -0
- data/lib/cortex_reaver/snippets/ramaze/cache/memcached.rb +14 -0
- data/lib/cortex_reaver/support/attachments.rb +113 -105
- data/lib/cortex_reaver/support/cached_rendering.rb +65 -62
- data/lib/cortex_reaver/support/canonical.rb +82 -85
- data/lib/cortex_reaver/support/comments.rb +57 -51
- data/lib/cortex_reaver/support/cortex_reaver_validation_helpers.rb +13 -0
- data/lib/cortex_reaver/support/sequenceable.rb +202 -203
- data/lib/cortex_reaver/support/tags.rb +103 -94
- data/lib/cortex_reaver/support/timestamps.rb +27 -21
- data/lib/cortex_reaver/support/viewable.rb +17 -0
- data/lib/cortex_reaver/version.rb +3 -3
- data/lib/cortex_reaver/view/admin/index.rhtml +2 -2
- data/lib/cortex_reaver/view/comments/comment.rhtml +4 -1
- data/lib/cortex_reaver/view/comments/list.rhtml +1 -1
- data/lib/cortex_reaver/view/comments/post_form.rhtml +1 -1
- data/lib/cortex_reaver/view/journals/form.rhtml +3 -1
- data/lib/cortex_reaver/view/journals/journal.rhtml +6 -4
- data/lib/cortex_reaver/view/journals/list.rhtml +2 -2
- data/lib/cortex_reaver/view/journals/show.rhtml +1 -1
- data/lib/cortex_reaver/view/pages/form.rhtml +2 -1
- data/lib/cortex_reaver/view/pages/list.rhtml +2 -2
- data/lib/cortex_reaver/view/pages/show.rhtml +1 -1
- data/lib/cortex_reaver/view/photographs/form.rhtml +7 -3
- data/lib/cortex_reaver/view/photographs/list.rhtml +1 -1
- data/lib/cortex_reaver/view/photographs/show.rhtml +7 -7
- data/lib/cortex_reaver/view/projects/form.rhtml +1 -0
- data/lib/cortex_reaver/view/projects/list.rhtml +3 -3
- data/lib/cortex_reaver/view/projects/show.rhtml +5 -2
- data/lib/cortex_reaver/view/tags/list.rhtml +6 -2
- data/lib/cortex_reaver/view/tags/show.rhtml +10 -5
- data/lib/cortex_reaver/view/users/form.rhtml +1 -1
- data/lib/cortex_reaver/view/users/list.rhtml +5 -2
- data/lib/cortex_reaver/view/users/login.rhtml +1 -1
- data/lib/cortex_reaver/view/users/show.rhtml +5 -1
- metadata +159 -149
- data/lib/cortex_reaver/public/dispatch.fcgi +0 -11
- data/lib/cortex_reaver/snippets/ramaze/dispatcher/file.rb +0 -37
- data/lib/cortex_reaver/support/pagination.rb +0 -38
- data/lib/cortex_reaver/view/error.rhtml +0 -72
- data/lib/cortex_reaver/view/photographs/short.rhtml +0 -3
@@ -1,78 +1,58 @@
|
|
1
1
|
module CortexReaver
|
2
2
|
class Comment < Sequel::Model(:comments)
|
3
|
-
|
4
|
-
|
3
|
+
plugin :timestamps
|
4
|
+
plugin :cached_rendering
|
5
|
+
plugin :comments
|
6
|
+
plugin :sequenceable
|
7
|
+
|
5
8
|
include CortexReaver::Model::Renderer
|
6
|
-
include CortexReaver::Model::Comments
|
7
|
-
include CortexReaver::Model::Sequenceable
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
validates do
|
19
|
-
presence_of :body
|
20
|
-
length_of :title, :maximum => 255, :allow_nil => true
|
21
|
-
length_of :name, :maximum => 255, :allow_nil => true
|
22
|
-
length_of :http, :maximum => 255, :allow_nil => true
|
23
|
-
length_of :email, :maximum => 255, :allow_nil => true
|
24
|
-
format_of :email,
|
25
|
-
:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/, :allow_nil => true
|
26
|
-
end
|
27
|
-
|
28
|
-
# Ensure comments with an email specified do *not* conflict with another user.
|
29
|
-
validates_each :email do |object, attribute, value|
|
30
|
-
if (not value.blank?) and User.filter(:email => value).count > 0
|
31
|
-
object.errors[attribute] << 'conflicts with a registered user'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Ensures comments belong to exactly one parent.
|
36
|
-
validates_each :page_id do |object, attribute, value|
|
37
|
-
count = 0
|
38
|
-
[:page_id, :project_id, :journal_id, :comment_id, :photograph_id].each do |field|
|
39
|
-
unless object[field].blank?
|
40
|
-
count += 1
|
41
|
-
if count > 1
|
42
|
-
object.errors[attribute] << 'has too many kinds of parents'
|
43
|
-
break
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
if count == 0
|
49
|
-
object.errors[attribute] << "doesn't have a parent"
|
50
|
-
end
|
51
|
-
end
|
10
|
+
many_to_one :creator, :class => 'CortexReaver::User', :key => 'created_by'
|
11
|
+
many_to_one :updater, :class => 'CortexReaver::User', :key => 'updated_by'
|
12
|
+
many_to_one :journal, :class => 'CortexReaver::Journal'
|
13
|
+
many_to_one :project, :class => 'CortexReaver::Project'
|
14
|
+
many_to_one :photograph, :class => 'CortexReaver::Photograph'
|
15
|
+
many_to_one :page, :class => 'CortexReaver::Page'
|
16
|
+
many_to_one :comment, :class => 'CortexReaver::Comment'
|
17
|
+
one_to_many :comments, :class => 'CortexReaver::Comment'
|
52
18
|
|
53
19
|
# Infer blank titles
|
54
|
-
before_save
|
20
|
+
def before_save
|
21
|
+
return false unless super
|
22
|
+
|
55
23
|
if title.blank?
|
56
24
|
title = 'Re: ' + parent.title.to_s
|
57
25
|
title.gsub!(/^(Re: )+/, 'Re: ')
|
58
26
|
self.title = title
|
59
27
|
end
|
28
|
+
|
29
|
+
true
|
60
30
|
end
|
61
31
|
|
62
32
|
# Update parent comment counts
|
63
|
-
before_destroy
|
33
|
+
def before_destroy
|
34
|
+
return false unless super
|
35
|
+
|
64
36
|
parent = self.parent
|
65
37
|
parent.comment_count -= 1
|
66
38
|
parent.skip_timestamp_update = true
|
67
39
|
parent.save
|
40
|
+
|
41
|
+
true
|
68
42
|
end
|
69
43
|
|
70
|
-
|
71
|
-
|
44
|
+
# Increment parent comment count
|
45
|
+
# WARNING: If we *reparent* comments as opposed to just posting, this will
|
46
|
+
# break.
|
47
|
+
def after_create
|
48
|
+
super
|
49
|
+
|
72
50
|
parent = self.parent
|
73
51
|
parent.comment_count += 1
|
74
52
|
parent.skip_timestamp_update = true
|
75
53
|
parent.save
|
54
|
+
|
55
|
+
true
|
76
56
|
end
|
77
57
|
|
78
58
|
render :body, :with => :render_comment
|
@@ -100,12 +80,43 @@ module CortexReaver
|
|
100
80
|
end
|
101
81
|
end
|
102
82
|
|
83
|
+
def to_s
|
84
|
+
title || 'comment ' + id.to_s
|
85
|
+
end
|
86
|
+
|
103
87
|
def url
|
104
88
|
root_parent.url + '#comment_' + id.to_s
|
105
89
|
end
|
106
90
|
|
107
|
-
def
|
108
|
-
|
91
|
+
def validate
|
92
|
+
validates_presence :body
|
93
|
+
validates_max_length 255, :title
|
94
|
+
validates_max_length 255, :name
|
95
|
+
validates_max_length 255, :http
|
96
|
+
validates_max_length 255, :email
|
97
|
+
validates_format(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/, :email)
|
98
|
+
|
99
|
+
# Ensure comments with an email specified do *not* conflict with another
|
100
|
+
# user.
|
101
|
+
if (not email.blank?) and User.filter(:email => value).count > 0
|
102
|
+
self.errors[:email] << 'conflicts with a registered user'
|
103
|
+
end
|
104
|
+
|
105
|
+
# Ensures comments belong to exactly one parent.
|
106
|
+
count = 0
|
107
|
+
[:page_id, :project_id, :journal_id, :comment_id, :photograph_id].each do |field|
|
108
|
+
unless self[field].blank?
|
109
|
+
count += 1
|
110
|
+
if count > 1
|
111
|
+
self.errors[attribute] << 'has too many kinds of parents'
|
112
|
+
break
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
if count == 0
|
118
|
+
self.errors[attribute] << "doesn't have a parent"
|
119
|
+
end
|
109
120
|
end
|
110
121
|
end
|
111
122
|
end
|
@@ -1,28 +1,26 @@
|
|
1
1
|
module CortexReaver
|
2
2
|
class Journal < Sequel::Model(:journals)
|
3
|
-
|
4
|
-
|
3
|
+
plugin :timestamps
|
4
|
+
plugin :cached_rendering
|
5
|
+
plugin :canonical
|
6
|
+
plugin :attachments
|
7
|
+
plugin :comments
|
8
|
+
plugin :tags
|
9
|
+
plugin :sequenceable
|
10
|
+
plugin :viewable
|
5
11
|
include CortexReaver::Model::Renderer
|
6
|
-
include CortexReaver::Model::Canonical
|
7
|
-
include CortexReaver::Model::Attachments
|
8
|
-
include CortexReaver::Model::Comments
|
9
|
-
include CortexReaver::Model::Tags
|
10
|
-
include CortexReaver::Model::Sequenceable
|
11
12
|
|
12
13
|
many_to_many :tags, :class => 'CortexReaver::Tag'
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
validates do
|
18
|
-
uniqueness_of :name
|
19
|
-
presence_of :name
|
20
|
-
length_of :name, :maximum => 255
|
21
|
-
presence_of :title
|
22
|
-
end
|
14
|
+
many_to_one :creator, :class => 'CortexReaver::User', :key => 'created_by'
|
15
|
+
many_to_one :updater, :class => 'CortexReaver::User', :key => 'updated_by'
|
16
|
+
one_to_many :comments, :class => 'CortexReaver::Comment'
|
23
17
|
|
24
18
|
render :body
|
25
19
|
|
20
|
+
def self.atom_url
|
21
|
+
'/journals/atom'
|
22
|
+
end
|
23
|
+
|
26
24
|
def self.get(id)
|
27
25
|
self[:name => id] || self[id]
|
28
26
|
end
|
@@ -35,10 +33,6 @@ module CortexReaver
|
|
35
33
|
'/journals'
|
36
34
|
end
|
37
35
|
|
38
|
-
def self.atom_url
|
39
|
-
'/journals/atom'
|
40
|
-
end
|
41
|
-
|
42
36
|
def atom_url
|
43
37
|
'/journals/atom/' + name
|
44
38
|
end
|
@@ -50,5 +44,13 @@ module CortexReaver
|
|
50
44
|
def to_s
|
51
45
|
title || name
|
52
46
|
end
|
47
|
+
|
48
|
+
def validate
|
49
|
+
validates_unique :name
|
50
|
+
validates_presence :name
|
51
|
+
validates_max_length 255, :name
|
52
|
+
validates_presence :title
|
53
|
+
end
|
54
|
+
|
53
55
|
end
|
54
56
|
end
|
@@ -1,50 +1,25 @@
|
|
1
1
|
module CortexReaver
|
2
2
|
class Page < Sequel::Model(:pages)
|
3
|
-
|
4
|
-
|
3
|
+
plugin :timestamps
|
4
|
+
plugin :cached_rendering
|
5
|
+
plugin :canonical
|
6
|
+
plugin :attachments
|
7
|
+
plugin :comments
|
8
|
+
plugin :tags
|
9
|
+
plugin :sequenceable
|
10
|
+
plugin :viewable
|
5
11
|
include CortexReaver::Model::Renderer
|
6
|
-
include CortexReaver::Model::Canonical
|
7
|
-
include CortexReaver::Model::Attachments
|
8
|
-
include CortexReaver::Model::Comments
|
9
|
-
include CortexReaver::Model::Tags
|
10
|
-
include CortexReaver::Model::Sequenceable
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
many_to_one :page, :class => 'CortexReaver::Page'
|
14
|
+
one_to_many :pages, :class => 'CortexReaver::Page'
|
15
|
+
many_to_one :creator, :class => 'CortexReaver::User', :key => 'created_by'
|
16
|
+
many_to_one :updater, :class => 'CortexReaver::User', :key => 'updated_by'
|
17
|
+
one_to_many :comments, :class => 'CortexReaver::Comment'
|
17
18
|
many_to_many :tags, :class => 'CortexReaver::Tag'
|
18
19
|
|
19
20
|
# Top-level pages.
|
20
21
|
subset :top, :page_id => nil
|
21
22
|
|
22
|
-
validates do
|
23
|
-
uniqueness_of :name
|
24
|
-
presence_of :name
|
25
|
-
length_of :name, :maximum => 255
|
26
|
-
presence_of :title
|
27
|
-
length_of :title, :maximum => 255
|
28
|
-
|
29
|
-
each(:name, :tag => :url_conflict) do |object, attributes, value|
|
30
|
-
if controller = Ramaze::Controller.at(object.url)
|
31
|
-
object.errors['name'] << "conflicts with the #{controller}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Reserve names of controllers so we don't conflict.
|
37
|
-
Ramaze::Global.mapping.keys.each do |path|
|
38
|
-
path =~ /\/(.+)(\/|$)/
|
39
|
-
self.reserved_canonical_names << $1 if $1
|
40
|
-
end
|
41
|
-
|
42
|
-
# Also reserve everything in the public directory, as a courtesy.
|
43
|
-
#
|
44
|
-
# I can't stop you from shooting yourself in the foot, but this will help
|
45
|
-
# you aim higher. :)
|
46
|
-
self.reserved_canonical_names += Dir.entries(CortexReaver.config[:public_root]) - ['..', '.']
|
47
|
-
|
48
23
|
# Use standard cached renderer
|
49
24
|
render :body
|
50
25
|
|
@@ -88,7 +63,6 @@ module CortexReaver
|
|
88
63
|
|
89
64
|
# Look up ids by nested names.
|
90
65
|
ids.inject(nil) do |page, name|
|
91
|
-
puts "Searching for #{name} in #{page.inspect}"
|
92
66
|
parent_id = page ? page.id : nil
|
93
67
|
self[:page_id => parent_id, :name => name]
|
94
68
|
end
|
@@ -106,6 +80,10 @@ module CortexReaver
|
|
106
80
|
'/pages/atom/' + id.to_s
|
107
81
|
end
|
108
82
|
|
83
|
+
def to_s
|
84
|
+
title || name
|
85
|
+
end
|
86
|
+
|
109
87
|
def url
|
110
88
|
if page
|
111
89
|
page.url + '/' + name
|
@@ -114,8 +92,12 @@ module CortexReaver
|
|
114
92
|
end
|
115
93
|
end
|
116
94
|
|
117
|
-
def
|
118
|
-
|
95
|
+
def validate
|
96
|
+
validates_unique :name
|
97
|
+
validates_presence :name
|
98
|
+
validates_max_length 255, :name
|
99
|
+
validates_presence :title
|
100
|
+
validates_max_length 255, :title
|
119
101
|
end
|
120
102
|
|
121
103
|
# Returns true if this page is located underneath another page.
|
@@ -129,7 +111,7 @@ module CortexReaver
|
|
129
111
|
end
|
130
112
|
|
131
113
|
# Create a default page if none exists.
|
132
|
-
if table_exists? and Page.count == 0
|
114
|
+
if dataset.table_exists? and Page.count == 0
|
133
115
|
Page.new(
|
134
116
|
:name => 'about',
|
135
117
|
:title => 'About Cortex Reaver',
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module CortexReaver
|
2
2
|
class Photograph < Sequel::Model(:photographs)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
plugin :timestamps
|
4
|
+
plugin :canonical
|
5
|
+
plugin :attachments
|
6
|
+
plugin :comments
|
7
|
+
plugin :tags
|
8
|
+
plugin :sequenceable
|
9
|
+
plugin :viewable
|
10
10
|
|
11
11
|
# Target image sizes
|
12
12
|
SIZES = {
|
@@ -18,16 +18,9 @@ module CortexReaver
|
|
18
18
|
}
|
19
19
|
|
20
20
|
many_to_many :tags, :class => 'CortexReaver::Tag'
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
validates do
|
26
|
-
uniqueness_of :name
|
27
|
-
presence_of :name
|
28
|
-
length_of :name, :maximum => 255
|
29
|
-
presence_of :title
|
30
|
-
end
|
21
|
+
many_to_one :creator, :class => 'CortexReaver::User', :key => 'created_by'
|
22
|
+
many_to_one :updater, :class => 'CortexReaver::User', :key => 'updated_by'
|
23
|
+
one_to_many :comments, :class => 'CortexReaver::Comment'
|
31
24
|
|
32
25
|
def self.atom_url
|
33
26
|
'/photographs/atom'
|
@@ -135,5 +128,12 @@ module CortexReaver
|
|
135
128
|
def url
|
136
129
|
'/photographs/show/' + name
|
137
130
|
end
|
131
|
+
|
132
|
+
def validate
|
133
|
+
validates_unique :name
|
134
|
+
validates_presence :name
|
135
|
+
validates_max_length 255, :name
|
136
|
+
validates_presence :title
|
137
|
+
end
|
138
138
|
end
|
139
139
|
end
|
@@ -1,25 +1,20 @@
|
|
1
1
|
module CortexReaver
|
2
2
|
class Project < Sequel::Model(:projects)
|
3
|
-
|
4
|
-
|
3
|
+
plugin :timestamps
|
4
|
+
plugin :cached_rendering
|
5
|
+
plugin :canonical
|
6
|
+
plugin :attachments
|
7
|
+
plugin :comments
|
8
|
+
plugin :tags
|
9
|
+
plugin :sequenceable
|
10
|
+
plugin :viewable
|
5
11
|
include CortexReaver::Model::Renderer
|
6
|
-
include CortexReaver::Model::Canonical
|
7
|
-
include CortexReaver::Model::Attachments
|
8
|
-
include CortexReaver::Model::Comments
|
9
|
-
include CortexReaver::Model::Tags
|
10
|
-
include CortexReaver::Model::Sequenceable
|
11
12
|
|
12
13
|
many_to_many :tags, :class => 'CortexReaver::Tag'
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
many_to_one :creator, :class => 'CortexReaver::User', :key => 'created_by'
|
15
|
+
many_to_one :updater, :class => 'CortexReaver::User', :key => 'updated_by'
|
16
|
+
one_to_many :comments, :class => 'CortexReaver::Comment'
|
16
17
|
|
17
|
-
validates do
|
18
|
-
uniqueness_of :name
|
19
|
-
presence_of :name
|
20
|
-
length_of :name, :maximum => 255
|
21
|
-
presence_of :title
|
22
|
-
end
|
23
18
|
|
24
19
|
render :body
|
25
20
|
|
@@ -43,12 +38,20 @@ module CortexReaver
|
|
43
38
|
'/projects/atom/' + name
|
44
39
|
end
|
45
40
|
|
41
|
+
def to_s
|
42
|
+
title || name
|
43
|
+
end
|
44
|
+
|
46
45
|
def url
|
47
46
|
'/projects/show/' + name
|
48
47
|
end
|
49
48
|
|
50
|
-
def
|
51
|
-
|
49
|
+
def validate
|
50
|
+
validates_unique :name
|
51
|
+
validates_presence :name
|
52
|
+
validates_max_length 255, :name
|
53
|
+
validates_presence :title
|
52
54
|
end
|
55
|
+
|
53
56
|
end
|
54
57
|
end
|