diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-09-04 13:39:08 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-09-04 13:39:08 +0300 |
commit | f9475e299c6f6b363d5ea302f1295a3ea0bf9adb (patch) | |
tree | cec2910cfe3c0065a88e884a60a588c548c0cae9 /lib/gitlab/file_markdown_link_builder.rb | |
parent | 0689900c7a5ce368c780f1fce8f465685bbfa9d6 (diff) |
Uploads to wiki stored inside the wiki git repository
Diffstat (limited to 'lib/gitlab/file_markdown_link_builder.rb')
-rw-r--r-- | lib/gitlab/file_markdown_link_builder.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/gitlab/file_markdown_link_builder.rb b/lib/gitlab/file_markdown_link_builder.rb new file mode 100644 index 00000000000..5386656efe7 --- /dev/null +++ b/lib/gitlab/file_markdown_link_builder.rb @@ -0,0 +1,21 @@ +# Builds the markdown link of a file +# It needs the methods filename and secure_url (final destination url) to be defined. +module Gitlab + module FileMarkdownLinkBuilder + include FileTypeDetection + + def markdown_link + return unless name = markdown_name + + markdown = "[#{name.gsub(']', '\\]')}](#{secure_url})" + markdown.prepend("!") if image_or_video? || dangerous? + markdown + end + + def markdown_name + return unless filename.present? + + image_or_video? ? File.basename(filename, File.extname(filename)) : filename + end + end +end |