Class: Gitlab::Git::Wiki::GollumSlug

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/wiki.rb

Overview

GollumSlug inlines just enough knowledge from Gollum::Page to generate a slug, which is used when previewing pages that haven't been persisted

Class Method Summary collapse

Class Method Details

.canonicalize_filename(filename) ⇒ Object


34
35
36
# File 'lib/gitlab/git/wiki.rb', line 34

def canonicalize_filename(filename)
  ::File.basename(filename, ::File.extname(filename)).tr('-', ' ')
end

.cname(name, char_white_sub = '-', char_other_sub = '-') ⇒ Object


22
23
24
25
26
27
28
# File 'lib/gitlab/git/wiki.rb', line 22

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

.format_to_ext(format) ⇒ Object


30
31
32
# File 'lib/gitlab/git/wiki.rb', line 30

def format_to_ext(format)
  format == :markdown ? "md" : format.to_s
end

.generate(title, format) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitlab/git/wiki.rb', line 38

def generate(title, format)
  ext = format_to_ext(format.to_sym)
  name = cname(title) + '.' + ext
  canonical_name = canonicalize_filename(name)

  path =
    if name.include?('/')
      name.sub(%r{/[^/]+$}, '/')
    else
      ''
    end

  path + cname(canonical_name, '-', '-')
end