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:
Jean-Philippe Lang 2007-10-07 15:21:40 +00:00
parent bb724e75c0
commit cdb2781b48
20 changed files with 42 additions and 6 deletions

View File

@ -17,13 +17,27 @@
require 'coderay' require 'coderay'
require 'coderay/helpers/file_type' require 'coderay/helpers/file_type'
require 'iconv'
module RepositoriesHelper module RepositoriesHelper
def syntax_highlight(name, content) def syntax_highlight(name, content)
type = CodeRay::FileType[name] type = CodeRay::FileType[name]
type ? CodeRay.scan(content, type).html : h(content) type ? CodeRay.scan(content, type).html : h(content)
end 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) def repository_field_tags(form, repository)
method = repository.class.name.demodulize.underscore + "_field_tags" method = repository.class.name.demodulize.underscore + "_field_tags"
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)

View File

@ -34,13 +34,13 @@
<%= table_file[key].nb_line_left %> <%= table_file[key].nb_line_left %>
</th> </th>
<td class="line-code <%= table_file[key].type_diff_left %>"> <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> </td>
<th class="line-num"> <th class="line-num">
<%= table_file[key].nb_line_right %> <%= table_file[key].nb_line_right %>
</th> </th>
<td class="line-code <%= table_file[key].type_diff_right %>"> <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> </td>
</tr> </tr>
<% end %> <% end %>
@ -72,11 +72,11 @@
</th> </th>
<% if table_file[key].line_left.empty? %> <% if table_file[key].line_left.empty? %>
<td class="line-code <%= table_file[key].type_diff_right %>"> <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> </td>
<% else %> <% else %>
<td class="line-code <%= table_file[key].type_diff_left %>"> <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> </td>
<% end %> <% end %>
</tr> </tr>

View File

@ -9,7 +9,7 @@
</thead> </thead>
<tbody> <tbody>
<% line_num = 1 %> <% line_num = 1 %>
<% syntax_highlight(@path, @content).each_line do |line| %> <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
<tr> <tr>
<th class="line-num"><%= line_num %></th> <th class="line-num"><%= line_num %></th>
<td class="line-code"><pre><%= line %></pre></td> <td class="line-code"><pre><%= line %></pre></td>

View File

@ -48,6 +48,9 @@
<p><label><%= l(:setting_sys_api_enabled) %></label> <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> <%= 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> </div>
<fieldset class="box"><legend><%= l(:setting_issue_list_default_columns) %></legend> <fieldset class="box"><legend><%= l(:setting_issue_list_default_columns) %></legend>

View File

@ -88,4 +88,8 @@ issue_list_default_columns:
- subject - subject
- assigned_to - assigned_to
- updated_on - updated_on
# encodings used to convert repository files content to UTF-8
# multiple values accepted, comma separated
repositories_encodings:
default: ''

View File

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -182,6 +182,7 @@ setting_autologin: Autologin
setting_date_format: Date format setting_date_format: Date format
setting_cross_project_issue_relations: Allow cross-project issue relations setting_cross_project_issue_relations: Allow cross-project issue relations
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings
label_user: User label_user: User
label_user_plural: Users label_user_plural: Users

View File

@ -517,3 +517,4 @@ button_reset: Reset
label_added_time_by: Added by %s %s ago label_added_time_by: Added by %s %s ago
field_estimated_hours: Estimated time field_estimated_hours: Estimated time
label_changeset_plural: Changesets label_changeset_plural: Changesets
setting_repositories_encodings: Repositories encodings

View File

@ -182,6 +182,7 @@ setting_autologin: Autologin
setting_date_format: Format de date setting_date_format: Format de date
setting_cross_project_issue_relations: Autoriser les relations entre demandes de différents projets 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_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: Utilisateur
label_user_plural: Utilisateurs label_user_plural: Utilisateurs

View File

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -515,3 +515,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: 問題の一覧で表示する項目 setting_issue_list_default_columns: 問題の一覧で表示する項目
setting_repositories_encodings: Repositories encodings

View File

@ -515,3 +515,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -514,3 +514,4 @@ label_changeset_plural: Zestawienia zmian
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -515,3 +515,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

View File

@ -517,3 +517,4 @@ label_changeset_plural: Changesets
field_column_names: Columns field_column_names: Columns
label_default_columns: Default columns label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings