To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / wiki_helper.rb @ 414:576a1dca2ee2
History | View | Annotate | Download (2.24 KB)
| 1 |
# redMine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
| 3 |
#
|
| 4 |
# This program is free software; you can redistribute it and/or
|
| 5 |
# modify it under the terms of the GNU General Public License
|
| 6 |
# as published by the Free Software Foundation; either version 2
|
| 7 |
# of the License, or (at your option) any later version.
|
| 8 |
#
|
| 9 |
# This program is distributed in the hope that it will be useful,
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
# GNU General Public License for more details.
|
| 13 |
#
|
| 14 |
# You should have received a copy of the GNU General Public License
|
| 15 |
# along with this program; if not, write to the Free Software
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 17 |
|
| 18 |
module WikiHelper |
| 19 |
|
| 20 |
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) |
| 21 |
s = ''
|
| 22 |
pages.select {|p| p.parent == parent}.each do |page|
|
| 23 |
attrs = "value='#{page.id}'"
|
| 24 |
attrs << " selected='selected'" if selected == page |
| 25 |
indent = (level > 0) ? (' ' * level * 2 + '» ') : nil |
| 26 |
|
| 27 |
s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
|
| 28 |
wiki_page_options_for_select(pages, selected, page, level + 1)
|
| 29 |
end
|
| 30 |
s |
| 31 |
end
|
| 32 |
|
| 33 |
def html_diff(wdiff) |
| 34 |
words = wdiff.words.collect{|word| h(word)}
|
| 35 |
words_add = 0
|
| 36 |
words_del = 0
|
| 37 |
dels = 0
|
| 38 |
del_off = 0
|
| 39 |
wdiff.diff.diffs.each do |diff|
|
| 40 |
add_at = nil
|
| 41 |
add_to = nil
|
| 42 |
del_at = nil
|
| 43 |
deleted = ""
|
| 44 |
diff.each do |change|
|
| 45 |
pos = change[1]
|
| 46 |
if change[0] == "+" |
| 47 |
add_at = pos + dels unless add_at
|
| 48 |
add_to = pos + dels |
| 49 |
words_add += 1
|
| 50 |
else
|
| 51 |
del_at = pos unless del_at
|
| 52 |
deleted << ' ' + h(change[2]) |
| 53 |
words_del += 1
|
| 54 |
end
|
| 55 |
end
|
| 56 |
if add_at
|
| 57 |
words[add_at] = '<span class="diff_in">' + words[add_at]
|
| 58 |
words[add_to] = words[add_to] + '</span>'
|
| 59 |
end
|
| 60 |
if del_at
|
| 61 |
words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>' |
| 62 |
dels += 1
|
| 63 |
del_off += words_del |
| 64 |
words_del = 0
|
| 65 |
end
|
| 66 |
end
|
| 67 |
simple_format_without_paragraph(words.join(' '))
|
| 68 |
end
|
| 69 |
end
|