浏览代码

Refactor FixRedirectionsBehavior

Thibaut Courouble 9 年之前
父节点
当前提交
b8658d9708
共有 4 个文件被更改,包括 13 次插入15 次删除
  1. 9 0
      lib/docs/core/scraper.rb
  2. 0 13
      lib/docs/core/scrapers/url_scraper.rb
  3. 2 1
      lib/docs/scrapers/mdn/dom.rb
  4. 2 1
      lib/docs/scrapers/mdn/svg.rb

+ 9 - 0
lib/docs/core/scraper.rb

@@ -154,6 +154,15 @@ module Docs
       Parser.new(string).html
     end
 
+    def with_filters(*filters)
+      stack = FilterStack.new
+      stack.push(*filters)
+      pipeline.instance_variable_set :@filters, stack.to_a.freeze
+      yield
+    ensure
+      @pipeline = nil
+    end
+
     module StubRootPage
       private
 

+ 0 - 13
lib/docs/core/scrapers/url_scraper.rb

@@ -42,11 +42,9 @@ module Docs
       end
 
       module ClassMethods
-        attr_accessor :fix_redirections
         attr_reader :redirections
 
         def store_pages(store)
-          return super unless fix_redirections
           instrument 'info.doc', msg: 'Fetching redirections...'
           with_redirections do
             instrument 'info.doc', msg: 'Building pages...'
@@ -84,17 +82,6 @@ module Docs
       def additional_options
         { redirections: self.class.redirections }
       end
-
-      def with_filters(*filters)
-        stack = FilterStack.new
-        stack.push(*filters)
-        pipeline.instance_variable_set :@filters, stack.to_a.freeze
-        yield
-      ensure
-        @pipeline = nil
-      end
     end
-
-    include FixRedirectionsBehavior
   end
 end

+ 2 - 1
lib/docs/scrapers/mdn/dom.rb

@@ -1,8 +1,9 @@
 module Docs
   class Dom < Mdn
+    include FixRedirectionsBehavior
+
     self.name = 'DOM'
     self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/API'
-    self.fix_redirections = true
 
     html_filters.push 'dom/clean_html', 'dom/entries', 'title'
 

+ 2 - 1
lib/docs/scrapers/mdn/svg.rb

@@ -1,8 +1,9 @@
 module Docs
   class Svg < Mdn
+    include FixRedirectionsBehavior
+
     self.name = 'SVG'
     self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/SVG'
-    self.fix_redirections = true
 
     html_filters.push 'svg/clean_html', 'svg/entries', 'title'