Class: Banzai::Filter::WikiLinkFilter::Rewriter

Inherits:
Object
  • Object
show all
Defined in:
lib/banzai/filter/wiki_link_filter/rewriter.rb

Instance Method Summary collapse

Constructor Details

#initialize(link_string, wiki:, slug:) ⇒ Rewriter

Returns a new instance of Rewriter.


7
8
9
10
11
# File 'lib/banzai/filter/wiki_link_filter/rewriter.rb', line 7

def initialize(link_string, wiki:, slug:)
  @uri = Addressable::URI.parse(link_string)
  @wiki_base_path = wiki && wiki.wiki_base_path
  @slug = slug
end

Instance Method Details

#apply_rulesObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/banzai/filter/wiki_link_filter/rewriter.rb', line 13

def apply_rules
  # Special case: relative URLs beginning with `/uploads/` refer to
  # user-uploaded files will be handled elsewhere.
  return @uri.to_s if public_upload?

  # Special case: relative URLs beginning with Wikis::CreateAttachmentService::ATTACHMENT_PATH
  # refer to user-uploaded files to the wiki repository.
  unless repository_upload?
    apply_file_link_rules!
    apply_hierarchical_link_rules!
  end

  apply_relative_link_rules!
  @uri.to_s
end