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
Boxiang Sun
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
...
@@ -70,7 +70,11 @@ class Blob < SimpleDelegator
def
raw_binary?
def
raw_binary?
if
valid_lfs_pointer?
if
valid_lfs_pointer?
!
rich_viewer
&
.
text_based?
if
rich_viewer
rich_viewer
.
binary?
else
true
end
else
else
binary?
binary?
end
end
...
@@ -96,22 +100,6 @@ class Blob < SimpleDelegator
...
@@ -96,22 +100,6 @@ class Blob < SimpleDelegator
lfs_pointer?
&&
!
project
.
lfs_enabled?
lfs_pointer?
&&
!
project
.
lfs_enabled?
end
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
def
simple_viewer
@simple_viewer
||=
simple_viewer_class
.
new
(
self
)
@simple_viewer
||=
simple_viewer_class
.
new
(
self
)
end
end
...
@@ -123,7 +111,7 @@ class Blob < SimpleDelegator
...
@@ -123,7 +111,7 @@ class Blob < SimpleDelegator
end
end
def
rendered_as_text?
(
ignore_errors:
true
)
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
end
def
show_viewer_switcher?
def
show_viewer_switcher?
...
@@ -137,13 +125,29 @@ class Blob < SimpleDelegator
...
@@ -137,13 +125,29 @@ class Blob < SimpleDelegator
private
private
def
simple_viewer_class
if
empty?
BlobViewer
::
Empty
elsif
raw_binary?
BlobViewer
::
Download
else
# text
BlobViewer
::
Text
end
end
def
rich_viewers_classes
def
rich_viewers_classes
if
valid_lfs_pointer?
if
valid_lfs_pointer?
RICH_VIEWERS
RICH_VIEWERS
elsif
binary?
elsif
binary?
RICH_VIEWERS
.
reject
(
&
:text_based
?
)
RICH_VIEWERS
.
select
(
&
:binary
?
)
else
# text
else
# text
RICH_VIEWERS
.
select
(
&
:text
_based
?
)
RICH_VIEWERS
.
select
(
&
:text?
)
end
end
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
end
app/models/blob_viewer/base.rb
View file @
a2f4650f
...
@@ -2,7 +2,7 @@ module BlobViewer
...
@@ -2,7 +2,7 @@ module BlobViewer
class
Base
class
Base
class_attribute
:partial_name
,
:type
,
:extensions
,
:client_side
,
:text_based
,
:switcher_icon
,
:switcher_title
,
:max_size
,
:absolute_max_size
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_reader
:blob
attr_accessor
:override_max_size
attr_accessor
:override_max_size
...
@@ -31,10 +31,14 @@ module BlobViewer
...
@@ -31,10 +31,14 @@ module BlobViewer
!
client_side?
!
client_side?
end
end
def
self
.
text
_based
?
def
self
.
text?
text_based
text_based
end
end
def
self
.
binary?
!
text?
end
def
self
.
can_render?
(
blob
)
def
self
.
can_render?
(
blob
)
!
extensions
||
extensions
.
include?
(
blob
.
extension
)
!
extensions
||
extensions
.
include?
(
blob
.
extension
)
end
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