1- # encoding: utf-8
1+ # Helper methods for the whole application
22module ApplicationHelper
3-
4- def title ( title , tag = nil )
3+ def title ( title , tag = nil )
54 title = h ( title )
65 @title . unshift title
76 content_tag ( tag , title ) if tag
@@ -11,7 +10,7 @@ def h1(str)
1110 title ( str , :h1 )
1211 end
1312
14- def feed ( title , link = nil )
13+ def feed ( title , link = nil )
1514 link ||= { format : :atom }
1615 @feeds [ link ] = title
1716 end
@@ -22,15 +21,30 @@ def link(rel, link)
2221
2322 def meta_for ( content )
2423 @author = content . node . user . try ( :name )
25- @keywords = content . node . popular_tags . map &:name
24+ @keywords = content . node . popular_tags . map ( &:name )
2625 @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
2928 # For all content recently published, ask robots to not index it if
3029 # a minimum score is not reached during the first 24 hours.
3130 # The threshold is set to the one used by moderated News, so the moderated
3231 # 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
3433 end
3534
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
3650end
0 commit comments