##// END OF EJS Templates
Rails3: helper: use html_safe at render_changes_tree(tree) of RepositoriesHelper...
Toshi MARUYAMA -
r7425:f9626e406613
parent child
Show More
@@ -1,285 +1,285
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'iconv'
19 19 require 'redmine/codeset_util'
20 20
21 21 module RepositoriesHelper
22 22 def format_revision(revision)
23 23 if revision.respond_to? :format_identifier
24 24 revision.format_identifier
25 25 else
26 26 revision.to_s
27 27 end
28 28 end
29 29
30 30 def truncate_at_line_break(text, length = 255)
31 31 if text
32 32 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
33 33 end
34 34 end
35 35
36 36 def render_properties(properties)
37 37 unless properties.nil? || properties.empty?
38 38 content = ''
39 39 properties.keys.sort.each do |property|
40 40 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>")
41 41 end
42 42 content_tag('ul', content, :class => 'properties')
43 43 end
44 44 end
45 45
46 46 def render_changeset_changes
47 47 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
48 48 case change.action
49 49 when 'A'
50 50 # Detects moved/copied files
51 51 if !change.from_path.blank?
52 52 change.action =
53 53 @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
54 54 end
55 55 change
56 56 when 'D'
57 57 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
58 58 else
59 59 change
60 60 end
61 61 end.compact
62 62
63 63 tree = { }
64 64 changes.each do |change|
65 65 p = tree
66 66 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
67 67 path = ''
68 68 dirs.each do |dir|
69 69 path += '/' + dir
70 70 p[:s] ||= {}
71 71 p = p[:s]
72 72 p[path] ||= {}
73 73 p = p[path]
74 74 end
75 75 p[:c] = change
76 76 end
77 77 render_changes_tree(tree[:s])
78 78 end
79 79
80 80 def render_changes_tree(tree)
81 81 return '' if tree.nil?
82 82 output = ''
83 83 output << '<ul>'
84 84 tree.keys.sort.each do |file|
85 85 style = 'change'
86 86 text = File.basename(h(file))
87 87 if s = tree[file][:s]
88 88 style << ' folder'
89 89 path_param = to_path_param(@repository.relative_path(file))
90 90 text = link_to(h(text), :controller => 'repositories',
91 91 :action => 'show',
92 92 :id => @project,
93 93 :path => path_param,
94 94 :rev => @changeset.identifier)
95 95 output << "<li class='#{style}'>#{text}</li>"
96 96 output << render_changes_tree(s)
97 97 elsif c = tree[file][:c]
98 98 style << " change-#{c.action}"
99 99 path_param = to_path_param(@repository.relative_path(c.path))
100 100 text = link_to(h(text), :controller => 'repositories',
101 101 :action => 'entry',
102 102 :id => @project,
103 103 :path => path_param,
104 104 :rev => @changeset.identifier) unless c.action == 'D'
105 105 text << " - #{h(c.revision)}" unless c.revision.blank?
106 text << ' (' + link_to(l(:label_diff), :controller => 'repositories',
106 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
107 107 :action => 'diff',
108 108 :id => @project,
109 109 :path => path_param,
110 :rev => @changeset.identifier) + ') ' if c.action == 'M'
111 text << ' ' + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
110 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
111 text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
112 112 output << "<li class='#{style}'>#{text}</li>"
113 113 end
114 114 end
115 115 output << '</ul>'
116 output
116 output.html_safe
117 117 end
118 118
119 119 def to_utf8(str)
120 120 return str if str.nil?
121 121 str = to_utf8_internal(str)
122 122 if str.respond_to?(:force_encoding)
123 123 str.force_encoding('UTF-8')
124 124 end
125 125 str
126 126 end
127 127
128 128 def to_utf8_internal(str)
129 129 return str if str.nil?
130 130 if str.respond_to?(:force_encoding)
131 131 str.force_encoding('ASCII-8BIT')
132 132 end
133 133 return str if str.empty?
134 134 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
135 135 if str.respond_to?(:force_encoding)
136 136 str.force_encoding('UTF-8')
137 137 end
138 138 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
139 139 @encodings.each do |encoding|
140 140 begin
141 141 return Iconv.conv('UTF-8', encoding, str)
142 142 rescue Iconv::Failure
143 143 # do nothing here and try the next encoding
144 144 end
145 145 end
146 146 str = Redmine::CodesetUtil.replace_invalid_utf8(str)
147 147 end
148 148 private :to_utf8_internal
149 149
150 150 def repository_field_tags(form, repository)
151 151 method = repository.class.name.demodulize.underscore + "_field_tags"
152 152 if repository.is_a?(Repository) &&
153 153 respond_to?(method) && method != 'repository_field_tags'
154 154 send(method, form, repository)
155 155 end
156 156 end
157 157
158 158 def scm_select_tag(repository)
159 159 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
160 160 Redmine::Scm::Base.all.each do |scm|
161 161 if Setting.enabled_scm.include?(scm) ||
162 162 (repository && repository.class.name.demodulize == scm)
163 163 scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
164 164 end
165 165 end
166 166 select_tag('repository_scm',
167 167 options_for_select(scm_options, repository.class.name.demodulize),
168 168 :disabled => (repository && !repository.new_record?),
169 169 :onchange => remote_function(
170 170 :url => {
171 171 :controller => 'repositories',
172 172 :action => 'edit',
173 173 :id => @project
174 174 },
175 175 :method => :get,
176 176 :with => "Form.serialize(this.form)")
177 177 )
178 178 end
179 179
180 180 def with_leading_slash(path)
181 181 path.to_s.starts_with?('/') ? path : "/#{path}"
182 182 end
183 183
184 184 def without_leading_slash(path)
185 185 path.gsub(%r{^/+}, '')
186 186 end
187 187
188 188 def subversion_field_tags(form, repository)
189 189 content_tag('p', form.text_field(:url, :size => 60, :required => true,
190 190 :disabled => (repository && !repository.root_url.blank?)) +
191 191 '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
192 192 content_tag('p', form.text_field(:login, :size => 30)) +
193 193 content_tag('p', form.password_field(
194 194 :password, :size => 30, :name => 'ignore',
195 195 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
196 196 :onfocus => "this.value=''; this.name='repository[password]';",
197 197 :onchange => "this.name='repository[password]';"))
198 198 end
199 199
200 200 def darcs_field_tags(form, repository)
201 201 content_tag('p', form.text_field(
202 202 :url, :label => l(:field_path_to_repository),
203 203 :size => 60, :required => true,
204 204 :disabled => (repository && !repository.new_record?))) +
205 205 content_tag('p', form.select(
206 206 :log_encoding, [nil] + Setting::ENCODINGS,
207 207 :label => l(:field_commit_logs_encoding), :required => true))
208 208 end
209 209
210 210 def mercurial_field_tags(form, repository)
211 211 content_tag('p', form.text_field(
212 212 :url, :label => l(:field_path_to_repository),
213 213 :size => 60, :required => true,
214 214 :disabled => (repository && !repository.root_url.blank?)
215 215 ) +
216 216 '<br />' + l(:text_mercurial_repository_note)) +
217 217 content_tag('p', form.select(
218 218 :path_encoding, [nil] + Setting::ENCODINGS,
219 219 :label => l(:field_scm_path_encoding)
220 220 ) +
221 221 '<br />' + l(:text_scm_path_encoding_note))
222 222 end
223 223
224 224 def git_field_tags(form, repository)
225 225 content_tag('p', form.text_field(
226 226 :url, :label => l(:field_path_to_repository),
227 227 :size => 60, :required => true,
228 228 :disabled => (repository && !repository.root_url.blank?)
229 229 ) +
230 230 '<br />' +
231 231 l(:text_git_repository_note)) +
232 232 content_tag('p', form.select(
233 233 :path_encoding, [nil] + Setting::ENCODINGS,
234 234 :label => l(:field_scm_path_encoding)
235 235 ) +
236 236 '<br />' + l(:text_scm_path_encoding_note)) +
237 237 content_tag('p', form.check_box(
238 238 :extra_report_last_commit,
239 239 :label => l(:label_git_report_last_commit)
240 240 ))
241 241 end
242 242
243 243 def cvs_field_tags(form, repository)
244 244 content_tag('p', form.text_field(
245 245 :root_url,
246 246 :label => l(:field_cvsroot),
247 247 :size => 60, :required => true,
248 248 :disabled => !repository.new_record?)) +
249 249 content_tag('p', form.text_field(
250 250 :url,
251 251 :label => l(:field_cvs_module),
252 252 :size => 30, :required => true,
253 253 :disabled => !repository.new_record?)) +
254 254 content_tag('p', form.select(
255 255 :log_encoding, [nil] + Setting::ENCODINGS,
256 256 :label => l(:field_commit_logs_encoding), :required => true)) +
257 257 content_tag('p', form.select(
258 258 :path_encoding, [nil] + Setting::ENCODINGS,
259 259 :label => l(:field_scm_path_encoding)
260 260 ) +
261 261 '<br />' + l(:text_scm_path_encoding_note))
262 262 end
263 263
264 264 def bazaar_field_tags(form, repository)
265 265 content_tag('p', form.text_field(
266 266 :url, :label => l(:field_path_to_repository),
267 267 :size => 60, :required => true,
268 268 :disabled => (repository && !repository.new_record?))) +
269 269 content_tag('p', form.select(
270 270 :log_encoding, [nil] + Setting::ENCODINGS,
271 271 :label => l(:field_commit_logs_encoding), :required => true))
272 272 end
273 273
274 274 def filesystem_field_tags(form, repository)
275 275 content_tag('p', form.text_field(
276 276 :url, :label => l(:field_root_directory),
277 277 :size => 60, :required => true,
278 278 :disabled => (repository && !repository.root_url.blank?))) +
279 279 content_tag('p', form.select(
280 280 :path_encoding, [nil] + Setting::ENCODINGS,
281 281 :label => l(:field_scm_path_encoding)
282 282 ) +
283 283 '<br />' + l(:text_scm_path_encoding_note))
284 284 end
285 285 end
General Comments 0
You need to be logged in to leave comments. Login now