raw 0.49.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/CONTRIBUTORS +106 -0
- data/doc/LICENSE +32 -0
- data/doc/coding_conventions.txt +11 -0
- data/lib/raw.rb +42 -0
- data/lib/raw/adapter.rb +113 -0
- data/lib/raw/adapter/cgi.rb +41 -0
- data/lib/raw/adapter/fastcgi.rb +48 -0
- data/lib/raw/adapter/mongrel.rb +146 -0
- data/lib/raw/adapter/script.rb +94 -0
- data/lib/raw/adapter/webrick.rb +144 -0
- data/lib/raw/adapter/webrick/vcr.rb +91 -0
- data/lib/raw/cgi.rb +323 -0
- data/lib/raw/cgi/cookie.rb +47 -0
- data/lib/raw/cgi/http.rb +62 -0
- data/lib/raw/compiler.rb +138 -0
- data/lib/raw/compiler/filter/cleanup.rb +21 -0
- data/lib/raw/compiler/filter/elements.rb +166 -0
- data/lib/raw/compiler/filter/elements/element.rb +210 -0
- data/lib/raw/compiler/filter/localization.rb +23 -0
- data/lib/raw/compiler/filter/markup.rb +32 -0
- data/lib/raw/compiler/filter/morph.rb +123 -0
- data/lib/raw/compiler/filter/morph/each.rb +34 -0
- data/lib/raw/compiler/filter/morph/for.rb +11 -0
- data/lib/raw/compiler/filter/morph/if.rb +26 -0
- data/lib/raw/compiler/filter/morph/selected_if.rb +43 -0
- data/lib/raw/compiler/filter/morph/standard.rb +55 -0
- data/lib/raw/compiler/filter/morph/times.rb +27 -0
- data/lib/raw/compiler/filter/script.rb +116 -0
- data/lib/raw/compiler/filter/squeeze.rb +16 -0
- data/lib/raw/compiler/filter/static_include.rb +74 -0
- data/lib/raw/compiler/filter/template.rb +121 -0
- data/lib/raw/compiler/reloader.rb +96 -0
- data/lib/raw/context.rb +154 -0
- data/lib/raw/context/flash.rb +157 -0
- data/lib/raw/context/global.rb +88 -0
- data/lib/raw/context/request.rb +338 -0
- data/lib/raw/context/response.rb +57 -0
- data/lib/raw/context/session.rb +198 -0
- data/lib/raw/context/session/drb.rb +11 -0
- data/lib/raw/context/session/file.rb +15 -0
- data/lib/raw/context/session/memcached.rb +13 -0
- data/lib/raw/context/session/memory.rb +12 -0
- data/lib/raw/context/session/og.rb +15 -0
- data/lib/raw/context/session/pstore.rb +13 -0
- data/lib/raw/control.rb +18 -0
- data/lib/raw/control/attribute.rb +91 -0
- data/lib/raw/control/attribute/checkbox.rb +25 -0
- data/lib/raw/control/attribute/datetime.rb +21 -0
- data/lib/raw/control/attribute/file.rb +20 -0
- data/lib/raw/control/attribute/fixnum.rb +26 -0
- data/lib/raw/control/attribute/float.rb +26 -0
- data/lib/raw/control/attribute/options.rb +38 -0
- data/lib/raw/control/attribute/password.rb +16 -0
- data/lib/raw/control/attribute/text.rb +16 -0
- data/lib/raw/control/attribute/textarea.rb +16 -0
- data/lib/raw/control/none.rb +16 -0
- data/lib/raw/control/relation.rb +59 -0
- data/lib/raw/control/relation/belongs_to.rb +0 -0
- data/lib/raw/control/relation/has_many.rb +97 -0
- data/lib/raw/control/relation/joins_many.rb +0 -0
- data/lib/raw/control/relation/many_to_many.rb +0 -0
- data/lib/raw/control/relation/refers_to.rb +29 -0
- data/lib/raw/controller.rb +37 -0
- data/lib/raw/controller/publishable.rb +160 -0
- data/lib/raw/dispatcher.rb +209 -0
- data/lib/raw/dispatcher/format.rb +108 -0
- data/lib/raw/dispatcher/format/atom.rb +31 -0
- data/lib/raw/dispatcher/format/css.rb +0 -0
- data/lib/raw/dispatcher/format/html.rb +42 -0
- data/lib/raw/dispatcher/format/json.rb +31 -0
- data/lib/raw/dispatcher/format/rss.rb +33 -0
- data/lib/raw/dispatcher/format/xoxo.rb +31 -0
- data/lib/raw/dispatcher/mounter.rb +60 -0
- data/lib/raw/dispatcher/router.rb +111 -0
- data/lib/raw/errors.rb +19 -0
- data/lib/raw/helper.rb +86 -0
- data/lib/raw/helper/benchmark.rb +23 -0
- data/lib/raw/helper/buffer.rb +60 -0
- data/lib/raw/helper/cookie.rb +32 -0
- data/lib/raw/helper/debug.rb +28 -0
- data/lib/raw/helper/default.rb +16 -0
- data/lib/raw/helper/feed.rb +451 -0
- data/lib/raw/helper/form.rb +284 -0
- data/lib/raw/helper/javascript.rb +59 -0
- data/lib/raw/helper/layout.rb +40 -0
- data/lib/raw/helper/navigation.rb +87 -0
- data/lib/raw/helper/pager.rb +305 -0
- data/lib/raw/helper/table.rb +247 -0
- data/lib/raw/helper/xhtml.rb +218 -0
- data/lib/raw/helper/xml.rb +125 -0
- data/lib/raw/mixin/magick.rb +35 -0
- data/lib/raw/mixin/sweeper.rb +71 -0
- data/lib/raw/mixin/thumbnails.rb +1 -0
- data/lib/raw/mixin/webfile.rb +165 -0
- data/lib/raw/render.rb +271 -0
- data/lib/raw/render/builder.rb +26 -0
- data/lib/raw/render/caching.rb +81 -0
- data/lib/raw/render/call.rb +43 -0
- data/lib/raw/render/send_file.rb +46 -0
- data/lib/raw/render/stream.rb +39 -0
- data/lib/raw/scaffold.rb +13 -0
- data/lib/raw/scaffold/controller.rb +25 -0
- data/lib/raw/scaffold/model.rb +157 -0
- data/lib/raw/test.rb +5 -0
- data/lib/raw/test/assertions.rb +169 -0
- data/lib/raw/test/context.rb +55 -0
- data/lib/raw/test/testcase.rb +79 -0
- data/lib/raw/util/attr.rb +128 -0
- data/lib/raw/util/encode_uri.rb +149 -0
- data/lib/raw/util/html_filter.rb +538 -0
- data/lib/raw/util/markup.rb +130 -0
- data/test/glue/tc_webfile.rb +1 -0
- data/test/nitro/CONFIG.rb +3 -0
- data/test/nitro/adapter/raw_post1.bin +9 -0
- data/test/nitro/adapter/tc_webrick.rb +16 -0
- data/test/nitro/cgi/tc_cookie.rb +14 -0
- data/test/nitro/cgi/tc_request.rb +61 -0
- data/test/nitro/compiler/tc_client_morpher.rb +47 -0
- data/test/nitro/compiler/tc_compiler.rb +25 -0
- data/test/nitro/dispatcher/tc_mounter.rb +47 -0
- data/test/nitro/helper/tc_feed.rb +135 -0
- data/test/nitro/helper/tc_navbar.rb +74 -0
- data/test/nitro/helper/tc_pager.rb +35 -0
- data/test/nitro/helper/tc_table.rb +68 -0
- data/test/nitro/helper/tc_xhtml.rb +19 -0
- data/test/nitro/tc_caching.rb +19 -0
- data/test/nitro/tc_cgi.rb +222 -0
- data/test/nitro/tc_context.rb +17 -0
- data/test/nitro/tc_controller.rb +103 -0
- data/test/nitro/tc_controller_aspect.rb +32 -0
- data/test/nitro/tc_controller_params.rb +885 -0
- data/test/nitro/tc_dispatcher.rb +109 -0
- data/test/nitro/tc_element.rb +85 -0
- data/test/nitro/tc_flash.rb +59 -0
- data/test/nitro/tc_helper.rb +47 -0
- data/test/nitro/tc_render.rb +119 -0
- data/test/nitro/tc_router.rb +61 -0
- data/test/nitro/tc_server.rb +35 -0
- data/test/nitro/tc_session.rb +66 -0
- data/test/nitro/tc_template.rb +71 -0
- data/test/nitro/util/tc_encode_url.rb +87 -0
- data/test/nitro/util/tc_markup.rb +31 -0
- data/test/public/blog/another/very_litle/index.xhtml +1 -0
- data/test/public/blog/inc1.xhtml +2 -0
- data/test/public/blog/inc2.xhtml +1 -0
- data/test/public/blog/list.xhtml +9 -0
- data/test/public/dummy_mailer/registration.xhtml +5 -0
- metadata +244 -0
@@ -0,0 +1,218 @@
|
|
1
|
+
module Raw
|
2
|
+
|
3
|
+
# A helper mixin for programmatically building XHTML
|
4
|
+
# blocks.
|
5
|
+
|
6
|
+
module XhtmlHelper
|
7
|
+
|
8
|
+
# Creates the href of an Object.
|
9
|
+
#--
|
10
|
+
# gmosx: this duplicates R functionality, merge!
|
11
|
+
#++
|
12
|
+
|
13
|
+
def href_of(obj, base = nil)
|
14
|
+
if obj.is_a?(Symbol) or obj.is_a?(String)
|
15
|
+
href = obj.to_s
|
16
|
+
elsif obj.respond_to? :to_href
|
17
|
+
href = obj.to_href
|
18
|
+
else
|
19
|
+
href = "#{obj.class.name.pluralize.underscore}/#{obj.oid}"
|
20
|
+
end
|
21
|
+
|
22
|
+
if base
|
23
|
+
base += '/'
|
24
|
+
else
|
25
|
+
base = "#{self.class.mount_path}/".squeeze
|
26
|
+
end
|
27
|
+
|
28
|
+
return "#{base}#{href}"
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creates a link to an Object.
|
32
|
+
|
33
|
+
def link_to(obj, base = nil)
|
34
|
+
%|<a href="#{href_of(obj, base)}">#{obj}</a>|
|
35
|
+
end
|
36
|
+
|
37
|
+
# Render select options. The parameter is a hash of options.
|
38
|
+
#
|
39
|
+
# [+labels+]
|
40
|
+
# The option labels.
|
41
|
+
#
|
42
|
+
# [+values+]
|
43
|
+
# The corresponding values.
|
44
|
+
#
|
45
|
+
# [+labels_values+]
|
46
|
+
# Use when labels == values.
|
47
|
+
#
|
48
|
+
# [+selected+]
|
49
|
+
# The value of the selected option.
|
50
|
+
#
|
51
|
+
# === Examples
|
52
|
+
#
|
53
|
+
# labels = ['Male', 'Female']
|
54
|
+
# o.select(:name => 'sex') {
|
55
|
+
# o.options(:labels => labels, :selected => 1)
|
56
|
+
# }
|
57
|
+
#
|
58
|
+
# or
|
59
|
+
#
|
60
|
+
# #{options :labels => labels, :values => [..], :selected => 1}
|
61
|
+
# #{build :options, :labels => labels, :values => [..], :selected => 1}
|
62
|
+
|
63
|
+
def options(options = {})
|
64
|
+
if labels = options[:labels] || options[:labels_values]
|
65
|
+
str = ''
|
66
|
+
|
67
|
+
values = options[:values] || options[:labels_values] || (0...labels.size).to_a
|
68
|
+
|
69
|
+
selected = options[:selected]
|
70
|
+
selected = selected.to_s if selected
|
71
|
+
|
72
|
+
labels.each_with_index do |label, idx|
|
73
|
+
value = values[idx]
|
74
|
+
if options[:style]
|
75
|
+
style = if options[:style].is_a?(Array)
|
76
|
+
options[:style][idx]
|
77
|
+
else
|
78
|
+
options[:style]
|
79
|
+
end
|
80
|
+
style = %{ style="#{style}"}
|
81
|
+
end
|
82
|
+
if value.to_s == selected
|
83
|
+
str << %|<option value="#{value}" selected="selected"#{style}>#{label}</option>|
|
84
|
+
else
|
85
|
+
str << %|<option value="#{value}"#{style}>#{label}</option>|
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
return str
|
90
|
+
else
|
91
|
+
raise ArgumentError.new('No labels provided')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Convert a collection of objects to options.
|
96
|
+
|
97
|
+
def objects_to_options(objs, params = {})
|
98
|
+
labels = []
|
99
|
+
values = []
|
100
|
+
for obj in objs
|
101
|
+
labels << obj.to_s
|
102
|
+
values << obj.pk
|
103
|
+
end
|
104
|
+
params[:labels] = labels
|
105
|
+
params[:values] = values
|
106
|
+
options(params)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Render a hidden form input.
|
110
|
+
|
111
|
+
def hidden(name, value)
|
112
|
+
# opts = options.collect { |k, v| %[#{k}="#{v}"] }.join(' ')
|
113
|
+
%[<input type="hidden" name="#{name}" value="#{value}" />]
|
114
|
+
end
|
115
|
+
|
116
|
+
# Render a submit input.
|
117
|
+
|
118
|
+
def submit(label, options = nil)
|
119
|
+
str = ''
|
120
|
+
|
121
|
+
label = options.delete(:value) unless label
|
122
|
+
|
123
|
+
str << '<input type="submit"'
|
124
|
+
str << %[ value="#{label}"] if label
|
125
|
+
|
126
|
+
unless options.empty?
|
127
|
+
opts = options.collect { |k, v| %[#{k}="#{v}"] }.join(' ')
|
128
|
+
str << %[ #{opts} ]
|
129
|
+
end
|
130
|
+
|
131
|
+
str << ' />'
|
132
|
+
|
133
|
+
return str
|
134
|
+
end
|
135
|
+
|
136
|
+
# Render a date select. Override to customize this.
|
137
|
+
#
|
138
|
+
# === Example
|
139
|
+
#
|
140
|
+
# #{date_select date, :name => 'brithday'}
|
141
|
+
|
142
|
+
def date_select(date, options = {})
|
143
|
+
raise 'No name provided to date_select' unless name = options[:name]
|
144
|
+
date ||= Time.now
|
145
|
+
%{
|
146
|
+
<select id="#{name}.day" name="#{name}.day">
|
147
|
+
#{options(:labels_values => (1..31).to_a, :selected => date.day)}
|
148
|
+
</select>
|
149
|
+
<select id="#{name}.month" name="#{name}.month">
|
150
|
+
#{options(:labels => Date::MONTHNAMES[1..12], :values => (1..12).to_a, :selected => (date.month))}
|
151
|
+
</select>
|
152
|
+
<select id="#{name}.year" name="#{name}.year">
|
153
|
+
#{options(:labels_values => ((Time.now.year-10)..(Time.now.year+10)).to_a, :selected => date.year)}
|
154
|
+
</select>}
|
155
|
+
end
|
156
|
+
|
157
|
+
# Render a time select. Override to customize this.
|
158
|
+
|
159
|
+
def time_select(time, options = {})
|
160
|
+
raise 'No name provided to time_select' unless name = options[:name]
|
161
|
+
time ||= Time.now
|
162
|
+
%{
|
163
|
+
<select id="#{name}.hour" name="#{name}.hour">
|
164
|
+
#{options(:labels_values => (1..60).to_a, :selected => time.hour)}
|
165
|
+
</select>
|
166
|
+
<select id="#{name}.min" name="#{name}.min">
|
167
|
+
#{options(:labels_values => (1..60).to_a, :selected => time.min)}
|
168
|
+
</select>}
|
169
|
+
end
|
170
|
+
|
171
|
+
# Render a datetime select. Override to customize this.
|
172
|
+
|
173
|
+
def datetime_select(time, options)
|
174
|
+
date_select(time, options) + ' at ' + time_select(time, options)
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
# gmosx: keep the leading / to be IE friendly.
|
179
|
+
|
180
|
+
def js_popup(options = {})
|
181
|
+
o = {
|
182
|
+
:width => 320,
|
183
|
+
:height => 240,
|
184
|
+
:title => 'Popup',
|
185
|
+
:resizable => false,
|
186
|
+
:scrollbars => false,
|
187
|
+
}.merge(options)
|
188
|
+
|
189
|
+
poptions = (o[:resizable] ? 'resizable=yes,' : 'resizable=no,')
|
190
|
+
poptions << (o[:scrollbars] ? 'scrollbars=yes' : 'scrollbars=no')
|
191
|
+
|
192
|
+
uri = o[:url] || o[:uri]
|
193
|
+
|
194
|
+
%[javascript: var pwl = (screen.width - #{o[:width]}) / 2; var pwt = (screen.height - #{o[:height]}) / 2; window.open('#{uri}', '#{o[:title]}', 'width=#{o[:width]},height=#{o[:height]},top='+pwt+',left='+pwl+', #{poptions}'); return false;"]
|
195
|
+
end
|
196
|
+
|
197
|
+
# === Example
|
198
|
+
#
|
199
|
+
# <a href="#" #{onclick_popup 'add-comment', :scrollbars => true}>Hello</a>
|
200
|
+
|
201
|
+
def onclick_popup(options = {})
|
202
|
+
%|onclick="#{js_popup(options)}"|
|
203
|
+
end
|
204
|
+
|
205
|
+
# Emit a link that spawns a popup window.
|
206
|
+
#
|
207
|
+
# === Example
|
208
|
+
#
|
209
|
+
# <a href="#" #{onclick :text => 'Hello', :uri => 'add-comment', :scrollbars => true}>Hello</a>
|
210
|
+
|
211
|
+
def popup(options = {})
|
212
|
+
%|<a href="#" #{onclick_popup(options)}>#{options[:text] || 'Popup'}</a>|
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Raw
|
2
|
+
|
3
|
+
# A helper mixin for programmatically building XML
|
4
|
+
# blocks.
|
5
|
+
#--
|
6
|
+
# gmosx, INVESTIGATE: is this used or deprecated?
|
7
|
+
#++
|
8
|
+
|
9
|
+
module XmlHelper
|
10
|
+
|
11
|
+
def method_missing(tag, *args, &block)
|
12
|
+
self.class.module_eval <<-"end_eval", __FILE__, __LINE__
|
13
|
+
def #{tag}(*args)
|
14
|
+
attrs = args.last.is_a?(Hash) ? args.pop : nil
|
15
|
+
|
16
|
+
if block_given?
|
17
|
+
start_tag!('#{tag}', attrs)
|
18
|
+
yield
|
19
|
+
end_tag!('#{tag}')
|
20
|
+
elsif (!args.empty?)
|
21
|
+
start_tag!('#{tag}', attrs)
|
22
|
+
self << args.first
|
23
|
+
end_tag!('#{tag}')
|
24
|
+
else
|
25
|
+
start_tag!('#{tag}', attrs, false)
|
26
|
+
self << ' />'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end_eval
|
30
|
+
|
31
|
+
self.send(tag, *args, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Emit the start (opening) tag of an element.
|
35
|
+
|
36
|
+
def start_tag!(tag, attributes = nil, close = true)
|
37
|
+
unless attributes
|
38
|
+
if close
|
39
|
+
self << "<#{tag}>"
|
40
|
+
else
|
41
|
+
self << "<#{tag}"
|
42
|
+
end
|
43
|
+
else
|
44
|
+
self << "<#{tag}"
|
45
|
+
for name, value in attributes
|
46
|
+
if value
|
47
|
+
self << %| #{name}="#{value}"|
|
48
|
+
else
|
49
|
+
self << %| #{name}="1"|
|
50
|
+
end
|
51
|
+
end
|
52
|
+
self << ">" if close
|
53
|
+
end
|
54
|
+
|
55
|
+
return self
|
56
|
+
end
|
57
|
+
|
58
|
+
# Emit the end (closing) tag of an element.
|
59
|
+
|
60
|
+
def end_tag!(tag)
|
61
|
+
self << "</#{tag}>"
|
62
|
+
|
63
|
+
return self
|
64
|
+
end
|
65
|
+
|
66
|
+
# Emit a text string.
|
67
|
+
|
68
|
+
def text!(str)
|
69
|
+
self << str
|
70
|
+
|
71
|
+
return self
|
72
|
+
end
|
73
|
+
alias_method :print, :text!
|
74
|
+
|
75
|
+
# Emit a comment.
|
76
|
+
|
77
|
+
def comment!(str)
|
78
|
+
self << "<!-- #{str} -->"
|
79
|
+
|
80
|
+
return self
|
81
|
+
end
|
82
|
+
|
83
|
+
# Emit a processing instruction.
|
84
|
+
|
85
|
+
def processing_instruction!(name, attributes = nil)
|
86
|
+
unless attributes
|
87
|
+
self << "<?#{name} ?>"
|
88
|
+
else
|
89
|
+
self << "<?#{name} "
|
90
|
+
attributes.each do |a, v|
|
91
|
+
self << %[#{a}="#{v}" ]
|
92
|
+
end
|
93
|
+
self << "?>"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
alias_method :pi!, :processing_instruction!
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
# A class that encapsulats the XML generation
|
101
|
+
# functionality. Utilizes duck typing to redirect
|
102
|
+
# output to a target buffer.
|
103
|
+
|
104
|
+
class Glue::XmlBuilder
|
105
|
+
include XmlHelper
|
106
|
+
|
107
|
+
# The target receives the generated xml,
|
108
|
+
# should respond_to :<<
|
109
|
+
|
110
|
+
attr_accessor :target
|
111
|
+
|
112
|
+
def initialize(target = '')
|
113
|
+
@target = target
|
114
|
+
end
|
115
|
+
|
116
|
+
def << (str)
|
117
|
+
@target << str
|
118
|
+
end
|
119
|
+
|
120
|
+
def to_s
|
121
|
+
@target.to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "RMagick"
|
2
|
+
|
3
|
+
module Raw::Mixin
|
4
|
+
|
5
|
+
# Magick transformation.
|
6
|
+
#--
|
7
|
+
# TODO: pass generalized RMagick command.
|
8
|
+
#++
|
9
|
+
|
10
|
+
module Thumbnails
|
11
|
+
|
12
|
+
# Default thumbnail width.
|
13
|
+
|
14
|
+
setting :width, :default => 128, :doc => 'Default thumbnail width'
|
15
|
+
|
16
|
+
# Default thumbnail height.
|
17
|
+
|
18
|
+
setting :height, :default => 128, :doc => 'Default thumbnail height'
|
19
|
+
|
20
|
+
def self.generate_thumbnail(src, tname, geostring)
|
21
|
+
ext = File.extname(src)
|
22
|
+
dst = "#{File.join(File.dirname(src), File.basename(src, ext))}_#{tname}#{ext}"
|
23
|
+
|
24
|
+
thumb = Magick::Image.read(File.join(Nitro::Server.public_root, src)).first
|
25
|
+
thumb.change_geometry!(geostring) do |cols, rows, thumb|
|
26
|
+
thumb.resize!(cols, rows)
|
27
|
+
end
|
28
|
+
thumb.write(File.join(Nitro::Server.public_root, dst))
|
29
|
+
|
30
|
+
return dst
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "raw/render/caching"
|
2
|
+
require "raw/util/encode_uri"
|
3
|
+
|
4
|
+
module Raw::Mixin
|
5
|
+
|
6
|
+
# This module adds cleanup functionality to managed
|
7
|
+
# classes. Override and implement sweep_affected.
|
8
|
+
# Typically used to cleanup output caching files from
|
9
|
+
# the filesystem. But you can also use it to clean up
|
10
|
+
# temp objects in the database or other temp files.
|
11
|
+
#--
|
12
|
+
# FIXME: find a better name.
|
13
|
+
#++
|
14
|
+
|
15
|
+
module Sweeper
|
16
|
+
extend Raw::Caching
|
17
|
+
extend Raw::EncodeURI
|
18
|
+
|
19
|
+
#--
|
20
|
+
# Inject the sweepers *after* the event to have a valid
|
21
|
+
# oid.
|
22
|
+
#++
|
23
|
+
|
24
|
+
before :og_insert do
|
25
|
+
sweep_affected(:insert) unless $sweeper_dissabled
|
26
|
+
end
|
27
|
+
|
28
|
+
before :og_update do
|
29
|
+
sweep_affected(:update) unless $sweeper_dissabled
|
30
|
+
end
|
31
|
+
|
32
|
+
before :og_delete do
|
33
|
+
sweep_affected(:delete) unless $sweeper_dissabled
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# If needed pass the calling action symbol to allow
|
39
|
+
# for conditional expiration.
|
40
|
+
# Action takes values from { :insert, :delete, :update }
|
41
|
+
# or your own custom enumeration.
|
42
|
+
#
|
43
|
+
# Generally add lines like the following:
|
44
|
+
#
|
45
|
+
# expire_output("file_to_expire")
|
46
|
+
# expire_output(Controller, :action)
|
47
|
+
# expire_output(obj) # uses obj.to_href
|
48
|
+
|
49
|
+
def sweep_affected(action = :all)
|
50
|
+
end
|
51
|
+
alias_method :expire_affected, :sweep_affected
|
52
|
+
|
53
|
+
# Called from an action that modifies the model to expire
|
54
|
+
# affected (dependend) cached pages. Generally you don't
|
55
|
+
# override this method.
|
56
|
+
|
57
|
+
def expire_affected_output(*args)
|
58
|
+
Sweeper.send(:expire_output, *args)
|
59
|
+
end
|
60
|
+
alias_method :expire_output, :expire_affected_output
|
61
|
+
|
62
|
+
# Expire affected cached fragments.
|
63
|
+
|
64
|
+
def expire_affected_fragment(name, options = {})
|
65
|
+
# TODO
|
66
|
+
end
|
67
|
+
alias_method :expire_fragment, :expire_affected_fragment
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|