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
c69a0779
Commit
c69a0779
authored
Apr 21, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address feedback
parent
fed9dcd9
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
23 deletions
+29
-23
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+16
-0
app/models/blob.rb
app/models/blob.rb
+3
-5
app/models/blob_viewer/base.rb
app/models/blob_viewer/base.rb
+2
-2
app/models/blob_viewer/download.rb
app/models/blob_viewer/download.rb
+3
-2
app/views/projects/blob/_content.html.haml
app/views/projects/blob/_content.html.haml
+3
-3
app/views/projects/blob/_render_error.html.haml
app/views/projects/blob/_render_error.html.haml
+2
-11
No files found.
app/helpers/blob_helper.rb
View file @
c69a0779
...
...
@@ -224,4 +224,20 @@ module BlobHelper
"it is stored in LFS"
end
end
def
blob_render_error_options
(
viewer
,
error
)
options
=
[]
if
error
==
:too_large
&&
viewer
.
can_override_max_size?
options
<<
link_to
(
'load it anyway'
,
url_for
(
params
.
merge
(
viewer:
viewer
.
type
,
override_max_size:
true
,
format:
nil
)))
end
if
viewer
.
rich?
&&
viewer
.
blob
.
rendered_as_text?
(
override_max_size:
true
)
options
<<
link_to
(
'view the source'
,
'#'
,
class:
'js-blob-viewer-switcher'
,
data:
{
viewer:
'simple'
})
end
options
<<
link_to
(
'download it'
,
blob_raw_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
)
options
end
end
app/models/blob.rb
View file @
c69a0779
...
...
@@ -107,12 +107,10 @@ class Blob < SimpleDelegator
end
def
rich_viewer_class
if
invalid_lfs_pointer?
||
empty?
nil
else
return
if
invalid_lfs_pointer?
||
empty?
rich_viewers_classes
.
find
{
|
viewer_class
|
viewer_class
.
can_render?
(
self
)
}
end
end
def
simple_viewer
@simple_viewer
||=
simple_viewer_class
.
new
(
self
)
...
...
app/models/blob_viewer/base.rb
View file @
c69a0779
...
...
@@ -2,7 +2,7 @@ module BlobViewer
class
Base
class_attribute
:partial_name
,
:type
,
:extensions
,
:client_side
,
:text_based
,
:switcher_icon
,
:switcher_title
,
:max_size
,
:absolute_max_size
delegate
:partial_path
,
:rich?
,
:simple?
,
:client_side?
,
:text_based?
,
to: :class
delegate
:partial_path
,
:rich?
,
:simple?
,
:client_side?
,
:
server_side?
,
:
text_based?
,
to: :class
attr_reader
:blob
...
...
@@ -26,7 +26,7 @@ module BlobViewer
client_side
end
def
server_side?
def
se
lf
.
se
rver_side?
!
client_side?
end
...
...
app/models/blob_viewer/download.rb
View file @
c69a0779
module
BlobViewer
class
Download
<
Base
include
Simple
# We pretend the Download viewer is rendered client-side so that it doesn't
# attempt to load the entire blob contents.
# We treat the Download viewer as if it renders the content client-side,
# so that it doesn't attempt to load the entire blob contents and is
# rendered synchronously instead of loaded asynchronously.
include
ClientSide
self
.
partial_name
=
'download'
...
...
app/views/projects/blob/_content.html.haml
View file @
c69a0779
-
simple_viewer
=
blob
.
simple_viewer
-
rich_viewer
=
blob
.
rich_viewer
-
active_viewer
=
rich_viewer
&&
params
[
:viewer
]
!=
'simple'
?
:rich
:
:simple
-
rich_viewer_active
=
rich_viewer
&&
params
[
:viewer
]
!=
'simple'
=
render
'projects/blob/viewer_wrapper'
,
viewer:
simple_viewer
,
hidden:
(
active_viewer
!=
:simple
)
=
render
'projects/blob/viewer_wrapper'
,
viewer:
simple_viewer
,
hidden:
rich_viewer_active
-
if
rich_viewer
=
render
'projects/blob/viewer_wrapper'
,
viewer:
rich_viewer
,
hidden:
(
active_viewer
!=
:rich
)
=
render
'projects/blob/viewer_wrapper'
,
viewer:
rich_viewer
,
hidden:
!
rich_viewer_active
app/views/projects/blob/_render_error.html.haml
View file @
c69a0779
-
reason
=
blob_render_error_reason
(
viewer
,
error
)
-
options
=
[]
-
if
error
==
:too_large
&&
viewer
.
can_override_max_size?
-
options
<<
link_to
(
'load it anyway'
,
url_for
(
params
.
merge
(
viewer:
viewer
.
type
,
override_max_size:
true
,
format:
nil
)))
-
if
viewer
.
rich?
&&
viewer
.
blob
.
rendered_as_text?
(
override_max_size:
true
)
-
options
<<
link_to
(
'view the source'
,
'#'
,
class:
'js-blob-viewer-switcher'
,
data:
{
viewer:
'simple'
})
-
options
<<
link_to
(
'download it'
,
blob_raw_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
)
.file-content.code
.nothing-here-block
The
#{
viewer
.
switcher_title
}
could not be displayed because
#{
reason
}
.
The
#{
viewer
.
switcher_title
}
could not be displayed because
#{
blob_render_error_reason
(
viewer
,
error
)
}
.
You can
=
options
.
to_sentence
(
two_words_connector:
' or '
,
last_word_connector:
', or '
).
html_safe
=
blob_render_error_options
(
viewer
,
error
)
.
to_sentence
(
two_words_connector:
' or '
,
last_word_connector:
', or '
).
html_safe
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