forked from diaspora/diaspora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_picker.rb
50 lines (39 loc) · 925 Bytes
/
template_picker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class TemplatePicker
attr_accessor :post
TEMPLATES = %w{ status_with_photo_backdrop
note
photo_backdrop
activity_streams_photo
status
}
def initialize(post)
self.post = post
end
def template_name
TEMPLATES.each do |template|
return TemplatePicker.jsonify_name(template) if self.send("#{template}?".to_sym)
end
'status' #default
end
def status_with_photo_backdrop?
status? && photo_backdrop?
end
def note?
self.status? && post.text(:plain_text => true).length > 200
end
def photo_backdrop?
post.photos.size == 1
end
def activity_streams_photo?
post.type == "ActivityStreams::Photo"
end
def status?
post.text?
end
def self.jsonified_templates
TEMPLATES.map{|x| jsonify_name(x)}
end
def self.jsonify_name(name)
name.gsub('_', '-')
end
end