Class: Gollum::Export::LinkFilter
- Inherits:
-
Object
- Object
- Gollum::Export::LinkFilter
- Defined in:
- lib/gollum/export/link_filter.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source, repository) ⇒ LinkFilter
constructor
A new instance of LinkFilter.
- #page_name_to_path(page_name) ⇒ Object
Constructor Details
#initialize(source, repository) ⇒ LinkFilter
Returns a new instance of LinkFilter.
4 5 6 7 |
# File 'lib/gollum/export/link_filter.rb', line 4 def initialize(source, repository) @source = source @repository = repository end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gollum/export/link_filter.rb', line 9 def call @result = @source.gsub(/\[\[.*\]\]/) do |page_name| page_name.gsub!(/[\[\]]/, '') link = page_name_to_path(page_name) "<a href=\"#{link}\">#{page_name}</a>" end if @repository @result.gsub!(/"(https:\/\/github.com\/#{@repository}\/wiki\/)(.*)"/) do |explicit_link| url, path = $1, $2 next explicit_link if path =~ /^_pages/ explicit_link.gsub!(url, '') explicit_link.gsub!(path, page_name_to_path(path)) end end @result end |
#page_name_to_path(page_name) ⇒ Object
30 31 32 |
# File 'lib/gollum/export/link_filter.rb', line 30 def page_name_to_path(page_name) "#{page_name.downcase.gsub(/\s/,'-').gsub(':', '%3A')}.html" end |