Module: BumbleHelper

Defined in:
app/helpers/bumble_helper.rb

Instance Method Summary collapse

Instance Method Details

#format_datetime_ago(time) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'app/helpers/bumble_helper.rb', line 10

def format_datetime_ago(time)
  if time > 5.days.ago
    formatted = time_ago_in_words(time).capitalize
    formatted.insert(0, 'Live in ') if time > Time.now
    formatted.insert(formatted.length, ' ago') if time < Time.now
  end

   :abbr, formatted || time.strftime('%d %b %y'), :title => time.iso8601, :class => 'published updated'
end

#markdown(text) ⇒ Object



2
3
4
# File 'app/helpers/bumble_helper.rb', line 2

def markdown(text)
  text.blank? ? "" : sanitize(RDiscount.new(text).to_html, :tags => %w(a p pre code b strong em i strike ul ol li blockquote br))
end

#page_descriptionObject



24
25
26
# File 'app/helpers/bumble_helper.rb', line 24

def page_description
  escape_once((@page_description || 'TODO'))
end

#page_titleObject



20
21
22
# File 'app/helpers/bumble_helper.rb', line 20

def page_title
  escape_once(strip_tags([DOMAIN, @page_title].compact.reject(&:blank?).join(' | ')))
end

#render_post(post, title = true) ⇒ Object



6
7
8
# File 'app/helpers/bumble_helper.rb', line 6

def render_post(post, title = true)
  render :partial => "posts/types/#{post.class.to_s.downcase}.html.haml", :object => post, :locals => {:title => title}
end


43
44
45
46
47
48
49
# File 'app/helpers/bumble_helper.rb', line 43

def spam_link_for(comment)
  if comment.approved?
    link_to 'Spam', reject_comment_path(comment)
  else
    link_to 'Approve', approve_comment_path(comment)
  end
end

#youtube_embed(link, width = 500, height = 300) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/bumble_helper.rb', line 28

def youtube_embed(link, width = 500, height = 300)
  matches = link.match(/http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/)
  youtube_id = matches[2]
  if youtube_id
     :object, :width => width, :height => height, :data => "http://www.youtube.com/v/#{youtube_id}" do
      tag(:param, :name => 'movie', :value => "http://www.youtube.com/v/#{youtube_id}") +
      tag(:param, :name => 'allowFullScreen', :value => 'true') +
      tag(:param, :name => 'allowscriptaccess', :value => 'always') +
      tag(:embed, :src => "http://www.youtube.com/v/#{youtube_id}", :type => 'application/x-shockwave-flash', :allowscriptaccess => 'always', :allowfullscreen => 'true', :width => width, :height => height)
    end
  else
    link_to link, link
  end
end