Skip to content

Commit 9ba10cc

Browse files
committed
untested make_entry extension mechanism and hReview code
darcs-hash:20080228031015-ce558-faf527d0fb8a3d909d382ed711b8f4615e924708.gz
1 parent 927c3f1 commit 9ba10cc

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

app/controllers/application.rb

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require_dependency "openid_login_system"
22

3+
require 'lib/collection_types'
4+
35
class NeedAuthSub < RuntimeError; end
46

57
class RemoteFailure < RuntimeError
@@ -75,6 +77,7 @@ def n_url url
7577
# links:
7678
# rel
7779
# href
80+
# extra: name of a method to be called on EntryConstructor
7881
def make_entry(params)
7982
unless params
8083
return Atom::Entry.new
@@ -137,6 +140,11 @@ def make_entry(params)
137140
end
138141
end
139142

143+
# extension mechanism
144+
if EntryConstructor.singleton_methods.member? params['extra']
145+
EntryConstructor.send params['extra'].to_sym, entry, params
146+
end
147+
140148
entry
141149
end
142150

lib/collection_types.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

0 commit comments

Comments
 (0)