Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ad99404d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ad99404d
编写于
4月 14, 2016
作者:
Z
Zeger-Jan van de Weg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Properly handle bigger files
上级
3fd0f537
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
44 addition
and
16 deletion
+44
-16
CHANGELOG
CHANGELOG
+1
-0
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+2
-2
app/models/blob.rb
app/models/blob.rb
+8
-0
app/models/snippet.rb
app/models/snippet.rb
+4
-0
app/views/projects/blob/_text.html.haml
app/views/projects/blob/_text.html.haml
+17
-8
app/views/shared/_file_highlight.html.haml
app/views/shared/_file_highlight.html.haml
+3
-2
lib/gitlab/highlight.rb
lib/gitlab/highlight.rb
+9
-4
未找到文件。
CHANGELOG
浏览文件 @
ad99404d
...
...
@@ -11,6 +11,7 @@ v 8.8.0 (unreleased)
- Allow "NEWS" and "CHANGES" as alternative names for CHANGELOG. !3768 (Connor Shea)
- Added button to toggle whitespaces changes on diff view
- Backport GitLab Enterprise support from EE
- Files over 5MB can only be viewed in their raw form, files over 1MB without highlighting !3718
v 8.7.1 (unreleased)
- Throttle the update of `project.last_activity_at` to 1 minute. !3848
...
...
app/helpers/blob_helper.rb
浏览文件 @
ad99404d
...
...
@@ -3,8 +3,8 @@ module BlobHelper
Gitlab
::
Highlight
.
new
(
blob_name
,
blob_content
,
nowrap:
nowrap
)
end
def
highlight
(
blob_name
,
blob_content
,
nowrap:
false
)
Gitlab
::
Highlight
.
highlight
(
blob_name
,
blob_content
,
nowrap:
nowrap
)
def
highlight
(
blob_name
,
blob_content
,
nowrap:
false
,
plain:
false
)
Gitlab
::
Highlight
.
highlight
(
blob_name
,
blob_content
,
nowrap:
nowrap
,
plain:
plain
)
end
def
no_highlight_files
...
...
app/models/blob.rb
浏览文件 @
ad99404d
...
...
@@ -19,6 +19,14 @@ class Blob < SimpleDelegator
new
(
blob
)
end
def
no_highlighting?
size
&&
size
>
1
.
megabyte
end
def
only_display_raw?
size
&&
size
>
5
.
megabytes
end
def
svg?
text?
&&
language
&&
language
.
name
==
'SVG'
end
...
...
app/models/snippet.rb
浏览文件 @
ad99404d
...
...
@@ -112,6 +112,10 @@ class Snippet < ActiveRecord::Base
visibility_level
end
def
no_highlighting?
content
.
lines
.
count
>
1000
end
class
<<
self
# Searches for snippets with a matching title or file name.
#
...
...
app/views/projects/blob/_text.html.haml
浏览文件 @
ad99404d
-
blob
.
load_all_data!
(
@repository
)
-
if
markup?
(
blob
.
name
)
.file-content.wiki
=
render_markup
(
blob
.
name
,
blob
.
data
)
-
if
blob
.
only_display_raw?
.file-content.code
.nothing-here-block
File too large, you can
=
succeed
'.'
do
=
link_to
'view the raw file'
,
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
target:
'_blank'
-
else
-
unless
blob
.
empty?
=
render
'shared/file_highlight'
,
blob:
blob
-
blob
.
load_all_data!
(
@repository
)
-
if
markup?
(
blob
.
name
)
.file-content.wiki
=
render_markup
(
blob
.
name
,
blob
.
data
)
-
else
.file-content.code
.nothing-here-block
Empty file
-
if
blob
.
empty?
.file-content.code
.nothing-here-block
Empty file
-
else
=
render
'shared/file_highlight'
,
blob:
blob
app/views/shared/_file_highlight.html.haml
浏览文件 @
ad99404d
.file-content.code.js-syntax-highlight
.line-numbers
-
if
blob
.
data
.
present?
-
link_icon
=
icon
(
'link'
)
-
blob
.
data
.
each_line
.
each_with_index
do
|
_
,
index
|
-
offset
=
defined?
(
first_line_number
)
?
first_line_number
:
1
-
i
=
index
+
offset
-# We're not using `link_to` because it is too slow once we get to thousands of lines.
%a
.diff-line-num
{
href:
"#L#{i}"
,
id:
"L#{i}"
,
'data-line-number'
=>
i
}
%i
.fa.fa-link
=
link_icon
=
i
.blob-content
{
data:
{
blob_id:
blob
.
id
}}
=
highlight
(
blob
.
name
,
blob
.
data
)
=
highlight
(
blob
.
name
,
blob
.
data
,
plain:
blob
.
no_highlighting?
)
lib/gitlab/highlight.rb
浏览文件 @
ad99404d
module
Gitlab
class
Highlight
def
self
.
highlight
(
blob_name
,
blob_content
,
nowrap:
true
)
new
(
blob_name
,
blob_content
,
nowrap:
nowrap
).
highlight
(
blob_content
,
continue:
false
)
def
self
.
highlight
(
blob_name
,
blob_content
,
nowrap:
true
,
plain:
false
)
new
(
blob_name
,
blob_content
,
nowrap:
nowrap
).
highlight
(
blob_content
,
continue:
false
,
plain:
plain
)
end
def
self
.
highlight_lines
(
repository
,
ref
,
file_name
)
...
...
@@ -17,8 +18,12 @@ module Gitlab
@lexer
=
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
rescue
Rouge
::
Lexers
::
PlainText
end
def
highlight
(
text
,
continue:
true
)
@formatter
.
format
(
@lexer
.
lex
(
text
,
continue:
continue
)).
html_safe
def
highlight
(
text
,
continue:
true
,
plain:
false
)
if
plain
@formatter
.
format
(
Rouge
::
Lexers
::
PlainText
.
lex
(
text
)).
html_safe
else
@formatter
.
format
(
@lexer
.
lex
(
text
,
continue:
continue
)).
html_safe
end
rescue
@formatter
.
format
(
Rouge
::
Lexers
::
PlainText
.
lex
(
text
)).
html_safe
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录