summaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-07 15:21:40 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-07 15:21:40 +0000
commitcdb2781b48f2a3ee2ba7d04574671ee195f7006f (patch)
tree9d60371f46307ae53380f96b7e591b948b0bb367 /app/helpers
parentbb724e75c0a9ffc7f97b59ef474d96f221f90fd0 (diff)
downloadredmine-cdb2781b48f2a3ee2ba7d04574671ee195f7006f.tar.gz
redmine-cdb2781b48f2a3ee2ba7d04574671ee195f7006f.zip
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
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/repositories_helper.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
index d82e16561..41218fa79 100644
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -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)