Skip to content

Commit

Permalink
Merge pull request #23 from gjtorikian/relative-images-matter
Browse files Browse the repository at this point in the history
Relative images matter
  • Loading branch information
gjtorikian committed Dec 25, 2013
2 parents d914aaf + f7b36a1 commit 001aa3a
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
html-proofer (0.2.3)
html-proofer (0.3.0)
colored (~> 1.2)
mercenary (~> 0.2.0)
nokogiri (~> 1.6.0)
Expand Down
1 change: 1 addition & 0 deletions lib/html/proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def run

def self.create_nokogiri(path)
path << "/index.html" if File.directory? path # support for Jekyll-style links
content = File.open(path, "rb") {|f| f.read }
Nokogiri::HTML(File.read(path))
end

Expand Down
8 changes: 5 additions & 3 deletions lib/html/proofer/checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ def internal?
def file_path
return if path.nil?

if path =~ /^\// #path relative to root
if path =~ /^\// # path relative to root
base = @check.src
elsif File.exist? File.expand_path path, @check.src #relative links, path is a file
elsif File.exist?(File.expand_path path, @check.src) # relative links, path is a file
base = File.dirname @check.path
else #relative link, path is a directory
elsif File.exist?(File.join(File.dirname(@check.path), path)) # relative links in nested dir, path is a file
base = File.dirname @check.path
else # relative link, path is a directory
base = @check.path
end

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions spec/html/proofer/fixtures/folder/relativeImage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<ing alt="sure thing" src="assets/barrel.png">Folder relative to self</a>
3 changes: 3 additions & 0 deletions spec/html/proofer/fixtures/relativeLinks.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
<a href="index.html">Relative to self</a>
<a href="folder/">Folder relative to self</a>
<a href="index.html#anchor">Anchor relative to self</a>

<img alt="sure thing" src="/gpl.png"/>Relative to root
<img alt="sure thing" src="gpl.png"/>Relative to self
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
238 changes: 238 additions & 0 deletions spec/html/proofer/fixtures/resources/books/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Git Resources • GitHub Training</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/style.css">
<link rel="icon" type="image/x-icon" href="/favicon.png" />
<link rel="alternate" type="application/atom+xml" title="Upcoming Events" href="/atom.xml">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/quotes.js"></script>
<script type="text/javascript" src="/js/all.js"></script>
</head>

<body class="resources">
<div class="page">
<div class="top-bar">&nbsp;</div>
<header>
<div class="container">
<h1 id="logo" class="content">
<a href="/" data-escp="">GitHub Training</a>
</h1>
<nav id="nav">
<ul class="content">
<li>
<a href="/">Overview</a>
</li>
<li>
<a href="/trainers/">Your Trainers</a>
</li>
<li>
<a href="/web/">Web-based</a>
</li>
<li>
<a href="/in-person/">In-person</a>
</li>
<li class="current">
<a href="/resources/">Resources</a>
</li>
<li>
<a href="/contact/">Contact</a>
</li>
</ul>
</nav>
</div>
</header>

<section class="hero pagehead">
<div class="container">
<div class="content">
<h2>Git Resources</h2>
<p>A collection of the highest quality Git resources.</p>
</div>
</div>
</section>

<section class="main">
<div class="container">
<div class="subpage-list">
<ul>
<li>
<a href="/resources/videos/">Videos</a>
</li>
<li>
<a href="/resources/presentations/">Presentations</a>
</li>
<li class="current">
<a href="/resources/books/">Books</a>
</li>
<li>
<a href="/resources/repositories/">GitHub Repositories</a>
</li>
<li>
<a href="/resources/other/">More Resources</a>
</li>
</ul>
</div>

<div class="container">
<div class="three-quarters">
<div class="container">
<div class="content">
<div class="section-description">
<h3>Git Books</h3>
<p>There are a number of excellent books written about Git that are available online. Here’s a list of some of the most popular ones.</p>
</div>
<ul class="resource-list book-list">

<li class="resource book">
<div class="container">
<div class="fifth">
<a href="http://git-scm.com/book">
<img src="assets/pro-git.jpg" alt="Pro Git">
</a>
</div>
<div class="four-fifths">
<h4><a href="http://git-scm.com/book">Pro Git</a></h4>
<p class="body"><p>The entire Pro Git book, written by Scott Chacon and published by Apress, is available online for free. All content is licensed under the <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution Non Commercial Share Alike 3.0 license</a>. Print versions of the book are also available on <a href="http://www.amazon.com/gp/product/1430218339?ie=UTF8&amp;tag=prgi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1430218339">Amazon.com</a>.</p>
</p>
</div>
</div>
</li>


