Mercurial > hg > soundsoftware-site
comparison app/helpers/wiki_helper.rb @ 523:0b6c82dead28 luisf
Merge from branch "cannam"
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 14:23:37 +0100 |
parents | cbce1fd3b1b7 |
children | cbb26bc654de |
comparison
equal
deleted
inserted
replaced
318:f7c525dc7585 | 523:0b6c82dead28 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 module WikiHelper | 18 module WikiHelper |
19 | 19 |
20 def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) | 20 def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) |
21 pages = pages.group_by(&:parent) unless pages.is_a?(Hash) | |
21 s = '' | 22 s = '' |
22 pages.select {|p| p.parent == parent}.each do |page| | 23 if pages.has_key?(parent) |
23 attrs = "value='#{page.id}'" | 24 pages[parent].each do |page| |
24 attrs << " selected='selected'" if selected == page | 25 attrs = "value='#{page.id}'" |
25 indent = (level > 0) ? (' ' * level * 2 + '» ') : nil | 26 attrs << " selected='selected'" if selected == page |
26 | 27 indent = (level > 0) ? (' ' * level * 2 + '» ') : nil |
27 s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" + | 28 |
28 wiki_page_options_for_select(pages, selected, page, level + 1) | 29 s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" + |
30 wiki_page_options_for_select(pages, selected, page, level + 1) | |
31 end | |
29 end | 32 end |
30 s | 33 s |
31 end | 34 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 | 35 end |