Unified · Split
| @@ -9,6 +9,7 @@ module Docs · 8 unmodified lines | ||
| 9 | 9 | |
| 10 | 10 | def update_links |
| 11 | 11 | css('a').each do |link| |
| 12 | + next if context[:skip_link].is_a?(Proc) && context[:skip_link].call(link) | |
| 12 | 13 | next unless url = to_internal_url(link['href']) |
| 13 | 14 | link['href'] = internal_path_to(url) |
| 14 | 15 | yield url if block_given? |
| @@ -366,4 +366,44 @@ class InternalUrlsFilterTest < MiniTest::Spec · 365 unmodified lines | ||
| 366 | 366 | end |
| 367 | 367 | end |
| 368 | 368 | end |
| 369 | + | |
| 370 | + context "context[:skip_link] is a block" do | |
| 371 | + before do | |
| 372 | + @body = link_to context[:url] | |
| 373 | + end | |
| 374 | + | |
| 375 | + it "calls the block with each link" do | |
| 376 | + context[:skip_link] = ->(arg) { @arg = arg.try(:to_html); nil } | |
| 377 | + filter.call | |
| 378 | + assert_equal @body, @arg | |
| 379 | + end | |
| 380 | + | |
| 381 | + context "and the block returns true" do | |
| 382 | + before do | |
| 383 | + context[:skip_link] = ->(_) { true } | |
| 384 | + end | |
| 385 | + | |
| 386 | + it "doesn't include the link's url in :internal_urls" do | |
| 387 | + assert internal_urls.empty? | |
| 388 | + end | |
| 389 | + | |
| 390 | + it "doesn't replace the link's url" do | |
| 391 | + assert_equal @body, filter_output_string | |
| 392 | + end | |
| 393 | + end | |
| 394 | + | |
| 395 | + context "and the block returns false" do | |
| 396 | + before do | |
| 397 | + context[:skip_link] = ->(_) { false } | |
| 398 | + end | |
| 399 | + | |
| 400 | + it "includes the link's url in :internal_urls" do | |
| 401 | + refute internal_urls.empty? | |
| 402 | + end | |
| 403 | + | |
| 404 | + it "replaces the link's url" do | |
| 405 | + refute_equal @body, filter_output_string | |
| 406 | + end | |
| 407 | + end | |
| 408 | + end | |
| 369 | 409 | end |