cortex-reaver 0.0.9 → 0.1.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/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
@@ -0,0 +1,13 @@
|
|
1
|
+
module Sequel
|
2
|
+
module Plugins
|
3
|
+
# Extra validation helpers!
|
4
|
+
module CortexReaverValidationHelpers
|
5
|
+
module InstanceMethods
|
6
|
+
# Checks to ensure att and att_confirmation are the same.
|
7
|
+
def validates_confirmation(atts, opts={})
|
8
|
+
validatable_attributes(atts, opts) { |a,v,m| (m || "does not match confirmation") unless v == self.send(a.to_s + '_confirmation') }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,247 +1,246 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
# Sequences are models that have order. This module provides class
|
4
|
-
#
|
5
|
-
# the next or previoud record, and finding a "window" of results
|
6
|
-
# specific record.
|
7
|
-
|
1
|
+
module Sequel
|
2
|
+
module Plugins
|
3
|
+
# Sequences are models that have order. This module provides class and
|
4
|
+
# instance methods that support sequential behavior like pagination,
|
5
|
+
# finding the next or previoud record, and finding a "window" of results
|
6
|
+
# around a specific record.
|
8
7
|
module Sequenceable
|
9
8
|
|
10
|
-
# Which column table to order this sequence by
|
11
|
-
DEFAULT_SEQUENCE_ORDER = :created_on
|
12
|
-
DEFAULT_SEQUENCE_REVERSE = false
|
13
|
-
DEFAULT_WINDOW_SIZE = 16
|
14
|
-
|
15
9
|
# Class methods
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
10
|
+
module ClassMethods
|
11
|
+
# Which column table to order this sequence by
|
12
|
+
DEFAULT_SEQUENCE_ORDER = :created_on
|
13
|
+
DEFAULT_SEQUENCE_REVERSE = false
|
14
|
+
DEFAULT_WINDOW_SIZE = 16
|
15
|
+
|
16
|
+
# Returns the sequence dataset (optionally, restricted to dataset)
|
17
|
+
def sequence(dataset = self.dataset)
|
18
|
+
if sequence_reverse
|
19
|
+
dataset.reverse_order(sequence_order)
|
20
|
+
else
|
21
|
+
dataset.order(sequence_order)
|
27
22
|
end
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
# Returns the first record in the sequence
|
26
|
+
def first
|
27
|
+
sequence.first
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
# Returns the last record in the sequence
|
31
|
+
def last
|
32
|
+
sequence.last
|
33
|
+
end
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
# Returns the table column to order by
|
36
|
+
def sequence_order
|
37
|
+
@sequence_order || DEFAULT_SEQUENCE_ORDER
|
38
|
+
end
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
# Sets the table column to order by
|
41
|
+
def sequence_order=(order)
|
42
|
+
@sequence_order = order
|
43
|
+
end
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
# Returns whether or not to reverse the order
|
46
|
+
def sequence_reverse
|
47
|
+
@sequence_reverse || DEFAULT_SEQUENCE_REVERSE
|
48
|
+
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
# Sets whether to reverse the sequence
|
51
|
+
def sequence_reverse=(reverse)
|
52
|
+
@sequence_reverse = reverse
|
53
|
+
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
55
|
+
# Returns an absolute window into this sequence, specified as an
|
56
|
+
# offset in window-sized increments from the beginning of the
|
57
|
+
# sequence. Hence window(0, 10) returns the first ten records in the
|
58
|
+
# sequence, window(1, 10) the next ten, and so on.
|
59
|
+
#
|
60
|
+
# One can also specify the special page_offsets :first or :last,
|
61
|
+
# which return the first and last available windows.
|
62
|
+
def window(page_offset, size = self.window_size)
|
63
|
+
case page_offset
|
64
|
+
when :first
|
65
|
+
page_offset = 0
|
66
|
+
when :last
|
67
|
+
page_offset = window_count(size) - 1
|
68
|
+
else
|
69
|
+
page_offset = page_offset.to_i
|
70
|
+
end
|
75
71
|
|
76
|
-
|
77
|
-
|
72
|
+
# Don't ask for negative pages!
|
73
|
+
page_offset = 0 if page_offset < 0
|
78
74
|
|
79
|
-
|
80
|
-
|
75
|
+
# Calculate offset
|
76
|
+
offset = page_offset * size
|
81
77
|
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
# Limit dataset
|
79
|
+
sequence.limit size, offset
|
80
|
+
end
|
85
81
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
# Returns the number of windows required to span this sequence
|
83
|
+
def window_count(size = self.window_size)
|
84
|
+
(Float(sequence.count) / size).ceil
|
85
|
+
end
|
90
86
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
87
|
+
# Returns the size of a window into this sequence
|
88
|
+
def window_size
|
89
|
+
@window_size || DEFAULT_WINDOW_SIZE
|
90
|
+
end
|
95
91
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
92
|
+
# Sets the size of a window into this sequence
|
93
|
+
def window_size=(size)
|
94
|
+
@window_size = size
|
100
95
|
end
|
101
96
|
end
|
102
97
|
|
103
|
-
|
98
|
+
module InstanceMethods
|
104
99
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
100
|
+
# Convenience references to class methods
|
101
|
+
def sequence
|
102
|
+
self.class.sequence
|
103
|
+
end
|
109
104
|
|
110
|
-
|
111
|
-
|
112
|
-
|
105
|
+
def sequence_order
|
106
|
+
self.class.sequence_order
|
107
|
+
end
|
113
108
|
|
114
|
-
|
115
|
-
|
116
|
-
|
109
|
+
def sequence_reverse
|
110
|
+
self.class.sequence_reverse
|
111
|
+
end
|
117
112
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
113
|
+
# Returns the next record in the sequence. Caches--use next(true) to
|
114
|
+
# refresh.
|
115
|
+
def next(refresh_cache = false)
|
116
|
+
if refresh_cache
|
117
|
+
@next = sequence.filter(sequence_order > send(sequence_order)).limit(1).first
|
118
|
+
else
|
119
|
+
@next ||= sequence.filter(sequence_order > send(sequence_order)).limit(1).first
|
120
|
+
end
|
124
121
|
end
|
125
|
-
end
|
126
122
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
123
|
+
# Returns true if a next record exists. Caches--use next(true) to
|
124
|
+
# refresh.
|
125
|
+
def next?(refresh_cache = false)
|
126
|
+
if refresh_cache
|
127
|
+
@next_exists ||= self.next_count > 0 ? true : false
|
128
|
+
else
|
129
|
+
@next_exists = self.next_count > 0 ? true : false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns the number of succeeding records
|
134
|
+
def next_count
|
135
|
+
sequence.filter(sequence_order > send(sequence_order)).count
|
133
136
|
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# Returns the number of succeeding records
|
137
|
-
def next_count
|
138
|
-
sequence.filter(sequence_order > send(sequence_order)).count
|
139
|
-
end
|
140
137
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
138
|
+
# Returns the previous record in the sequence. Caches--use
|
139
|
+
# previous(true) to refresh.
|
140
|
+
def previous(refresh_cache = false)
|
141
|
+
if refresh_cache
|
142
|
+
@previous = sequence.filter(sequence_order < send(sequence_order)).reverse.limit(1).first
|
143
|
+
else
|
144
|
+
@previous ||= sequence.filter(sequence_order < send(sequence_order)).reverse.limit(1).first
|
145
|
+
end
|
146
|
+
end
|
150
147
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
148
|
+
# Returns true if a previous record exists. Caches--use previous?(true)
|
149
|
+
# to refresh.
|
150
|
+
def previous?(refresh_cache = false)
|
151
|
+
if refresh_cache
|
152
|
+
@previous_exists = self.previous_count > 0 ? true : false
|
153
|
+
else
|
154
|
+
@previous_exists ||= self.previous_count > 0 ? true : false
|
155
|
+
end
|
158
156
|
end
|
159
|
-
end
|
160
157
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
158
|
+
# Returns the number of preceding records
|
159
|
+
def previous_count
|
160
|
+
sequence.filter(sequence_order < send(sequence_order)).count
|
161
|
+
end
|
165
162
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
# Find records
|
188
|
-
sequence.limit(size, offset)
|
189
|
-
when :float
|
190
|
-
count = sequence.count # Total records
|
191
|
-
if size >= count
|
192
|
-
# Window includes all records in the sequence
|
193
|
-
return self.class.find(:all)
|
194
|
-
else
|
195
|
-
# Window is smaller than the sequence
|
196
|
-
position = self.position # This record's position
|
197
|
-
previous_size = (Float(size - 1) / 2).floor # How many records before
|
198
|
-
next_size = (Float(size - 1) / 2).ceil # How many records after
|
163
|
+
alias :position :previous_count
|
164
|
+
|
165
|
+
# Returns a collection of records around this record.
|
166
|
+
# Mode is one of:
|
167
|
+
# 1. :absolute Returns a window containing this record in even multiples from
|
168
|
+
# the first record, like a page of a book.
|
169
|
+
# 2. :float Returns a centered window of the provided size. If the edge of
|
170
|
+
# the sequence is reached, the window shifts to include more
|
171
|
+
# elements of the sequence. If no more elements are available
|
172
|
+
# (the window is larger than the size of the sequence), the
|
173
|
+
# entire sequence is returned. If the size is even, one more
|
174
|
+
# record is returned suceeding this record than preceding this
|
175
|
+
# record, if possible.
|
176
|
+
# 3. :clip Returns a centered window of or smaller than the given size. If
|
177
|
+
# the edge of the sequence is reached, the window is clipped.
|
178
|
+
def window(mode = :absolute, size = self.class.window_size)
|
179
|
+
case mode
|
180
|
+
when :absolute
|
181
|
+
# Calculate page offset
|
182
|
+
offset = (Float(position) / size).floor * size
|
199
183
|
|
200
|
-
#
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
#
|
206
|
-
|
184
|
+
# Find records
|
185
|
+
sequence.limit(size, offset)
|
186
|
+
when :float
|
187
|
+
count = sequence.count # Total records
|
188
|
+
if size >= count
|
189
|
+
# Window includes all records in the sequence
|
190
|
+
return self.class.find(:all)
|
191
|
+
else
|
192
|
+
# Window is smaller than the sequence
|
193
|
+
position = self.position # This record's position
|
194
|
+
previous_size = (Float(size - 1) / 2).floor # How many records before
|
195
|
+
next_size = (Float(size - 1) / 2).ceil # How many records after
|
196
|
+
|
197
|
+
# Shift window if necessary
|
198
|
+
if (displacement = previous_size - position) > 0
|
199
|
+
# The window extends before the start of the sequence
|
200
|
+
previous_size -= displacement
|
201
|
+
elsif (displacement = next_size - self.next_count) > 0
|
202
|
+
# The window extends beyond the end of the sequence
|
203
|
+
previous_size += displacement
|
204
|
+
end
|
205
|
+
|
206
|
+
# Calculate window offset
|
207
|
+
offset = position - previous_size
|
208
|
+
|
209
|
+
# Find records
|
210
|
+
sequence.limit(size, offset)
|
207
211
|
end
|
212
|
+
when :clip
|
213
|
+
position = self.position # Our position in sequence
|
214
|
+
previous_size = (Float(size - 1) / 2).floor # How many records before
|
208
215
|
|
209
|
-
|
210
|
-
|
216
|
+
if (displacement = previous_size - position) > 0
|
217
|
+
# The window extends before the beginning of the sequence
|
218
|
+
size -= displacement
|
219
|
+
offset = 0
|
220
|
+
else
|
221
|
+
# The window doesn't extend before the beginning of the sequence.
|
222
|
+
offset = position - previous_size
|
223
|
+
end
|
211
224
|
|
212
|
-
# Find records
|
225
|
+
# Find records.
|
213
226
|
sequence.limit(size, offset)
|
214
|
-
end
|
215
|
-
when :clip
|
216
|
-
position = self.position # Our position in sequence
|
217
|
-
previous_size = (Float(size - 1) / 2).floor # How many records before
|
218
|
-
|
219
|
-
if (displacement = previous_size - position) > 0
|
220
|
-
# The window extends before the beginning of the sequence
|
221
|
-
size -= displacement
|
222
|
-
offset = 0
|
223
227
|
else
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
# Find records.
|
229
|
-
sequence.limit(size, offset)
|
230
|
-
else
|
231
|
-
raise ArgumentError.new('first argument must be one of :absolute, :float, :clip')
|
228
|
+
raise ArgumentError.new('first argument must be one of :absolute, :float, :clip')
|
229
|
+
end
|
232
230
|
end
|
233
|
-
end
|
234
231
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
'
|
240
|
-
|
232
|
+
# Returns a url for this record, viewed in an absolute window. TODO:
|
233
|
+
# handle non-default window sizes.
|
234
|
+
def absolute_window_url(size = self.class.window_size)
|
235
|
+
page = (Float(position) / size).floor
|
236
|
+
self.class.url + '/page/' + page.to_s + '#' + self.class.to_s.demodulize.underscore +
|
237
|
+
'_' + send(self.class.canonical_name_attr)
|
238
|
+
end
|
241
239
|
|
242
|
-
|
243
|
-
|
244
|
-
|
240
|
+
# Returns the absolute window index that this record appears in
|
241
|
+
def absolute_window_index(size = self.class.window_size)
|
242
|
+
(Float(self.position) / size).floor
|
243
|
+
end
|
245
244
|
end
|
246
245
|
end
|
247
246
|
end
|