Module: Gollum::Helpers

Included in:
Filter, Markup
Defined in:
lib/gollum-lib/helpers.rb

Instance Method Summary collapse

Instance Method Details

Take a link path and turn it into a string for display as link text. For example: ‘/opt/local/bin/ruby.ext’ -> ‘ruby’



17
18
19
20
# File 'lib/gollum-lib/helpers.rb', line 17

def path_to_link_text(str)
  return nil unless str
  ::File.basename(str, Page.valid_extension?(str) ? ::File.extname(str) : '')
end

#trim_leading_slashes(url) ⇒ Object

If url starts with a leading slash, trim down its number of leading slashes to 1. Else, return url unchanged.



7
8
9
10
11
12
# File 'lib/gollum-lib/helpers.rb', line 7

def trim_leading_slashes(url)
  return nil if url.nil?
  url.gsub!('%2F', '/')
  return '/' + url.gsub(/^\/+/, '') if url[0, 1] == '/'
  url
end