From cdb2781b48f2a3ee2ba7d04574671ee195f7006f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 7 Oct 2007 15:21:40 +0000 Subject: 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 --- app/helpers/repositories_helper.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'app/helpers') 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) -- cgit v1.2.3