From 8ddb812035842100f01a137320d13f99645cfed5 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sat, 18 Feb 2017 10:33:02 -0500 Subject: [PATCH] Pass response object to Scraper#parse method --- lib/docs/core/scraper.rb | 6 +++--- lib/docs/scrapers/angular.rb | 18 +++++++++--------- lib/docs/scrapers/cakephp.rb | 4 ++-- lib/docs/scrapers/go.rb | 5 +++-- lib/docs/scrapers/sqlite.rb | 4 ++-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/docs/core/scraper.rb b/lib/docs/core/scraper.rb index bf2af017..00324b24 100644 --- a/lib/docs/core/scraper.rb +++ b/lib/docs/core/scraper.rb @@ -172,7 +172,7 @@ module Docs def process_response(response) data = {} - html, title = parse(response.body) + html, title = parse(response) context = pipeline_context(response) context[:html_title] = title pipeline.call(html, context, data) @@ -183,8 +183,8 @@ module Docs options.merge url: response.url end - def parse(string) - parser = Parser.new(string) + def parse(response) + parser = Parser.new(response.body) [parser.html, parser.title] end diff --git a/lib/docs/scrapers/angular.rb b/lib/docs/scrapers/angular.rb index a1766228..a4df8290 100644 --- a/lib/docs/scrapers/angular.rb +++ b/lib/docs/scrapers/angular.rb @@ -58,15 +58,15 @@ module Docs private - def parse(string) - string.gsub! '', 'live example' - string.gsub! '', 'live example' + response.body.gsub! '', '

' + def parse(response) + response.body.gsub! '

', '

' super end end diff --git a/lib/docs/scrapers/go.rb b/lib/docs/scrapers/go.rb index 1434411b..5b255747 100644 --- a/lib/docs/scrapers/go.rb +++ b/lib/docs/scrapers/go.rb @@ -21,8 +21,9 @@ module Docs private - def parse(html) # Hook here because Nokogori removes whitespace from textareas - super html.gsub %r{]*>([\W\w]+?)}, '
\1
' + def parse(response) # Hook here because Nokogori removes whitespace from textareas + response.body.gsub! %r{]*>([\W\w]+?)}, '
\1
' + super end end end diff --git a/lib/docs/scrapers/sqlite.rb b/lib/docs/scrapers/sqlite.rb index 9031548e..0eeeed27 100644 --- a/lib/docs/scrapers/sqlite.rb +++ b/lib/docs/scrapers/sqlite.rb @@ -44,8 +44,8 @@ module Docs private - def parse(html) - html.gsub! %r{(]*>[^<]+)

}, '\1' + def parse(response) + response.body.gsub! %r{(]*>[^<]+)}, '\1' super end end