Merge pull request #160 from warpc/151-grit_encodings_problems
[issue #151] Fix for view the russian texts in Git
This commit is contained in:
commit
2f2ce5b9d2
|
@ -1,12 +1,10 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Git::BlobsController < Git::BaseController
|
||||
before_filter :set_path
|
||||
before_filter :set_commit_hash
|
||||
before_filter :find_tree
|
||||
before_filter :set_path_blob
|
||||
before_filter :set_commit_hash
|
||||
|
||||
def show
|
||||
@blob = @tree / @path
|
||||
|
||||
if params[:raw]
|
||||
image_url = Rails.root.to_s + "/" + @path
|
||||
|
||||
|
@ -19,21 +17,18 @@ class Git::BlobsController < Git::BaseController
|
|||
end
|
||||
|
||||
def blame
|
||||
@blob = @tree / @path
|
||||
|
||||
@blame = Grit::Blob.blame(@git_repository.repo, @commit.try(:id), @path)
|
||||
end
|
||||
|
||||
def raw
|
||||
@blob = @tree / @path
|
||||
|
||||
headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"]
|
||||
render :text => @blob.data, :content_type => @blob.mime_type
|
||||
end
|
||||
|
||||
protected
|
||||
def set_path
|
||||
def set_path_blob
|
||||
@path = params[:path]
|
||||
@blob = @tree / @path.encode_to_default
|
||||
end
|
||||
|
||||
def set_commit_hash
|
||||
|
|
|
@ -13,7 +13,7 @@ module CommitHelper
|
|||
end
|
||||
res << "</table>"
|
||||
|
||||
res.join("\n").html_safe
|
||||
res.join("\n").encode_to_default.html_safe
|
||||
end
|
||||
|
||||
# def format_commit_message(message)
|
||||
|
@ -34,7 +34,7 @@ module CommitHelper
|
|||
|
||||
def short_commit_message(message)
|
||||
# Why 42? Because it is the Answer!
|
||||
truncate(message, :length => 42, :omission => "...")
|
||||
truncate(message, :length => 42, :omission => "...").encode_to_default
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ module GitHelper
|
|||
res = "#{link_to @project.name, tree_path(@project)} /"
|
||||
end
|
||||
|
||||
res.html_safe
|
||||
res.encode_to_default.html_safe
|
||||
end
|
||||
|
||||
def render_line_numbers(n)
|
||||
|
@ -38,7 +38,9 @@ module GitHelper
|
|||
|
||||
def render_blob(blob)
|
||||
res = ""
|
||||
blob.data.split("\n").collect{|line| "<div>#{line.present? ? h(line) : "<br>"}</div>"}.join
|
||||
blob.data.encode_to_default.split("\n").collect do |line|
|
||||
"<div>#{line.present? ? h(line) : "<br>"}</div>"
|
||||
end.join
|
||||
end
|
||||
|
||||
def choose_render_way(blob)
|
||||
|
@ -46,4 +48,9 @@ module GitHelper
|
|||
return :text if blob.mime_type.match(/text|xml|json/)
|
||||
:binary
|
||||
end
|
||||
|
||||
def force_encoding_to_site(string)
|
||||
string.dup.encode_to_default
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -29,7 +29,9 @@
|
|||
- @blame.each do |elem|
|
||||
%tr
|
||||
%td.message{ :rowspan => elem[1].length }
|
||||
.commit #{link_to shortest_hash_id(elem[0].id), commit_path(@project, elem[0].id)} by #{elem[0].author} #{elem[0].author != elem[0].committer ? "(#{elem[0].committer})" : "" }
|
||||
.commit
|
||||
#{link_to shortest_hash_id(elem[0].id), commit_path(@project, elem[0].id)} by
|
||||
#{elem[0].author.to_s.encode_to_default} #{elem[0].author != elem[0].committer ? "(#{elem[0].committer.to_s.encode_to_default})" : "" }
|
||||
.message
|
||||
%span.date= commit_date(elem[0].committed_date)
|
||||
%span.message= short_commit_message(elem[0].message)
|
||||
|
@ -40,7 +42,7 @@
|
|||
|
||||
%td.code
|
||||
%pre
|
||||
%div= elem[1].first
|
||||
%div= elem[1].first.encode_to_default
|
||||
|
||||
- elem[1][1..-1].each do |line|
|
||||
%tr
|
||||
|
@ -49,6 +51,6 @@
|
|||
- index += 1
|
||||
%td.code
|
||||
%pre
|
||||
%div= line
|
||||
%div= line.encode_to_default
|
||||
|
||||
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
|
@ -49,7 +49,7 @@
|
|||
%td.blob
|
||||
:plain
|
||||
<br/>
|
||||
<pre>#{ link_to @blob.basename, raw_path(@project, @treeish, @path) }</pre>
|
||||
<pre>#{ link_to @blob.basename.encode_to_default, raw_path(@project, @treeish, @path) }</pre>
|
||||
<br/>
|
||||
|
||||
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
.content
|
||||
.inner
|
||||
|
||||
%a{ :name => h(commit_diff.a_path) }
|
||||
%a{ :name => h(commit_diff.a_path.encode_to_default) }
|
||||
|
||||
.blob_header
|
||||
.size= h(commit_diff.a_path)
|
||||
.size= h(commit_diff.a_path.encode_to_default)
|
||||
- if commit_diff.b_path.present?
|
||||
.buttons
|
||||
= link_to("view file @ #{short_hash_id(@commit.id)}", blob_commit_path(@project, @commit.id, commit_diff.b_path))
|
||||
= link_to("view file @ #{short_hash_id(@commit.id)}", blob_commit_path(@project, @commit.id, commit_diff.b_path.encode_to_default))
|
||||
.clear
|
||||
|
||||
.diff_data
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
%table
|
||||
%tr
|
||||
%td.committers
|
||||
.author #{commit.author}, #{commit_date(commit.authored_date)}
|
||||
.author #{commit.author.to_s.encode_to_default}, #{commit_date(commit.authored_date)}
|
||||
- if commit.committer != commit.author
|
||||
.committer
|
||||
(committed by: #{commit.committer}, #{commit_date(commit.committed_date)})
|
||||
(committed by: #{commit.committer.to_s.encode_to_default}, #{commit_date(commit.committed_date)})
|
||||
%td.message
|
||||
%p= link_to commit.message, commit_path(@project, commit.id)
|
||||
%p= link_to commit.message.encode_to_default, commit_path(@project, commit.id)
|
||||
%td.trees
|
||||
.commit
|
||||
Commit:
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
= image_tag("git/icons/folder_16.png")
|
||||
%td.tree_element
|
||||
- if entry.is_a?(Grit::Blob)
|
||||
= link_to entry.name, blob_path(@project, @treeish, File.join([@path, entry.name].compact))
|
||||
= link_to entry.name.encode_to_default, blob_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact))
|
||||
- else
|
||||
= link_to "#{entry.name}/", tree_path(@project, @treeish, File.join([@path, entry.name].compact))
|
||||
= link_to "#{entry.name.encode_to_default}/", tree_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact))
|
||||
%td==
|
||||
%td.last==
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
require './lib/ext/core/string'
|
|
@ -0,0 +1,5 @@
|
|||
class String
|
||||
def encode_to_default
|
||||
force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue