add additional check for the undefined method 'html_safe' for nil:NilClass

This commit is contained in:
Alexander Machehin 2014-10-09 14:24:43 +06:00
parent fad1708318
commit 4872e60c56
1 changed files with 13 additions and 10 deletions

View File

@ -106,22 +106,25 @@ module GitHelper
def blob_highlight(blob)
return if blob.nil? || blob.data.blank?
if blob.mime_type == 'text/rpm-spec'
Pygments.highlight blob.data, lexer: 'spec'
else
blob.colorize
end.html_safe
result = if blob.mime_type == 'text/rpm-spec'
Pygments.highlight blob.data, lexer: 'spec'
else
blob.colorize
end
result = nil
result.present? ? result.html_safe : blob.data
rescue MentosError, Yajl::ParseError => e
blob.data.html_safe
end
def blame_highlight(blob, text)
return if blob.nil? || text.blank?
if blob.mime_type == 'text/rpm-spec'
Pygments.highlight(text, lexer: 'spec')
else
blob.lexer.highlight text
end.html_safe
result = if blob.mime_type == 'text/rpm-spec'
Pygments.highlight(text, lexer: 'spec')
else
blob.lexer.highlight text
end
result.present? ? result.html_safe : text
rescue MentosError, Yajl::ParseError => e
text.html_safe
end