Module: Aerial::Helper
- Defined in:
- lib/aerial/base.rb
Instance Method Summary collapse
-
#base_url ⇒ Object
Returns the absolute base url.
-
#blurb(text, options = {}) ⇒ Object
Truncate a string.
-
#full_hostname(link = "") ⇒ Object
Creates an absolute link
linklink 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. -
#host ⇒ Object
Returns the request host TODO: just use request.host (rack.lighthouseapp.com/projects/22435/tickets/77-requesthost-should-answer-the-forwarded-host).
-
#humanized_date(date) ⇒ Object
Format just the DATE in a nice easy to read format.
-
#link_to_author(comment) ⇒ Object
Author link.
-
#link_to_tags(tags) ⇒ Object
Create a list of hyperlinks with a set of tags.
-
#page_title ⇒ Object
Display the page titles in proper format.
-
#partial(template, options = {}) ⇒ Object
Handy method to render partials including collections.
-
#path ⇒ Object
Returns the path.
-
#rss_date(date) ⇒ Object
Format for the rss 2.0 feed.
-
#short_date(date) ⇒ Object
Format just the DATE in a short way.
-
#url ⇒ Object
Returns the current url.
Instance Method Details
#base_url ⇒ Object
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, ={}) .merge!(:length => 160, :omission => "...") if text l = [:length] - [:omission].length chars = text (chars.length > [:length] ? chars[0...l] + [: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 |
#host ⇒ Object
Returns the request host TODO: just use request.host (rack.lighthouseapp.com/projects/22435/tickets/77-requesthost-should-answer-the-forwarded-host)
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 |
#link_to_author(comment) ⇒ Object
Author link
98 99 100 101 102 103 |
# File 'lib/aerial/base.rb', line 98 def (comment) unless comment.homepage.blank? return "<a href='#{comment.homepage}' rel='external'>#{comment.}</a>" end comment. end |
#link_to_tags(tags) ⇒ Object
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 () return unless links = [] .each do |tag| links << "<a href='/tags/#{tag}' rel='#{tag}'>#{tag}</a>" end links.join(", ") end |
#page_title ⇒ Object
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, = {}) .merge!(:layout => false) return if .has_key?(:collection) && [:collection].nil? if collection = .delete(:collection) then collection.inject([]) do |buffer, member| buffer << haml(template, .merge(:layout => false, :locals => {template.to_sym => member})) end.join("\n") else haml(template, ) end end |
#path ⇒ Object
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 |
#url ⇒ Object
Returns the current url
6 |
# File 'lib/aerial/base.rb', line 6 def url() request.url end |