Chris@0: # redMine - project management software
Chris@0: # Copyright (C) 2006-2007 Jean-Philippe Lang
Chris@0: #
Chris@0: # This program is free software; you can redistribute it and/or
Chris@0: # modify it under the terms of the GNU General Public License
Chris@0: # as published by the Free Software Foundation; either version 2
Chris@0: # of the License, or (at your option) any later version.
Chris@0: #
Chris@0: # This program is distributed in the hope that it will be useful,
Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0: # GNU General Public License for more details.
Chris@0: #
Chris@0: # You should have received a copy of the GNU General Public License
Chris@0: # along with this program; if not, write to the Free Software
Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0:
Chris@0: module WikiHelper
Chris@0:
Chris@0: def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
Chris@0: s = ''
Chris@0: pages.select {|p| p.parent == parent}.each do |page|
Chris@0: attrs = "value='#{page.id}'"
Chris@0: attrs << " selected='selected'" if selected == page
Chris@0: indent = (level > 0) ? (' ' * level * 2 + '» ') : nil
Chris@0:
chris@37: s << "\n" +
Chris@0: wiki_page_options_for_select(pages, selected, page, level + 1)
Chris@0: end
Chris@0: s
Chris@0: end
Chris@0:
Chris@0: def html_diff(wdiff)
Chris@0: words = wdiff.words.collect{|word| h(word)}
Chris@0: words_add = 0
Chris@0: words_del = 0
Chris@0: dels = 0
Chris@0: del_off = 0
Chris@0: wdiff.diff.diffs.each do |diff|
Chris@0: add_at = nil
Chris@0: add_to = nil
Chris@0: del_at = nil
Chris@0: deleted = ""
Chris@0: diff.each do |change|
Chris@0: pos = change[1]
Chris@0: if change[0] == "+"
Chris@0: add_at = pos + dels unless add_at
Chris@0: add_to = pos + dels
Chris@0: words_add += 1
Chris@0: else
Chris@0: del_at = pos unless del_at
Chris@0: deleted << ' ' + h(change[2])
Chris@0: words_del += 1
Chris@0: end
Chris@0: end
Chris@0: if add_at
Chris@0: words[add_at] = '' + words[add_at]
Chris@0: words[add_to] = words[add_to] + ''
Chris@0: end
Chris@0: if del_at
Chris@0: words.insert del_at - del_off + dels + words_add, '' + deleted + ''
Chris@0: dels += 1
Chris@0: del_off += words_del
Chris@0: words_del = 0
Chris@0: end
Chris@0: end
Chris@0: simple_format_without_paragraph(words.join(' '))
Chris@0: end
Chris@0: end