diff options
author | Nick Thomas <nick@gitlab.com> | 2018-10-15 20:00:59 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-10-16 14:53:30 +0300 |
commit | c7be9f5cacadf196754159515a20d4ec31cff5f1 (patch) | |
tree | 1be69619aa281818b48bd48f895f9a86d9b8b24f /lib | |
parent | 27e9ed7a4ce2b1d97b7b8093ecde02f7c591349b (diff) |
Remove a dependency on gitlab-gollum-lib
Removing this dependency also allows us to remove a transitive
dependency on gitlab_grit - which is the whole point of this exercise.
I don't think we can EOL gitlab_grit until it's removed as a dependency
from gitaly-ruby, but this at least gets it out of gitlab-ce.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/wiki.rb | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index 072019dfb0a..563712c5d63 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -1,8 +1,3 @@ -# We only need Gollum::Page so let's not load all of gollum-lib. -require 'gollum-lib/pagination' -require 'gollum-lib/wiki' -require 'gollum-lib/page' - module Gitlab module Git class Wiki @@ -18,6 +13,38 @@ module Gitlab 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) + else + '' + end + end + + def generate(title, format) + name = cname(title) + '.' + format_to_ext(format) + blob = PageBlob.new(name) + + path = + if blob.name.include?('/') + blob.name.sub(%r{/[^/]+$}, '/') + else + '' + end + + path + cname(name) + end + end + end + attr_reader :repository def self.default_ref @@ -90,15 +117,7 @@ module Gitlab end def preview_slug(title, format) - # Adapted from gollum gem (Gollum::Wiki#preview_page) to avoid - # using Rugged through a Gollum::Wiki instance - page_class = Gollum::Page - page = page_class.new(nil) - ext = page_class.format_to_ext(format.to_sym) - name = page_class.cname(title) + '.' + ext - blob = PageBlob.new(name) - page.populate(blob) - page.url_path + GollumSlug.generate(title, format) end def page_formatted_data(title:, dir: nil, version: nil) |