Refactor FixRedirectionsBehavior

pull/343/merge
Thibaut Courouble 9 years ago
parent 9c53ba1d4e
commit b8658d9708

@ -154,6 +154,15 @@ module Docs
Parser.new(string).html Parser.new(string).html
end 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 module StubRootPage
private private

@ -42,11 +42,9 @@ module Docs
end end
module ClassMethods module ClassMethods
attr_accessor :fix_redirections
attr_reader :redirections attr_reader :redirections
def store_pages(store) def store_pages(store)
return super unless fix_redirections
instrument 'info.doc', msg: 'Fetching redirections...' instrument 'info.doc', msg: 'Fetching redirections...'
with_redirections do with_redirections do
instrument 'info.doc', msg: 'Building pages...' instrument 'info.doc', msg: 'Building pages...'
@ -84,17 +82,6 @@ module Docs
def additional_options def additional_options
{ redirections: self.class.redirections } { redirections: self.class.redirections }
end 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
end end
include FixRedirectionsBehavior
end
end end

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

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

Loading…
Cancel
Save