Merge pull request #164 from abf/rosa-build:fix_truncating_filename
fix truncating filename in web git file tree view
This commit is contained in:
commit
ae1fd15dad
|
@ -24,15 +24,13 @@ class String
|
||||||
|
|
||||||
# same as reverse.truncate.reverse
|
# same as reverse.truncate.reverse
|
||||||
def rtruncate(length, options = {})
|
def rtruncate(length, options = {})
|
||||||
text = self.dup
|
chars = self.dup.mb_chars
|
||||||
|
return self if chars.length <= length
|
||||||
options[:omission] ||= "..."
|
options[:omission] ||= "..."
|
||||||
options[:separator] ||= '/'
|
options[:separator] ||= '/'
|
||||||
|
|
||||||
length_with_room_for_omission = length - options[:omission].mb_chars.length
|
start = chars.length - length + options[:omission].mb_chars.length
|
||||||
chars = text.mb_chars
|
stop = options[:separator] ? (chars.index(options[:separator].mb_chars, start) || start) : start
|
||||||
stop = options[:separator] ?
|
"#{options[:omission]}#{chars[stop..-1]}".to_s
|
||||||
(chars.index(options[:separator].mb_chars, length_with_room_for_omission) || length_with_room_for_omission) : length_with_room_for_omission
|
|
||||||
|
|
||||||
(chars.length > length ? "#{options[:omission]}#{chars[-(stop+1)...-1]}" : text).to_s
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue