summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-18 18:22:41 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-18 18:22:41 +0000
commitb3b2eb3e50c519259ce6842b4f658860757e43c1 (patch)
tree0d539a72cd11266b2c8f5f45f91950c713a33a94
parent6be2e99bb60ef828e258345bd43593c93ad680bf (diff)
downloadredmine-b3b2eb3e50c519259ce6842b4f658860757e43c1.tar.gz
redmine-b3b2eb3e50c519259ce6842b4f658860757e43c1.zip
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
-rw-r--r--app/helpers/application_helper.rb8
-rw-r--r--test/fixtures/wiki_contents.yml2
-rw-r--r--test/functional/wiki_controller_test.rb14
3 files changed, 20 insertions, 4 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index bec54a83e..9790848e8 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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
diff --git a/test/fixtures/wiki_contents.yml b/test/fixtures/wiki_contents.yml
index b5fd01080..d65f523ff 100644
--- a/test/fixtures/wiki_contents.yml
+++ b/test/fixtures/wiki_contents.yml
@@ -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.
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 1274e676b..8d2187b47 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -79,6 +79,20 @@ class WikiControllerTest < ActionController::TestCase
get :show, :project_id => 1, :id => 'Unexistent page'
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