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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
a2f4650f
Commit
a2f4650f
authored
Apr 24, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BlobViewer::Base#binary? method
parent
ec19703a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
22 deletions
+30
-22
app/models/blob.rb
app/models/blob.rb
+24
-20
app/models/blob_viewer/base.rb
app/models/blob_viewer/base.rb
+6
-2
No files found.
app/models/blob.rb
View file @
a2f4650f
...
...
@@ -70,7 +70,11 @@ class Blob < SimpleDelegator
def
raw_binary?
if
valid_lfs_pointer?
!
rich_viewer
&
.
text_based?
if
rich_viewer
rich_viewer
.
binary?
else
true
end
else
binary?
end
...
...
@@ -96,22 +100,6 @@ class Blob < SimpleDelegator
lfs_pointer?
&&
!
project
.
lfs_enabled?
end
def
simple_viewer_class
if
empty?
BlobViewer
::
Empty
elsif
raw_binary?
BlobViewer
::
Download
else
# text
BlobViewer
::
Text
end
end
def
rich_viewer_class
return
if
invalid_lfs_pointer?
||
empty?
rich_viewers_classes
.
find
{
|
viewer_class
|
viewer_class
.
can_render?
(
self
)
}
end
def
simple_viewer
@simple_viewer
||=
simple_viewer_class
.
new
(
self
)
end
...
...
@@ -123,7 +111,7 @@ class Blob < SimpleDelegator
end
def
rendered_as_text?
(
ignore_errors:
true
)
simple_viewer
.
is_a?
(
BlobViewer
::
Text
)
&&
(
ignore_errors
||
simple_viewer
.
render_error
.
nil?
)
simple_viewer
.
text?
&&
(
ignore_errors
||
simple_viewer
.
render_error
.
nil?
)
end
def
show_viewer_switcher?
...
...
@@ -137,13 +125,29 @@ class Blob < SimpleDelegator
private
def
simple_viewer_class
if
empty?
BlobViewer
::
Empty
elsif
raw_binary?
BlobViewer
::
Download
else
# text
BlobViewer
::
Text
end
end
def
rich_viewers_classes
if
valid_lfs_pointer?
RICH_VIEWERS
elsif
binary?
RICH_VIEWERS
.
reject
(
&
:text_based
?
)
RICH_VIEWERS
.
select
(
&
:binary
?
)
else
# text
RICH_VIEWERS
.
select
(
&
:text
_based
?
)
RICH_VIEWERS
.
select
(
&
:text?
)
end
end
def
rich_viewer_class
return
if
invalid_lfs_pointer?
||
empty?
rich_viewers_classes
.
find
{
|
viewer_class
|
viewer_class
.
can_render?
(
self
)
}
end
end
app/models/blob_viewer/base.rb
View file @
a2f4650f
...
...
@@ -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?
,
:server_side?
,
:text
_based
?
,
to: :class
delegate
:partial_path
,
:rich?
,
:simple?
,
:client_side?
,
:server_side?
,
:text
?
,
:binary
?
,
to: :class
attr_reader
:blob
attr_accessor
:override_max_size
...
...
@@ -31,10 +31,14 @@ module BlobViewer
!
client_side?
end
def
self
.
text
_based
?
def
self
.
text?
text_based
end
def
self
.
binary?
!
text?
end
def
self
.
can_render?
(
blob
)
!
extensions
||
extensions
.
include?
(
blob
.
extension
)
end
...
...
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