Module: Aerial::Helper

Defined in:
lib/aerial/base.rb

Instance Method Summary collapse

Instance Method Details

#base_urlObject

Returns the absolute base url



25
26
27
28
29
30
31
32
33
# File 'lib/aerial/base.rb', line 25

def base_url
  scheme = request.scheme
  port = request.port
  url = "#{scheme}://#{host}"
  if scheme == "http" && port != 80 || scheme == "https" && port != 443
    url << ":#{port}"
  end
  url << request.script_name
end

#blurb(text, options = {}) ⇒ Object

Truncate a string



73
74
75
76
77
78
79
80
# File 'lib/aerial/base.rb', line 73

def blurb(text, options ={})
  options.merge!(:length => 160, :omission => "...")
  if text
    l = options[:length] - options[:omission].length
    chars = text
    (chars.length > options[:length] ? chars[0...l] + options[:omission] : text).to_s
  end
end

#full_hostname(link = "") ⇒ Object

Creates an absolute link

+link+ link to append to the baseurl
TODO: should we add more value to this? it seems like we might as well
  just take care of this by appending the link to base_url in the app


39
40
41
# File 'lib/aerial/base.rb', line 39

def full_hostname(link = "")
  "#{base_url}#{link}"
end

#hostObject



10
11
12
13
14
15
16
# File 'lib/aerial/base.rb', line 10

def host
  if request.env['HTTP_X_FORWARDED_SERVER'] =~ /[a-z]*/
    request.env['HTTP_X_FORWARDED_SERVER']
  else
    request.host
  end
end

#humanized_date(date) ⇒ Object

Format just the DATE in a nice easy to read format



50
51
52
53
54
55
56
# File 'lib/aerial/base.rb', line 50

def humanized_date(date)
  if date && date.respond_to?(:strftime)
    date.strftime('%A %B, %d %Y').strip
  else
    'Never'
  end
end

Author link



98
99
100
101
102
103
# File 'lib/aerial/base.rb', line 98

def link_to_author(comment)
  unless comment.homepage.blank?
    return "<a href='#{comment.homepage}' rel='external'>#{comment.author}</a>"
  end
  comment.author
end

Create a list of hyperlinks with a set of tags



106
107
108
109
110
111
112
113
# File 'lib/aerial/base.rb', line 106

def link_to_tags(tags)
  return unless tags
  links = []
  tags.each do |tag|
    links << "<a href='/tags/#{tag}' rel='#{tag}'>#{tag}</a>"
  end
  links.join(", ")
end

#page_titleObject

Display the page titles in proper format



44
45
46
47
# File 'lib/aerial/base.rb', line 44

def page_title
  title = @page_title ? "| #{@page_title}" : ""
  return "#{Aerial.config.title} #{title}"
end

#partial(template, options = {}) ⇒ Object

Handy method to render partials including collections



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/aerial/base.rb', line 83

def partial(template, options = {})
  options.merge!(:layout => false)
  return if options.has_key?(:collection) && options[:collection].nil?

  if collection = options.delete(:collection) then
    collection.inject([]) do |buffer, member|
      buffer << haml(template, options.merge(:layout => false,
                                             :locals => {template.to_sym => member}))
    end.join("\n")
  else
     haml(template, options)
  end
end

#pathObject

Returns the path



19
20
21
22
# File 'lib/aerial/base.rb', line 19

def path
  base = "#{request.env['REQUEST_URI']}".scan(/\w+/).first
  return base.blank? ? "index" : base
end

#rss_date(date) ⇒ Object

Format for the rss 2.0 feed



68
69
70
# File 'lib/aerial/base.rb', line 68

def rss_date(date)
  date.strftime("%a, %d %b %Y %H:%M:%S %Z") #Tue, 03 Jun 2003 09:39:21 GMT
end

#short_date(date) ⇒ Object

Format just the DATE in a short way



59
60
61
62
63
64
65
# File 'lib/aerial/base.rb', line 59

def short_date(date)
  if date && date.respond_to?(:strftime)
    date.strftime('%b %d').strip
  else
    'Never'
  end
end

#urlObject

Returns the current url



6
# File 'lib/aerial/base.rb', line 6

def url() request.url end