Default encodings for repository files can now be set in application settings (Admin -> Settings -> Repositories encodings).
These encodings are used to convert files content and diff to UTF-8 so that they're properly displayed. Multiple values are allowed (comma separated). git-svn-id: http://redmine.rubyforge.org/svn/trunk@814 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -17,13 +17,27 @@
|
||||
|
||||
require 'coderay'
|
||||
require 'coderay/helpers/file_type'
|
||||
require 'iconv'
|
||||
|
||||
module RepositoriesHelper
|
||||
def syntax_highlight(name, content)
|
||||
type = CodeRay::FileType[name]
|
||||
type ? CodeRay.scan(content, type).html : h(content)
|
||||
end
|
||||
|
||||
|
||||
def to_utf8(str)
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
||||
@encodings.each do |encoding|
|
||||
begin
|
||||
return Iconv.conv('UTF-8', encoding, str)
|
||||
rescue Iconv::Failure
|
||||
# do nothing here and try the next encoding
|
||||
end
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def repository_field_tags(form, repository)
|
||||
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||||
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
|
||||
|
||||
@@ -34,13 +34,13 @@
|
||||
<%= table_file[key].nb_line_left %>
|
||||
</th>
|
||||
<td class="line-code <%= table_file[key].type_diff_left %>">
|
||||
<pre><%= table_file[key].line_left %></pre>
|
||||
<pre><%=to_utf8 table_file[key].line_left %></pre>
|
||||
</td>
|
||||
<th class="line-num">
|
||||
<%= table_file[key].nb_line_right %>
|
||||
</th>
|
||||
<td class="line-code <%= table_file[key].type_diff_right %>">
|
||||
<pre><%= table_file[key].line_right %></pre>
|
||||
<pre><%=to_utf8 table_file[key].line_right %></pre>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -72,11 +72,11 @@
|
||||
</th>
|
||||
<% if table_file[key].line_left.empty? %>
|
||||
<td class="line-code <%= table_file[key].type_diff_right %>">
|
||||
<pre><%= table_file[key].line_right %></pre>
|
||||
<pre><%=to_utf8 table_file[key].line_right %></pre>
|
||||
</td>
|
||||
<% else %>
|
||||
<td class="line-code <%= table_file[key].type_diff_left %>">
|
||||
<pre><%= table_file[key].line_left %></pre>
|
||||
<pre><%=to_utf8 table_file[key].line_left %></pre>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<% line_num = 1 %>
|
||||
<% syntax_highlight(@path, @content).each_line do |line| %>
|
||||
<% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
|
||||
<tr>
|
||||
<th class="line-num"><%= line_num %></th>
|
||||
<td class="line-code"><pre><%= line %></pre></td>
|
||||
|
||||
@@ -48,6 +48,9 @@
|
||||
|
||||
<p><label><%= l(:setting_sys_api_enabled) %></label>
|
||||
<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %></p>
|
||||
|
||||
<p><label><%= l(:setting_repositories_encodings) %></label>
|
||||
<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %><br /><em><%= l(:text_comma_separated) %></em></p>
|
||||
</div>
|
||||
|
||||
<fieldset class="box"><legend><%= l(:setting_issue_list_default_columns) %></legend>
|
||||
|
||||
Reference in New Issue
Block a user