Permalink
Browse files

Fixed path bug when saving assets

  • Loading branch information...
1 parent 1eeb9da commit 62aca2505d2080f66c4db7ff63c519fbe7abeb80 @viking committed Nov 10, 2009
Showing with 9 additions and 6 deletions.
  1. +3 −5 lib/butternut/formatter.rb
  2. +2 −1 spec/butternut/formatter_spec.rb
  3. +3 −0 spec/fixtures/css/bar.css
  4. +1 −0 spec/fixtures/foo.html
@@ -416,9 +416,6 @@ def underscore(camel_cased_word)
def transform_page_source(page_source, page_url)
page_uri = URI.parse(page_url)
page_uri.query = nil
- page_uri.path = File.dirname(page_uri.path)
- page_url = page_uri.to_s
-
collected_files = []
doc = Nokogiri.HTML(page_source)
@@ -437,9 +434,10 @@ def transform_page_source(page_source, page_url)
local_file = File.join(@source_output_dir, basename)
remote_file = case elt_url
when %r{^\w+://} then elt_url
+ when %r{^/} then
+ "#{page_uri.scheme}://#{page_uri.host}:#{page_uri.port}#{elt_url}"
else
- elt_url.sub!(/^\//, "")
- page_url + "/" + elt_url
+ page_url.to_s + "/" + elt_url
end
File.open(local_file, "w") { |f| f.write open(remote_file).read }
collected_files << elt_url
@@ -265,7 +265,8 @@ def most_recent_html_file(dir)
it "saves images and stylesheets and rewrites urls in page source" do
@page_doc.at('img')['src'].should == "picard.jpg"
- @page_doc.at('link[rel="stylesheet"]')['href'].should == "foo.css"
+ @page_doc.at('link:first[rel="stylesheet"]')['href'].should == "foo.css"
+ @page_doc.at('link:last[rel="stylesheet"]')['href'].should == "bar.css"
end
it "turns off links" do
@@ -0,0 +1,3 @@
+h1 {
+ font-size: 2em;
+}
View
@@ -2,6 +2,7 @@
<head>
<title>Foo</title>
<link rel="stylesheet" href="foo.css" type="text/css"/>
+ <link rel="stylesheet" href="/css/bar.css" type="text/css"/>
<script type="text/javascript" src="foo.js"></script>
</head>
<body>

0 comments on commit 62aca25

Please sign in to comment.