Move code in scraper.rb

pull/15/head
Thibaut 11 years ago
parent d964fd4ca9
commit 5c4775201b

@ -35,22 +35,6 @@ module Docs
html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths' html_filters.push 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths'
text_filters.push 'inner_html', 'clean_text', 'attribution' text_filters.push 'inner_html', 'clean_text', 'attribution'
def base_url
@base_url ||= URL.parse self.class.base_url
end
def root_url
@root_url ||= root_path? ? URL.parse(File.join(base_url.to_s, root_path)) : base_url.normalize
end
def root_path
self.class.root_path
end
def root_path?
root_path.present? && root_path != '/'
end
def build_page(path) def build_page(path)
response = request_one url_for(path) response = request_one url_for(path)
result = handle_response(response) result = handle_response(response)
@ -72,15 +56,20 @@ module Docs
end end
end end
def options def base_url
@options ||= self.class.options.deep_dup.tap do |options| @base_url ||= URL.parse self.class.base_url
options.merge! base_url: base_url, root_path: root_path, root_url: root_url
(options[:skip] ||= []).concat ['', '/'] if root_path?
if options[:only] || options[:only_patterns]
(options[:only] ||= []).concat root_path? ? [root_path] : ['', '/']
end end
options.freeze
def root_url
@root_url ||= root_path? ? URL.parse(File.join(base_url.to_s, root_path)) : base_url.normalize
end
def root_path
self.class.root_path
end end
def root_path?
root_path.present? && root_path != '/'
end end
def pipeline def pipeline
@ -89,6 +78,22 @@ module Docs
end end
end end
def options
@options ||= self.class.options.deep_dup.tap do |options|
options.merge! base_url: base_url, root_url: root_url, root_path: root_path
if root_path?
(options[:skip] ||= []).concat ['', '/']
end
if options[:only] || options[:only_patterns]
(options[:only] ||= []).concat root_path? ? [root_path] : ['', '/']
end
options.freeze
end
end
private private
def request_one(url) def request_one(url)

Loading…
Cancel
Save