[refs #151] refactoring

This commit is contained in:
Alexander Machehin 2012-02-06 19:58:27 +06:00
parent a79a081fd1
commit 70346f0015
9 changed files with 15 additions and 31 deletions

View File

@ -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.force_encoding(Encoding::ASCII_8BIT)
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.force_encoding(Encoding::ASCII_8BIT)
@blame = Grit::Blob.blame(@git_repository.repo, @commit.try(:id), @path)
end
def raw
@blob = @tree / @path.force_encoding(Encoding::ASCII_8BIT)
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

View File

@ -13,7 +13,7 @@ module CommitHelper
end
res << "</table>"
res.join("\n").force_encoding(Encoding.default_internal || Encoding::UTF_8).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 => "...").force_encoding(Encoding.default_internal || Encoding::UTF_8)
truncate(message, :length => 42, :omission => "...").encode_to_default
end
end

View File

@ -38,7 +38,7 @@ module GitHelper
def render_blob(blob)
res = ""
blob.data.force_encoding(Encoding.default_internal || Encoding::UTF_8).split("\n").collect do |line|
blob.data.encode_to_default.split("\n").collect do |line|
"<div>#{line.present? ? h(line) : "<br>"}</div>"
end.join
end
@ -50,7 +50,7 @@ module GitHelper
end
def force_encoding_to_site(string)
string.dup.force_encoding(Encoding.default_internal || Encoding::UTF_8)
string.dup.encode_to_default
end
end

View File

@ -42,7 +42,7 @@
%td.code
%pre
%div= elem[1].first.force_encoding(Encoding.default_internal || Encoding::UTF_8)
%div= elem[1].first.encode_to_default
- elem[1][1..-1].each do |line|
%tr
@ -51,6 +51,6 @@
- index += 1
%td.code
%pre
%div= line.force_encoding(Encoding.default_internal || Encoding::UTF_8)
%div= line.encode_to_default
- content_for :sidebar, render(:partial => 'git/shared/sidebar')

View File

@ -49,7 +49,7 @@
%td.blob
:plain
<br/>
<pre>#{ link_to @blob.basename.force_encoding(Encoding.default_internal || Encoding::UTF_8), 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')

View File

@ -2,13 +2,13 @@
.content
.inner
%a{ :name => h(commit_diff.a_path.force_encoding(Encoding.default_internal || Encoding::UTF_8)) }
%a{ :name => h(commit_diff.a_path.encode_to_default) }
.blob_header
.size= h(commit_diff.a_path.force_encoding(Encoding.default_internal || Encoding::UTF_8))
.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.force_encoding(Encoding.default_internal || Encoding::UTF_8)))
= 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

View File

@ -1 +1 @@
require './lib/core'
require './lib/ext/core/string'

View File

@ -1,3 +0,0 @@
Dir.glob(File.join('.', 'lib', 'ext', 'core', '*')) do |file|
require file
end

View File

@ -1,8 +0,0 @@
class Object
alias_method :base_to_s, :to_s
def to_s
res = base_to_s.dup
res.force_encoding(Encoding.default_internal || Encoding::UTF_8)
end
end