Module: Poodle::DisplayHelper

Defined in:
app/helpers/poodle/display_helper.rb

Instance Method Summary collapse

Instance Method Details

#display_time(time) ⇒ Object



33
34
35
# File 'app/helpers/poodle/display_helper.rb', line 33

def display_time(time)
  distance_of_time_in_words_to_now(time) + (time > Time.now ? " from now" : " ago")
end

#scrap_word(text, char_count_limit, more_text = nil, more_link = nil, style = '') ⇒ Object

Example

scrap_word(long_text, 120)
scrap_word(long_text, 120, "Read More", read_more_url)


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
# File 'app/helpers/poodle/display_helper.rb', line 6

def scrap_word(text, char_count_limit, more_text = nil, more_link = nil, style='')
  # remove HTML tags
  text = text.to_s.gsub(/<\/?[^>]*>/, " ")
  # remove additional spaces
  text = text.to_s.gsub(/[ ]+/, " ")
  if text.length < char_count_limit
    return text
  end
  teaser = ""
  words = text.split(/ /)
  words.each do |word|
    if word.length > 0
      if (teaser + word).length > char_count_limit
        if more_text && more_link
          teaser = teaser + " " + link_to(more_text, more_link,:style=>style, :target=>"_blank")
        else
          teaser = teaser.strip + "..."
        end
        break;
      else
        teaser = teaser + word + " "
      end
    end
  end
  return teaser
end

#stringify_date(date) ⇒ Object



37
38
39
# File 'app/helpers/poodle/display_helper.rb', line 37

def stringify_date(date)
  date.strftime("%A %d %b %Y")
end