Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Overview

The methods added to this helper will be available to all templates in the application.

Instance Method Summary collapse

Instance Method Details



65
66
67
68
# File 'app/helpers/application_helper.rb', line 65

def comment_toggle_link(post)
  text = post.allows_comment? ? 'Disallow Comments' : 'Allow Comments'
  link_to(text, {:controller => 'post', :action => 'toggle_commenting', :id => post.id}, {'onclick' => "return toggleCommenting('#{post.id}')"})
end


56
57
58
# File 'app/helpers/application_helper.rb', line 56

def link_user(user, text=user.name)
  link_to text, :controller => 'user', :action => user.username
end

#page_subtitleObject



103
104
105
# File 'app/helpers/application_helper.rb', line 103

def page_subtitle()
  user_page? ? @user.subtitle : @app_config['main']['subtitle']
end

#page_titleObject



99
100
101
# File 'app/helpers/application_helper.rb', line 99

def page_title()
  user_page? ? @user.title : @app_config['main']['title']
end

#post_links(post) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/application_helper.rb', line 70

def post_links(post)
  if post.allows_comment?
    disp = ''
  else
    disp = 'style="display: none;"'
  end

  str = '<ul class="postlinks">'
  str << "<li #{disp} id=\"replylink_#{post.id}\">" + link_to('Reply', {:controller => 'post', :action => 'reply', :user => post.user.username, :slug => post.slug}, 'onclick' => "return showReply('#{post.id}')", 'id' => "post_reply_#{post.id}") + "</li>"
  str << '<li>' + link_to('Add Tags', {:controller => 'post', :action => 'tag', :user => post.user.username, :slug => post.slug}, 'onclick' => "return showTagger('#{post.id}')", 'id' => "post_tagger_#{post.id}") + '</li>'
  str << '<li>' + link_to("View / Permalink", {:controller => 'post', :action => 'view', :user => post.user.username, :slug => post.slug}, {'class' => 'middle' }) + '</li>'
  str << "<li #{disp} id=\"comment_count_#{post.id}\"> " + link_to("Comments (#{post.comments.length})", :controller => 'post', :action => 'view', :user => post.user.username, :slug => post.slug, :anchor => 'comments') + "</li>"    
  str << "<li>" + link_to("Trackbacks (#{post.pings.length})", :controller => 'post', :action => 'view', :user => post.user.username, :slug => post.slug, :anchor => 'trackbacks') + "</li>"
  str << '</ul>'
end

#render_body(post) ⇒ Object



86
87
88
89
90
91
# File 'app/helpers/application_helper.rb', line 86

def render_body(post)
  unless ['view', 'reply'].include? @params['action']
    return post.sections.first + (post.sections.length > 1 ? '<p>' + link_to('Read More ...', :controller => 'post', :action => 'view', :user => post.user.username, :slug => post.slug) + '</p>' : '')
  end
  post.rendered
end

#server_url_for(options = {}) ⇒ Object



107
108
109
# File 'app/helpers/application_helper.rb', line 107

def server_url_for(options = {})
  "http://" << @request.host << @request.port_string << (options.empty? ? '' : url_for(options))
end

#sexifytime(t, username = nil) ⇒ Object



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
51
52
53
54
# File 'app/helpers/application_helper.rb', line 3

def sexifytime(t, username=nil)
  day = case t.day % 10
  when 0
    "#{t.day}th"
  when 1
    "#{t.day}st"
  when 2
    "#{t.day}nd"
  when 3
    "#{t.day}rd"
  else
    "#{t.day}th"
  end
  
  day = "#{t.day}th" if [12, 13, 14].include? t.day


  str = ''
  str <<        link_to(day, :controller => 'post', :action => 'range', :user => username, :year => t.strftime('%Y'), :month => t.strftime('%m'), :day => t.strftime('%d'))
  str << ' ' << link_to(t.strftime('%B'), :controller => 'post', :action => 'range', :user => username, :year => t.strftime('%Y'), :month => t.strftime('%m'), :day => nil)
  str << ' ' << link_to(t.strftime('%Y'), :controller => 'post', :action => 'range', :user => username, :year => t.strftime('%Y'), :month => nil, :day => nil)
  str << ', '

  str << case t.hour
  when 0..2
    'the wee hours'
  when 3..6
    'terribly early in the morning'
  when 7..9
    'early morning'
  when 10
    'mid-morning'
  when 11
    'late morning'
  when 12..13
    'lunch time'
  when 14
    'early afternoon'
  when 15..16
    'mid-afternoon'
  when 17
    'late afternoon'
  when 18..19
    'early evening'
  when 20..21
    'evening time'
  when 22
    'late evening'
  when 23
    'late at night'
  end
end


60
61
62
63
# File 'app/helpers/application_helper.rb', line 60

def tag_links(post, limit = nil)
  tags = post.tags.sort_by {|tag| tag.numitems}.reverse.map { |tag| link_to(tag.tag, :controller => 'tags', :action => 'show', :tag => CGI.escape(tag.tag)) }
  (limit ? tags.first(limit) : tags ).join(', ')
end

#user_face(user) ⇒ Object



93
94
95
96
97
# File 'app/helpers/application_helper.rb', line 93

def user_face(user)
  return nil unless user.has_face?
  image = %{<img class="user_face" src="/image/face/#{user.id}" height="#{user.face.height}" width="#{user.face.width}" />}
  link_user(user, image) 
end