Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 7
- Log:
Initial import of RForum 0.2 sources from a downloaded Tarball.
RForum is a Ruby On Rails based forum and mail gateway service.
- Author:
- adh
- Date:
- Sat Jul 22 18:43:13 +0100 2006
- Size:
- 3017 Bytes
1 | module ForumHelper |
2 | |
3 | def wrap(s, n) |
4 | Wraptools.wrap_ff(s, n) |
5 | end |
6 | |
7 | # Calculates the difference between time and sysdate, and rewrites it as text, |
8 | # e.g. "3 days ago" |
9 | # At present, this is not used anywhere in the code. There is an intention to use it in |
10 | # forum/show action ('this topis was edited 4 centuries ago') |
11 | def format_relative_time(time) |
12 | interval = (Time.now - time) |
13 | seconds = (interval).to_i |
14 | minutes = (interval / 60).to_i |
15 | hours = (interval / (60*60)).to_i |
16 | days = (interval / (60*60*24)).to_i |
17 | |
18 | if days == 0 |
19 | if hours == 0 |
20 | if minutes == 0 |
21 | return l(:seconds_ago, seconds) |
22 | end |
23 | return l(:minutes_ago, minutes) |
24 | end |
25 | return l(:hours_ago, hours) |
26 | end |
27 | |
28 | if days == 1 |
29 | return l(:yesterday) |
30 | else |
31 | return l(:days_ago, days) |
32 | end |
33 | end |
34 | |
35 | # Extract a small part of the text to show in the search results. |
36 | def searchresult_text_excerpt(text, query) |
37 | excerpt = h(text[0,100]) |
38 | if text.size > 100 |
39 | excerpt << '...' |
40 | end |
41 | |
42 | # hilight searched words |
43 | words = query.split |
44 | words.each do |word| |
45 | begin |
46 | excerpt[word] = '<em>' + word + '</em>' |
47 | rescue |
48 | end |
49 | end |
50 | excerpt |
51 | end |
52 | |
53 | # Color quoting levels in a string. Use CGI::escapeHTML before doing this. |
54 | def color_quoting(s) |
55 | s.gsub(/\r\n/, "\n").gsub(/(^)((>)+)(.*?)$/m) do |match| |
56 | '<span class="quoting-level-' + ($2.size / 4).to_s + '">' + $2 + $4 + '</span>' |
57 | end |
58 | end |
59 | |
60 | def format_post_text_new(s) |
61 | #color_quoting(h(s)) |
62 | s = h(Wraptools::unwrap_quoted(s)) |
63 | |
64 | parts = [] |
65 | s.gsub(/\r\n/, "\n").scan(/(^)((>)*)(.*?)$/m) do |match| |
66 | line = $4 |
67 | level = $2.size / 4 |
68 | if level > 0 |
69 | # remove leading space after ">" is removed |
70 | line.sub!(/^ /, '') |
71 | end |
72 | |
73 | # convert leading spaces to |
74 | line.sub!(/^( *)/, '') |
75 | line = ' ' * $1.size + line |
76 | |
77 | parts << [line, level] |
78 | end |
79 | |
80 | cur_level = -1 |
81 | s = '' |
82 | parts.each do |line, level| |
83 | if level > cur_level |
84 | while level > cur_level do |
85 | cur_level += 1 |
86 | s << '<div class="quoting level-' + cur_level.to_s + '">' |
87 | end |
88 | elsif level < cur_level |
89 | while level < cur_level do |
90 | s << '</div>' |
91 | cur_level -= 1 |
92 | end |
93 | end |
94 | |
95 | if line =~ /schrieb:$/ |
96 | line = '<span class="author-level-' + |
97 | (cur_level + 1).to_s + '">' + line + '</span>' |
98 | end |
99 | |
100 | s << line |
101 | s << "<br />" |
102 | end |
103 | |
104 | while 0 <= cur_level do |
105 | s << '</div>' |
106 | cur_level -= 1 |
107 | end |
108 | |
109 | s |
110 | end |
111 | |
112 | # Converts urls in a string to links. |
113 | # The string has to be html-escaped (CGI::escapeHTML) |
114 | def url_to_link(s) |
115 | url_regex= /(http:\/\/[^)\s]+[^.?!\)\]\s])/is |
116 | s.gsub(url_regex) do |match| |
117 | url = $1 |
118 | '<a href="' + |
119 | ('http://' if url =~ /^www/).to_s + |
120 | url + |
121 | '" rel="nofollow">' + |
122 | url + |
123 | '</a>' |
124 | end |
125 | end |
126 | |
127 | end |
128 |