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
iv
gitlab-ce
Commits
29ea8d09
Commit
29ea8d09
authored
Jul 08, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplication, useless rescue, and avoid using ActionView
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
356b2d2b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
31 deletions
+27
-31
app/uploaders/uploader_helper.rb
app/uploaders/uploader_helper.rb
+16
-13
config/initializers/mime_types.rb
config/initializers/mime_types.rb
+2
-4
lib/banzai/filter/video_link_filter.rb
lib/banzai/filter/video_link_filter.rb
+9
-14
No files found.
app/uploaders/uploader_helper.rb
View file @
29ea8d09
# Extra methods for uploader
# Extra methods for uploader
module
UploaderHelper
module
UploaderHelper
IMAGE_EXT
=
%w(png jpg jpeg gif bmp tiff)
IMAGE_EXT
=
%w[png jpg jpeg gif bmp tiff]
VIDEO_EXT
=
%w(mov mp4 ogg webm flv)
# We recommend using the .mp4 format over .mov. Videos in .mov format can
# still be used but you really need to make sure they are served with the
# proper MIME type video/mp4 and not video/quicktime or your videos won’t play
# on IE ≥ 9.
# http://archive.sublimevideo.info/20150912/docs.sublimevideo.net/troubleshooting.html
VIDEO_EXT
=
%w[mp4 m4v mov webm ogv]
def
image?
def
image?
extension_match?
(
IMAGE_EXT
)
extension_match?
(
IMAGE_EXT
)
rescue
false
end
end
def
video?
def
video?
extension_match?
(
VIDEO_EXT
)
extension_match?
(
VIDEO_EXT
)
rescue
false
end
end
def
image_or_video?
def
image_or_video?
...
@@ -20,13 +21,15 @@ module UploaderHelper
...
@@ -20,13 +21,15 @@ module UploaderHelper
end
end
def
extension_match?
(
extensions
)
def
extension_match?
(
extensions
)
if
file
.
respond_to?
(
:extension
)
extension
=
extensions
.
include?
(
file
.
extension
.
downcase
)
if
file
.
respond_to?
(
:extension
)
else
file
.
extension
# Not all CarrierWave storages respond to :extension
else
ext
=
file
.
path
.
split
(
'.'
).
last
.
downcase
# Not all CarrierWave storages respond to :extension
extensions
.
include?
(
ext
)
File
.
extname
(
file
.
path
).
delete
(
'.'
)
end
end
extensions
.
include?
(
extension
.
downcase
)
end
end
def
file_storage?
def
file_storage?
...
...
config/initializers/mime_types.rb
View file @
29ea8d09
...
@@ -9,8 +9,6 @@ Mime::Type.register_alias "text/plain", :patch
...
@@ -9,8 +9,6 @@ Mime::Type.register_alias "text/plain", :patch
Mime
::
Type
.
register_alias
"text/html"
,
:markdown
Mime
::
Type
.
register_alias
"text/html"
,
:markdown
Mime
::
Type
.
register_alias
"text/html"
,
:md
Mime
::
Type
.
register_alias
"text/html"
,
:md
Mime
::
Type
.
register
"video/mp4"
,
:mp4
,
[],
[
:m4v
,
:mov
]
Mime
::
Type
.
register
"video/webm"
,
:webm
Mime
::
Type
.
register
"video/webm"
,
:webm
Mime
::
Type
.
register
"video/ogg"
,
:ogg
Mime
::
Type
.
register
"video/ogg"
,
:ogv
,
[],
[
:ogg
]
Mime
::
Type
.
register
"video/ogg"
,
:ogv
Mime
::
Type
.
register
"video/mp4"
,
:mp4
Mime
::
Type
.
register
"video/mp4"
,
:m4v
lib/banzai/filter/video_link_filter.rb
View file @
29ea8d09
...
@@ -7,13 +7,9 @@ module Banzai
...
@@ -7,13 +7,9 @@ module Banzai
include
ActionView
::
Helpers
::
TagHelper
include
ActionView
::
Helpers
::
TagHelper
include
ActionView
::
Context
include
ActionView
::
Context
EXTENSIONS
=
%w(.mov .mp4 .ogg .webm .flv)
def
call
def
call
doc
.
search
(
'img'
).
each
do
|
el
|
doc
.
search
(
'img'
).
each
do
|
el
|
if
video?
(
el
)
el
.
replace
(
video_tag
(
doc
,
el
))
if
video?
(
el
)
el
.
replace
video_node
(
el
)
end
end
end
doc
doc
...
@@ -22,19 +18,18 @@ module Banzai
...
@@ -22,19 +18,18 @@ module Banzai
private
private
def
video?
(
element
)
def
video?
(
element
)
EXTENSIONS
.
include?
File
.
extname
(
element
.
attribute
(
'src'
).
value
)
extension
=
File
.
extname
(
element
.
attribute
(
'src'
).
value
).
delete
(
'.'
)
UploaderHelper
::
VIDEO_EXT
.
include?
(
extension
)
end
end
# Return a video tag Nokogiri node
# Return a video tag Nokogiri node
#
#
def
video_node
(
element
)
def
video_node
(
doc
,
element
)
vtag
=
content_tag
(
:video
,
""
,
{
doc
.
document
.
create_element
(
src:
element
.
attribute
(
'src'
).
value
,
'video'
,
class:
'video-js'
,
preload:
'auto'
,
src:
element
.
attribute
(
'src'
).
value
,
controls:
true
class:
'video-js'
,
})
controls:
true
)
Nokogiri
::
HTML
::
DocumentFragment
.
parse
(
vtag
)
end
end
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