Pass response object to Scraper#parse method

pull/570/merge
Thibaut Courouble 8 years ago
parent 5bee5c652a
commit 8ddb812035

@ -172,7 +172,7 @@ module Docs
def process_response(response) def process_response(response)
data = {} data = {}
html, title = parse(response.body) html, title = parse(response)
context = pipeline_context(response) context = pipeline_context(response)
context[:html_title] = title context[:html_title] = title
pipeline.call(html, context, data) pipeline.call(html, context, data)
@ -183,8 +183,8 @@ module Docs
options.merge url: response.url options.merge url: response.url
end end
def parse(string) def parse(response)
parser = Parser.new(string) parser = Parser.new(response.body)
[parser.html, parser.title] [parser.html, parser.title]
end end

@ -58,15 +58,15 @@ module Docs
private private
def parse(string) def parse(response)
string.gsub! '<code-example', '<pre' response.body.gsub! '<code-example', '<pre'
string.gsub! '</code-example', '</pre' response.body.gsub! '</code-example', '</pre'
string.gsub! '<code-pane', '<pre' response.body.gsub! '<code-pane', '<pre'
string.gsub! '</code-pane', '</pre' response.body.gsub! '</code-pane', '</pre'
string.gsub! '<live-example></live-example>', 'live example' response.body.gsub! '<live-example></live-example>', 'live example'
string.gsub! '<live-example', '<span' response.body.gsub! '<live-example', '<span'
string.gsub! '</live-example', '</span' response.body.gsub! '</live-example', '</span'
super string super
end end
end end
end end

@ -59,8 +59,8 @@ module Docs
private private
def parse(string) def parse(response)
string.gsub! '<h5 class="method-name">', '<h3 class="method-name">' response.body.gsub! '<h5 class="method-name">', '<h3 class="method-name">'
super super
end end
end end

@ -21,8 +21,9 @@ module Docs
private private
def parse(html) # Hook here because Nokogori removes whitespace from textareas def parse(response) # Hook here because Nokogori removes whitespace from textareas
super html.gsub %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>' response.body.gsub! %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>'
super
end end
end end
end end

@ -44,8 +44,8 @@ module Docs
private private
def parse(html) def parse(response)
html.gsub! %r{(<h2[^>]*>[^<]+)</h1>}, '\1</h2>' response.body.gsub! %r{(<h2[^>]*>[^<]+)</h1>}, '\1</h2>'
super super
end end
end end

Loading…
Cancel
Save