##// END OF EJS Templates
Handle the case of a text formatter that doesn't support section edit (#2222)....
Jean-Philippe Lang -
r7711:1e8a9da13168
parent child
Show More
@@ -85,7 +85,10 class WikiController < ApplicationController
85 end
85 end
86 end
86 end
87 @editable = editable?
87 @editable = editable?
88 @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) && params[:version].nil?
88 @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) &&
89 params[:version].nil? &&
90 Redmine::WikiFormatting.supports_section_edit?
91
89 render :action => 'show'
92 render :action => 'show'
90 end
93 end
91
94
@@ -103,7 +106,7 class WikiController < ApplicationController
103 @content.version = @page.content.version
106 @content.version = @page.content.version
104
107
105 @text = @content.text
108 @text = @content.text
106 if params[:section].present?
109 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
107 @section = params[:section].to_i
110 @section = params[:section].to_i
108 @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
111 @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
109 render_404 if @text.blank?
112 render_404 if @text.blank?
@@ -131,7 +134,7 class WikiController < ApplicationController
131
134
132 @content.comments = params[:content][:comments]
135 @content.comments = params[:content][:comments]
133 @text = params[:content][:text]
136 @text = params[:content][:text]
134 if params[:section].present?
137 if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
135 @section = params[:section].to_i
138 @section = params[:section].to_i
136 @section_hash = params[:section_hash]
139 @section_hash = params[:section_hash]
137 @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
140 @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
@@ -62,6 +62,11 module Redmine
62 text
62 text
63 end
63 end
64
64
65 # Returns true if the text formatter supports single section edit
66 def supports_section_edit?
67 (formatter.instance_methods & ['update_section', :update_section]).any?
68 end
69
65 # Returns a cache key for the given text +format+, +object+ and +attribute+ or nil if no caching should be done
70 # Returns a cache key for the given text +format+, +object+ and +attribute+ or nil if no caching should be done
66 def cache_key_for(format, object, attribute)
71 def cache_key_for(format, object, attribute)
67 if object && attribute && !object.new_record? && object.respond_to?(:updated_on) && !format.blank?
72 if object && attribute && !object.new_record? && object.respond_to?(:updated_on) && !format.blank?
@@ -42,4 +42,14 EXPECTED
42
42
43 assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
43 assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
44 end
44 end
45
46 def test_supports_section_edit
47 with_settings :text_formatting => 'textile' do
48 assert_equal true, Redmine::WikiFormatting.supports_section_edit?
49 end
50
51 with_settings :text_formatting => '' do
52 assert_equal false, Redmine::WikiFormatting.supports_section_edit?
53 end
54 end
45 end
55 end
General Comments 0
You need to be logged in to leave comments. Login now