diff --git a/lib/docs/filters/core/internal_urls.rb b/lib/docs/filters/core/internal_urls.rb
index 54d27280..5db6285e 100644
--- a/lib/docs/filters/core/internal_urls.rb
+++ b/lib/docs/filters/core/internal_urls.rb
@@ -3,10 +3,10 @@ require 'set'
module Docs
class InternalUrlsFilter < Filter
def call
+ return doc if skip_links?
internal_urls = Set.new if follow_links?
css('a').each do |link|
- next if skip_link?(link)
next unless url = parse_href(link['href'])
next unless subpath = subpath_to(url)
@@ -24,12 +24,12 @@ module Docs
doc
end
- def follow_links?
- !(context[:follow_links] && context[:follow_links].call(self) == false)
+ def skip_links?
+ context[:skip_links] && context[:skip_links].call(self)
end
- def skip_link?(link)
- context[:skip_links] && context[:skip_links].call(link)
+ def follow_links?
+ !(context[:follow_links] && context[:follow_links].call(self) == false)
end
def parse_href(str)
diff --git a/lib/docs/scrapers/backbone.rb b/lib/docs/scrapers/backbone.rb
index 1f39ed9a..66e26eba 100644
--- a/lib/docs/scrapers/backbone.rb
+++ b/lib/docs/scrapers/backbone.rb
@@ -10,7 +10,7 @@ module Docs
options[:title] = 'Backbone.js'
options[:container] = '.container'
- options[:skip_links] = -> (_) { true }
+ options[:skip_links] = ->(filter) { true }
options[:attribution] = <<-HTML
© 2010–2013 Jeremy Ashkenas, DocumentCloud
diff --git a/lib/docs/scrapers/coffeescript.rb b/lib/docs/scrapers/coffeescript.rb
index 291446f1..dca7c448 100644
--- a/lib/docs/scrapers/coffeescript.rb
+++ b/lib/docs/scrapers/coffeescript.rb
@@ -9,7 +9,7 @@ module Docs
options[:title] = 'CoffeeScript'
options[:container] = '.container'
- options[:skip_links] = -> (_) { true }
+ options[:skip_links] = ->(filter) { true }
options[:attribution] = <<-HTML
© 2009–2013 Jeremy Ashkenas
diff --git a/lib/docs/scrapers/less.rb b/lib/docs/scrapers/less.rb
index 0bb54c4c..ec094c53 100644
--- a/lib/docs/scrapers/less.rb
+++ b/lib/docs/scrapers/less.rb
@@ -8,7 +8,7 @@ module Docs
options[:title] = 'LESS'
options[:container] = 'section'
- options[:skip_links] = -> (_) { true }
+ options[:skip_links] = ->(filter) { true }
options[:attribution] = <<-HTML
© 2009–2013 Alexis Sellier & The Core Less Team
diff --git a/lib/docs/scrapers/lodash.rb b/lib/docs/scrapers/lodash.rb
index e5b76d18..c0147790 100644
--- a/lib/docs/scrapers/lodash.rb
+++ b/lib/docs/scrapers/lodash.rb
@@ -10,7 +10,7 @@ module Docs
options[:title] = 'Lo-Dash'
options[:container] = 'h1+div+div'
- options[:skip_links] = -> (_) { true }
+ options[:skip_links] = ->(filter) { true }
options[:attribution] = <<-HTML
© 2012–2013 The Dojo Foundation
diff --git a/lib/docs/scrapers/underscore.rb b/lib/docs/scrapers/underscore.rb
index 0eb4d886..a5c6a19a 100644
--- a/lib/docs/scrapers/underscore.rb
+++ b/lib/docs/scrapers/underscore.rb
@@ -10,7 +10,7 @@ module Docs
options[:title] = 'Underscore.js'
options[:container] = '#documentation'
- options[:skip_links] = -> (_) { true }
+ options[:skip_links] = ->(filter) { true }
options[:attribution] = <<-HTML
© 2009–2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
diff --git a/test/lib/docs/filters/core/internal_urls_test.rb b/test/lib/docs/filters/core/internal_urls_test.rb
index 637306be..52c1a7d9 100644
--- a/test/lib/docs/filters/core/internal_urls_test.rb
+++ b/test/lib/docs/filters/core/internal_urls_test.rb
@@ -5,16 +5,15 @@ class InternalUrlsFilterTest < MiniTest::Spec
include FilterTestHelper
self.filter_class = Docs::InternalUrlsFilter
- describe ":internal_urls" do
- before do
- context[:base_url] = context[:root_url] = 'http://example.com/dir'
- context[:url] = 'http://example.com/dir'
- end
+ before do
+ context[:base_url] = context[:root_url] = context[:url] = 'http://example.com/dir'
+ end
- let :internal_urls do
- filter_result[:internal_urls]
- end
+ let :internal_urls do
+ filter_result[:internal_urls]
+ end
+ describe ":internal_urls" do
it "is an array" do
assert_instance_of Array, internal_urls
end
@@ -135,31 +134,6 @@ class InternalUrlsFilterTest < MiniTest::Spec
end
end
- context "when context[:skip_links] is a block" do
- let :block do
- context[:skip_links] = Proc.new {}
- end
-
- it "passes all links to the block" do
- @body = link_to 'http://example.com'
- context[:skip_links] = ->(arg) { @arg = arg }
- internal_urls
- assert_equal @body, @arg.to_s
- end
-
- it "doesn't include urls from links where the block returns true" do
- @body = link_to 'http://example.com/dir/path'
- context[:skip_links] = ->(_) { true }
- assert_empty internal_urls
- end
-
- it "includes urls from links where the block returns false" do
- @body = link_to 'http://example.com/dir/path'
- context[:skip_links] = ->(_) { false }
- assert_equal 1, internal_urls.length
- end
- end
-
context "when context[:follow_links] is a block" do
before do
@body = link_to context[:url]
@@ -305,4 +279,46 @@ class InternalUrlsFilterTest < MiniTest::Spec
end
end
end
+
+ context "context[:skip_links]" do
+ before do
+ @body = link_to context[:url]
+ end
+
+ context "when it is a block" do
+ it "calls the block with the filter instance" do
+ context[:skip_links] = ->(arg) { @arg = arg; nil }
+ filter.call
+ assert_equal filter, @arg
+ end
+
+ context "and the block returns true" do
+ before do
+ context[:skip_links] = ->(_) { true }
+ end
+
+ it "doesn't set :internal_urls" do
+ refute internal_urls
+ end
+
+ it "doesn't replace urls" do
+ assert_equal @body, filter_output_string
+ end
+ end
+
+ context "and the block returns false" do
+ before do
+ context[:skip_links] = ->(_) { false }
+ end
+
+ it "set :internal_urls" do
+ assert internal_urls
+ end
+
+ it "replaces urls" do
+ refute_equal @body, filter_output_string
+ end
+ end
+ end
+ end
end