<li class="resource book">
<div class="container">
<div class="fifth">
<a href="http://net.tutsplus.com/freebies/books/getting-good-with-git-free-ebook/">
<img src="assets/getting-good-with-git.jpg" alt="Getting Good with Git">
</a>
</div>
<div class="four-fifths">
<h4><a href="http://net.tutsplus.com/freebies/books/getting-good-with-git-free-ebook/">Getting Good with Git</a></h4>
<p class="body"><p>In this book, Andrew Burgess will take you from knowing nothing about source code management to being able to use Git proficiently.</p>
</p>
</div>
</div>
</li>


<li class="resource book">
<div class="container">
<div class="fifth">
<a href="http://bit.ly/ogitbook">
<img src="assets/version-control-with-git.jpg" alt="Version Control with Git, 2nd Edition">
</a>
</div>
<div class="four-fifths">
<h4><a href="http://bit.ly/ogitbook">Version Control with Git, 2nd Edition</a></h4>
<p class="body"><p>Get up to speed on Git for tracking, branching, merging, and managing code revisions. Through a series of step-by-step tutorials, this practical guide takes you quickly from Git fundamentals to advanced techniques, and provides friendly yet rigorous advice for navigating the many functions of this open source version control system.</p>
</p>
</div>
</div>
</li>


</ul>
</div>
</div>

</div>
<div class="quarter">
<div class="content">
<div class="help-box">
<h4>GitHub Help</h4>
<p>GitHub’s <a href="http://help.github.com" target=_blank>help website</a> is an excellent resource to keep bookmarked. It covers a range of Git topics from basic setup, all the way through to advanced topics.</p>
</div>
</div>
</div>
</div>

<div class="container page-bottom">
<div class="golden-small">
<div class="content">

<h3>Get in touch, today!</h3>
<p>We love hearing from people, so if you have any questions about GitHub’s training products and services, get in touch right away.</p>
<p class="more"><a href="/contact/" class="">Contact our training team »</a></p>

</div>
</div>
<div class="golden-large">
<div class="content">
<div class="testimonial">
<p class="byline">Here’s what people are saying about GitHub’s training…</p>
<div class="quote">
<p id="js-quote-text"></p>
<div class="pointer-border"></div>
<div class="pointer"></div>
</div>
<div class="author">
<h3 id="js-quote-author"></h3>
<p id="js-quote-company"></p>
</div>
</div>
</div>
</div>
</div>

</div>
</section>

<div class="push"></div>
</div>
<footer>
<div class="container">
<div class="content">
<div id="footerlogo">
<a href="https://github.com/" data-escp="">GitHub</a>
</div>
<p>
<a href="https://help.github.com/articles/github-terms-of-service">Terms of Service</a>
<a href="https://help.github.com/articles/github-privacy-policy">Privacy</a>
<a href="https://help.github.com/articles/github-security">Security</a>
<br />
© 2013 GitHub Inc. All rights reserved.
</p>
</div>
</div>
</footer>


<!-- Gauges (http://gaug.es/) -->
<script type="text/javascript">
var _gauges = _gauges || [];
(function() {
var t = document.createElement('script');
t.type = 'text/javascript';
t.async = true;
t.id = 'gauges-tracker';
t.setAttribute('data-site-id', '50235916613f5d4f9c000042');
t.src = '//secure.gaug.es/track.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(t, s);
})();
</script>



<!-- Google Analytics (http://google.com/analytics) -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3769691-19']);
_gaq.push(['_setDomainName', '']); // Multiple sub-domains
_gaq.push(['_setAllowLinker', true]); // Multiple TLDs
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>


</body>
</html>
18 changes: 15 additions & 3 deletions spec/html/proofer/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,20 @@

it 'ignores images marked as ignore data-proofer-ignore' do
ignorableImages = "#{FIXTURES_DIR}/ignorableImages.html"
@linkCheck = Links.new("#{FIXTURES_DIR}", ignorableImages, HTML::Proofer.create_nokogiri(ignorableImages))
@linkCheck.run
@linkCheck.issues[0].should eq(nil)
@imageCheck = Images.new("#{FIXTURES_DIR}", ignorableImages, HTML::Proofer.create_nokogiri(ignorableImages))
@imageCheck.run
@imageCheck.issues[0].should eq(nil)
end

it 'properly checks relative links' do
relativeLinks = "#{FIXTURES_DIR}/relativeLinks.html"
@imageCheck = Images.new("#{FIXTURES_DIR}", relativeLinks, HTML::Proofer.create_nokogiri(relativeLinks))
@imageCheck.run
@imageCheck.issues[0].should eq(nil)

relativeLinks = "#{FIXTURES_DIR}/resources/books/index.html"
@imageCheck = Images.new("#{FIXTURES_DIR}", relativeLinks, HTML::Proofer.create_nokogiri(relativeLinks))
@imageCheck.run
@imageCheck.issues[0].should eq(nil)
end
end

0 comments on commit 001aa3a

Please sign in to comment.