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:
parent
bb724e75c0
commit
cdb2781b48
|
@ -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>
|
||||
|
|
|
@ -88,4 +88,8 @@ issue_list_default_columns:
|
|||
- subject
|
||||
- assigned_to
|
||||
- updated_on
|
||||
# encodings used to convert repository files content to UTF-8
|
||||
# multiple values accepted, comma separated
|
||||
repositories_encodings:
|
||||
default: ''
|
||||
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -182,6 +182,7 @@ setting_autologin: Autologin
|
|||
setting_date_format: Date format
|
||||
setting_cross_project_issue_relations: Allow cross-project issue relations
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
||||
label_user: User
|
||||
label_user_plural: Users
|
||||
|
|
|
@ -517,3 +517,4 @@ button_reset: Reset
|
|||
label_added_time_by: Added by %s %s ago
|
||||
field_estimated_hours: Estimated time
|
||||
label_changeset_plural: Changesets
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -182,6 +182,7 @@ setting_autologin: Autologin
|
|||
setting_date_format: Format de date
|
||||
setting_cross_project_issue_relations: Autoriser les relations entre demandes de différents projets
|
||||
setting_issue_list_default_columns: Colonnes affichées par défaut sur la liste des demandes
|
||||
setting_repositories_encodings: Encodages des dépôts
|
||||
|
||||
label_user: Utilisateur
|
||||
label_user_plural: Utilisateurs
|
||||
|
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -515,3 +515,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: 問題の一覧で表示する項目
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -515,3 +515,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Zestawienia zmian
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -514,3 +514,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -515,3 +515,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
|
@ -517,3 +517,4 @@ label_changeset_plural: Changesets
|
|||
field_column_names: Columns
|
||||
label_default_columns: Default columns
|
||||
setting_issue_list_default_columns: Default columns displayed on the issue list
|
||||
setting_repositories_encodings: Repositories encodings
|
||||
|
|
Loading…
Reference in New Issue