-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94b6af7
commit 074f8a2
Showing
4 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ docs/ | |
_yardoc | ||
doc/ | ||
.DS_Store | ||
|
||
.htmlproofer.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,57 @@ | ||
require 'json' | ||
|
||
module HTML | ||
class Proofer | ||
module Cache | ||
def create_nokogiri(path) | ||
if File.exist? path | ||
content = File.open(path).read | ||
class Cache | ||
attr_reader :status | ||
|
||
FILENAME = '.htmlproofer.log' | ||
|
||
def initialize(now, options) | ||
@status = {} | ||
@now = now | ||
@status[:time] = @now | ||
@status[:urls] = [] | ||
|
||
if options.nil? || options.empty? | ||
@store = false | ||
else | ||
@store = true | ||
@timeframe = options[:timeframe] | ||
end | ||
|
||
if File.exist?(FILENAME) | ||
@exists = true | ||
@cache_log = JSON.parse(File.read(FILENAME)) | ||
else | ||
content = path | ||
@exists = false | ||
end | ||
end | ||
|
||
def store? | ||
@store | ||
end | ||
|
||
def exists? | ||
@exists && within_timeframe | ||
end | ||
|
||
def within_timeframe | ||
|
||
end | ||
|
||
def load | ||
|
||
end | ||
|
||
def add(url, status) | ||
return unless store? | ||
@status[:urls] << { :url => url, :status => status } | ||
end | ||
|
||
Nokogiri::HTML(content) | ||
def write | ||
File.write(FILENAME, @status.to_json) | ||
end | ||
module_function :create_nokogiri | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Cache test' do | ||
it 'ignores an invalid tag by default' do | ||
brokenLinkExternalFilepath = "#{FIXTURES_DIR}/links/brokenLinkExternal.html" | ||
proofer = run_proofer(brokenLinkExternalFilepath) | ||
expect(proofer.failed_tests.first).to match(/failed: 0/) | ||
|
||
run_proofer(brokenLinkExternalFilepath, { :cache => { :timeframe => '30d' } }) | ||
end | ||
|
||
|
||
end |
074f8a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typhoeus includes built in support for caching. It’s documented in the readme. Could we use this interface?
074f8a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome suggestion. Thanks!