Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d3c0cfa5
Commit
d3c0cfa5
authored
Apr 07, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't show 'Copy content' button on text files that are not rendered as text
parent
50608648
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
40 deletions
+58
-40
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+4
-0
app/models/blob.rb
app/models/blob.rb
+25
-5
app/views/projects/blob/_blob.html.haml
app/views/projects/blob/_blob.html.haml
+7
-1
app/views/projects/blob/_header.html.haml
app/views/projects/blob/_header.html.haml
+1
-1
app/views/projects/blob/_image.html.haml
app/views/projects/blob/_image.html.haml
+1
-14
app/views/projects/blob/_markup.html.haml
app/views/projects/blob/_markup.html.haml
+4
-0
app/views/projects/blob/_svg.html.haml
app/views/projects/blob/_svg.html.haml
+9
-0
app/views/projects/blob/_text.html.haml
app/views/projects/blob/_text.html.haml
+2
-19
app/views/projects/blob/_too_large.html.haml
app/views/projects/blob/_too_large.html.haml
+5
-0
No files found.
app/helpers/blob_helper.rb
View file @
d3c0cfa5
...
@@ -118,6 +118,10 @@ module BlobHelper
...
@@ -118,6 +118,10 @@ module BlobHelper
blob
&&
blob
.
text?
&&
!
blob
.
lfs_pointer?
&&
!
blob
.
only_display_raw?
blob
&&
blob
.
text?
&&
!
blob
.
lfs_pointer?
&&
!
blob
.
only_display_raw?
end
end
def
blob_rendered_as_text?
(
blob
)
blob_text_viewable?
(
blob
)
&&
blob
.
to_partial_path
(
@project
)
==
'text'
end
def
blob_size
(
blob
)
def
blob_size
(
blob
)
if
blob
.
lfs_pointer?
if
blob
.
lfs_pointer?
blob
.
lfs_size
blob
.
lfs_size
...
...
app/models/blob.rb
View file @
d3c0cfa5
...
@@ -42,12 +42,16 @@ class Blob < SimpleDelegator
...
@@ -42,12 +42,16 @@ class Blob < SimpleDelegator
size
&&
truncated?
size
&&
truncated?
end
end
def
extension
extname
.
downcase
.
delete
(
'.'
)
end
def
svg?
def
svg?
text?
&&
language
&&
language
.
name
==
'SVG'
text?
&&
language
&&
language
.
name
==
'SVG'
end
end
def
pdf?
def
pdf?
name
&&
File
.
extname
(
name
)
==
'.
pdf'
extension
==
'
pdf'
end
end
def
ipython_notebook?
def
ipython_notebook?
...
@@ -55,11 +59,15 @@ class Blob < SimpleDelegator
...
@@ -55,11 +59,15 @@ class Blob < SimpleDelegator
end
end
def
sketch?
def
sketch?
binary?
&&
ext
name
.
downcase
.
delete
(
'.'
)
==
'sketch'
binary?
&&
ext
ension
==
'sketch'
end
end
def
stl?
def
stl?
extname
.
downcase
.
delete
(
'.'
)
==
'stl'
extension
==
'stl'
end
def
markup?
text?
&&
Gitlab
::
MarkupHelper
.
markup?
(
name
)
end
end
def
size_within_svg_limits?
def
size_within_svg_limits?
...
@@ -77,8 +85,10 @@ class Blob < SimpleDelegator
...
@@ -77,8 +85,10 @@ class Blob < SimpleDelegator
else
else
'text'
'text'
end
end
elsif
image?
||
svg?
elsif
image?
'image'
'image'
elsif
svg?
'svg'
elsif
pdf?
elsif
pdf?
'pdf'
'pdf'
elsif
ipython_notebook?
elsif
ipython_notebook?
...
@@ -87,8 +97,18 @@ class Blob < SimpleDelegator
...
@@ -87,8 +97,18 @@ class Blob < SimpleDelegator
'sketch'
'sketch'
elsif
stl?
elsif
stl?
'stl'
'stl'
elsif
markup?
if
only_display_raw?
'too_large'
else
'markup'
end
elsif
text?
elsif
text?
'text'
if
only_display_raw?
'too_large'
else
'text'
end
else
else
'download'
'download'
end
end
...
...
app/views/projects/blob/_blob.html.haml
View file @
d3c0cfa5
...
@@ -33,4 +33,10 @@
...
@@ -33,4 +33,10 @@
=
link_to
'Fork'
,
fork_path
,
method: :post
,
class:
'btn btn-grouped btn-inverted btn-new'
=
link_to
'Fork'
,
fork_path
,
method: :post
,
class:
'btn btn-grouped btn-inverted btn-new'
%button
.js-cancel-fork-suggestion.btn.btn-grouped
{
type:
'button'
}
%button
.js-cancel-fork-suggestion.btn.btn-grouped
{
type:
'button'
}
Cancel
Cancel
=
render
blob
.
to_partial_path
(
@project
),
blob:
blob
-
if
blob
.
empty?
.file-content.code
.nothing-here-block
Empty file
-
else
=
render
blob
.
to_partial_path
(
@project
),
blob:
blob
app/views/projects/blob/_header.html.haml
View file @
d3c0cfa5
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
.file-actions.hidden-xs
.file-actions.hidden-xs
.btn-group
{
role:
"group"
}
<
.btn-group
{
role:
"group"
}
<
=
copy_blob_content_button
(
blob
)
if
!
blame
&&
blob_
text_viewable
?
(
blob
)
=
copy_blob_content_button
(
blob
)
if
!
blame
&&
blob_
rendered_as_text
?
(
blob
)
=
open_raw_file_button
(
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
))
=
open_raw_file_button
(
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
))
=
view_on_environment_button
(
@commit
.
sha
,
@path
,
@environment
)
if
@environment
=
view_on_environment_button
(
@commit
.
sha
,
@path
,
@environment
)
if
@environment
...
...
app/views/projects/blob/_image.html.haml
View file @
d3c0cfa5
.file-content.image_file
.file-content.image_file
-
if
blob
.
svg?
%img
{
src:
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
alt:
blob
.
name
}
-
if
blob
.
size_within_svg_limits?
-# We need to scrub SVG but we cannot do so in the RawController: it would
-# be wrong/strange if RawController modified the data.
-
blob
.
load_all_data!
(
@repository
)
-
blob
=
sanitize_svg
(
blob
)
%img
{
src:
"data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}"
,
alt:
"#{blob.name}"
}
-
else
.nothing-here-block
The SVG could not be displayed as it is too large, you can
#{
link_to
(
'view the raw file'
,
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
target:
'_blank'
,
rel:
'noopener noreferrer'
)
}
instead.
-
else
%img
{
src:
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
tree_join
(
@commit
.
id
,
blob
.
path
)),
alt:
"#{blob.name}"
}
app/views/projects/blob/_markup.html.haml
0 → 100644
View file @
d3c0cfa5
-
blob
.
load_all_data!
(
@repository
)
.file-content.wiki
=
render_markup
(
blob
.
name
,
blob
.
data
)
app/views/projects/blob/_svg.html.haml
0 → 100644
View file @
d3c0cfa5
-
if
blob
.
size_within_svg_limits?
-# We need to scrub SVG but we cannot do so in the RawController: it would
-# be wrong/strange if RawController modified the data.
-
blob
.
load_all_data!
(
@repository
)
-
blob
=
sanitize_svg
(
blob
)
.file-content.image_file
%img
{
src:
"data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}"
,
alt:
blob
.
name
}
-
else
=
render
'too_large'
app/views/projects/blob/_text.html.haml
View file @
d3c0cfa5
-
if
blob
.
only_display_raw?
-
blob
.
load_all_data!
(
@repository
)
.file-content.code
=
render
'shared/file_highlight'
,
blob:
blob
,
repository:
@repository
.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'
,
rel:
'noopener noreferrer'
-
else
-
blob
.
load_all_data!
(
@repository
)
-
if
blob
.
empty?
.file-content.code
.nothing-here-block
Empty file
-
else
-
if
markup?
(
blob
.
name
)
.file-content.wiki
=
render_markup
(
blob
.
name
,
blob
.
data
)
-
else
=
render
'shared/file_highlight'
,
blob:
blob
,
repository:
@repository
app/views/projects/blob/_too_large.html.haml
0 → 100644
View file @
d3c0cfa5
.file-content.code
.nothing-here-block
The file could not be displayed as it is too large, you can
#{
link_to
(
'view the raw file'
,
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
target:
'_blank'
,
rel:
'noopener noreferrer'
)
}
instead.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment