summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-10-15 18:34:55 +0100
committerNick Thomas <nick@gitlab.com>2018-10-16 12:53:30 +0100
commitc5bff77ea4a6170a3dc1966254feac0ca1836eaa (patch)
tree8f54c14718b7911f5524a4b569f206bfc73a5a49 /lib
parent0621ee38b501b2f2a1f7717aff249ebf1bcebbf8 (diff)
downloadgitlab-ce-c5bff77ea4a6170a3dc1966254feac0ca1836eaa.tar.gz
Remove a dependency on gitlab-gollum-libnick.thomas/gitlab-ce-44361-remove-gitlab-grit
Inlining this code allows us to remove a dependency on gitlab_grit in gitlab-ce. We can't stop maintaining gitlab_grit yet, since gitaly-ruby still depends on this gem, but it moves us a step closer.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/wiki.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb
index 563712c5d63..7fe56979d5c 100644
--- a/lib/gitlab/git/wiki.rb
+++ b/lib/gitlab/git/wiki.rb
@@ -11,16 +11,11 @@ module Gitlab
{ user_id: user_id, username: username, name: name, email: email, message: message }
end
end
- PageBlob = Struct.new(:name)
# GollumSlug inlines just enough knowledge from Gollum::Page to generate a
# slug, which is used when previewing pages that haven't been persisted
class GollumSlug
class << self
- def format_to_ext(format)
- format == :markdown ? 'md' : format.to_s
- end
-
def cname(name, char_white_sub = '-', char_other_sub = '-')
if name.respond_to?(:gsub)
name.gsub(/\s/, char_white_sub).gsub(/[<>+]/, char_other_sub)
@@ -29,18 +24,27 @@ module Gitlab
end
end
+ def format_to_ext(format)
+ format == :markdown ? "md" : format.to_s
+ end
+
+ def canonicalize_filename(filename)
+ ::File.basename(filename, ::File.extname(filename)).tr('-', ' ')
+ end
+
def generate(title, format)
- name = cname(title) + '.' + format_to_ext(format)
- blob = PageBlob.new(name)
+ ext = format_to_ext(format.to_sym)
+ name = cname(title) + '.' + ext
+ canonical_name = canonicalize_filename(name)
path =
- if blob.name.include?('/')
- blob.name.sub(%r{/[^/]+$}, '/')
+ if name.include?('/')
+ name.sub(%r{/[^/]+$}, '/')
else
''
end
- path + cname(name)
+ path + cname(canonical_name, '-', '-')
end
end
end