File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1
1
require_dependency "openid_login_system"
2
2
3
+ require 'lib/collection_types'
4
+
3
5
class NeedAuthSub < RuntimeError ; end
4
6
5
7
class RemoteFailure < RuntimeError
@@ -75,6 +77,7 @@ def n_url url
75
77
# links:
76
78
# rel
77
79
# href
80
+ # extra: name of a method to be called on EntryConstructor
78
81
def make_entry ( params )
79
82
unless params
80
83
return Atom ::Entry . new
@@ -137,6 +140,11 @@ def make_entry(params)
137
140
end
138
141
end
139
142
143
+ # extension mechanism
144
+ if EntryConstructor . singleton_methods . member? params [ 'extra' ]
145
+ EntryConstructor . send params [ 'extra' ] . to_sym , entry , params
146
+ end
147
+
140
148
entry
141
149
end
142
150
Original file line number Diff line number Diff line change
1
+ # this module contains methods for customizing an Atom::Entry for different
2
+ # types of collections based on form input parameters
3
+ module EntryConstructor
4
+ module_function
5
+
6
+ # a microformatted review of something
7
+ def hreview entry , params
8
+ review = <<END
9
+ <div class="hreview">
10
+ <div class="item">
11
+ END
12
+
13
+ review << if params [ 'item' ] [ 'url' ] . empty?
14
+ "<span class='fn'>" + CGI . escapeHTML ( params [ 'title' ] ) + "</span>"
15
+ else
16
+ "<a class='url fn' href='" +
17
+ CGI . escapeHTML ( params [ 'item' ] [ 'url' ] ) + "'>" +
18
+ CGI . escapeHTML ( params [ 'title' ] ) + "</a>"
19
+ end
20
+
21
+ unless params [ 'rating' ] . empty?
22
+ # 'rating' filled stars out of 5 hollow ones
23
+ rating = params [ 'rating' ] . to_i
24
+ stars = ( '★' * rating ) + ( '☆' * ( 5 - rating ) )
25
+
26
+ review << "<div>Rating: <abbr class='rating' title='#{ rating } '>#{ stars } </abbr></div>"
27
+ end
28
+
29
+ if entry . content
30
+ review << "<div class='description'>#{ entry . content . html } </div>"
31
+ end
32
+
33
+ review <<<<END
34
+ </div>
35
+ </div>
36
+ END
37
+
38
+ entry . content = review
39
+ entry . content [ 'type' ] = 'html'
40
+ end
41
+ end
You can’t perform that action at this time.
0 commit comments