1
- # encoding: utf-8
1
+ # Helper methods for the whole application
2
2
module ApplicationHelper
3
-
4
- def title ( title , tag = nil )
3
+ def title ( title , tag = nil )
5
4
title = h ( title )
6
5
@title . unshift title
7
6
content_tag ( tag , title ) if tag
@@ -11,7 +10,7 @@ def h1(str)
11
10
title ( str , :h1 )
12
11
end
13
12
14
- def feed ( title , link = nil )
13
+ def feed ( title , link = nil )
15
14
link ||= { format : :atom }
16
15
@feeds [ link ] = title
17
16
end
@@ -22,15 +21,30 @@ def link(rel, link)
22
21
23
22
def meta_for ( content )
24
23
@author = content . node . user . try ( :name )
25
- @keywords = content . node . popular_tags . map &:name
24
+ @keywords = content . node . popular_tags . map ( &:name )
26
25
@description = content . title
27
- @dont_index = true if content . node . score < 0
28
- published_at = content . node . try ( :created_at ) || DateTime . now ( )
26
+ @dont_index = true if content . node . score . negative?
27
+ published_at = content . node . try ( :created_at ) || DateTime . now
29
28
# For all content recently published, ask robots to not index it if
30
29
# a minimum score is not reached during the first 24 hours.
31
30
# The threshold is set to the one used by moderated News, so the moderated
32
31
# content can still be fastly indexed by robots.
33
- @dont_index ||= true if published_at > DateTime . now ( ) - 24 . hour && content . node . score <= News . accept_threshold
32
+ @dont_index ||= true if published_at > DateTime . now - 24 . hours && content . node . score <= News . accept_threshold
34
33
end
35
34
35
+ def list_of ( enum , opts = { } , &block )
36
+ opts_attributes = opts . map { |k , v | " #{ k } ='#{ v } '" } . join
37
+ enum . map do |i |
38
+ result = capture ( i , &block )
39
+
40
+ if result . count ( "\n " ) > 1
41
+ result . gsub! ( "\n " , "\n " )
42
+ result = "\n #{ result . strip } \n "
43
+ else
44
+ result . strip!
45
+ end
46
+
47
+ %(<li#{ opts_attributes } >#{ result } </li>)
48
+ end . join ( "\n " ) . html_safe
49
+ end
36
50
end
0 commit comments