Fixes section edit links when text includes pre/code tag (#2222).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7835 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-11-18 18:22:41 +00:00
parent 6be2e99bb6
commit b3b2eb3e50
3 changed files with 20 additions and 4 deletions

View File

@ -489,6 +489,7 @@ module ApplicationHelper
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
@parsed_headings = []
@current_section = 0 if options[:edit_section_links]
text = parse_non_pre_blocks(text) do |text|
[:parse_sections, :parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_macros, :parse_headings].each do |method_name|
send method_name, text, project, obj, attr, only_path, options
@ -732,12 +733,11 @@ module ApplicationHelper
def parse_sections(text, project, obj, attr, only_path, options)
return unless options[:edit_section_links]
section = 0
text.gsub!(HEADING_RE) do
section += 1
if section > 1
@current_section += 1
if @current_section > 1
content_tag('div',
link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => section)),
link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)),
:class => 'contextual',
:title => l(:button_edit_section)) + $1
else

View File

@ -111,6 +111,8 @@ wiki_contents_011:
h2. Heading 1
@WHATEVER@
Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in.
Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc.

View File

@ -80,6 +80,20 @@ class WikiControllerTest < ActionController::TestCase
assert_response 404
end
def test_show_should_display_section_edit_links
@request.session[:user_id] = 2
get :show, :project_id => 1, :id => 'Page with sections'
assert_no_tag 'a', :attributes => {
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1'
}
assert_tag 'a', :attributes => {
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
}
assert_tag 'a', :attributes => {
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
}
end
def test_show_unexistent_page_with_edit_right
@request.session[:user_id] = 2
get :show, :project_id => 1, :id => 'Unexistent page'