Add :fix_urls_before_parse option for Angular doc

pull/382/head
Thibaut Courouble 9 years ago
parent 122089a4d5
commit 6c9fc464c2

@ -20,6 +20,7 @@ module Docs
def normalize_url(str)
str.strip!
str.gsub!(' ', '%20')
str = context[:fix_urls_before_parse].call(str) if context[:fix_urls_before_parse]
url = to_absolute_url(str)
while new_url = fix_url(url)

@ -115,6 +115,24 @@ class NormalizeUrlsFilterTest < MiniTest::Spec
end
end
context "when context[:fix_urls_before_parse] is a block" do
before do
@body = link_to 'foo[bar]'
end
it "calls the block with each absolute url" do
context[:fix_urls_before_parse] = ->(arg) { (@args ||= []).push(arg); nil }
@body += link_to 'foo[bar]'
filter.call
assert_equal ['foo[bar]'] * 2, @args
end
it "replaces the url with the block's return value" do
context[:fix_urls_before_parse] = ->(url) { '/fixed' }
assert_equal link_to('http://example.com/fixed'), filter_output_string
end
end
context "when context[:fix_urls] is a block" do
before do
@body = link_to 'http://example.com/path?#'

Loading…
Cancel
Save