nanoc 3.3.5 → 3.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.md +4 -0
- data/lib/nanoc.rb +1 -1
- data/lib/nanoc/filters/relativize_paths.rb +2 -5
- data/test/filters/test_relativize_paths.rb +64 -6
- metadata +2 -2
data/NEWS.md
CHANGED
data/lib/nanoc.rb
CHANGED
@@ -73,7 +73,7 @@ module Nanoc::Filters
|
|
73
73
|
# Ensure that all prefixes are strings
|
74
74
|
namespaces = namespaces.inject({}) { |new, (prefix, uri)| new.merge(prefix.to_s => uri) }
|
75
75
|
|
76
|
-
doc = klass.fragment(content)
|
76
|
+
doc = content =~ /<html[\s>]/ ? klass.parse(content) : klass.fragment(content)
|
77
77
|
selectors.map { |sel| "descendant-or-self::#{sel}" }.each do |selector|
|
78
78
|
doc.xpath(selector, namespaces).each do |node|
|
79
79
|
if self.path_is_relativizable?(node.content)
|
@@ -92,10 +92,7 @@ module Nanoc::Filters
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def path_is_relativizable?(s)
|
95
|
-
|
96
|
-
return false if s =~ URI.regexp
|
97
|
-
return false if s[0,1] == '#'
|
98
|
-
return true
|
95
|
+
s[0,1] == '/'
|
99
96
|
end
|
100
97
|
|
101
98
|
end
|
@@ -77,6 +77,42 @@ class Nanoc::Filters::RelativizePathsTest < MiniTest::Unit::TestCase
|
|
77
77
|
assert_equal(expected_content, actual_content)
|
78
78
|
end
|
79
79
|
|
80
|
+
def test_filter_html_with_boilerplate
|
81
|
+
# Create filter with mock item
|
82
|
+
filter = Nanoc::Filters::RelativizePaths.new
|
83
|
+
|
84
|
+
# Mock item
|
85
|
+
filter.instance_eval do
|
86
|
+
@item_rep = Nanoc::ItemRep.new(
|
87
|
+
Nanoc::Item.new(
|
88
|
+
'content',
|
89
|
+
{},
|
90
|
+
'/foo/bar/baz/'),
|
91
|
+
:blah)
|
92
|
+
@item_rep.path = '/foo/bar/baz/'
|
93
|
+
end
|
94
|
+
|
95
|
+
# Set content
|
96
|
+
raw_content = <<EOS
|
97
|
+
<!DOCTYPE html>
|
98
|
+
<html>
|
99
|
+
<head>
|
100
|
+
<title>Hello</title>
|
101
|
+
</head>
|
102
|
+
<body>
|
103
|
+
<a href=/foo>foo</a>
|
104
|
+
</body>
|
105
|
+
</html>
|
106
|
+
EOS
|
107
|
+
expected_match_0 = %r{<a href="\.\./\.\.">foo</a>}
|
108
|
+
expected_match_1 = %r{^<!DOCTYPE html>\s*<html>\s*<head>(.|\s)*<title>Hello</title>\s*</head>\s*<body>\s*<a href="../..">foo</a>\s*</body>\s*</html>\s*$}
|
109
|
+
|
110
|
+
# Test
|
111
|
+
actual_content = filter.run(raw_content, :type => :html)
|
112
|
+
assert_match(expected_match_0, actual_content)
|
113
|
+
assert_match(expected_match_1, actual_content)
|
114
|
+
end
|
115
|
+
|
80
116
|
def test_filter_html_multiple
|
81
117
|
# Create filter with mock item
|
82
118
|
filter = Nanoc::Filters::RelativizePaths.new
|
@@ -245,6 +281,30 @@ class Nanoc::Filters::RelativizePathsTest < MiniTest::Unit::TestCase
|
|
245
281
|
assert_equal(expected_content, actual_content)
|
246
282
|
end
|
247
283
|
|
284
|
+
def test_filter_html_with_relative_path
|
285
|
+
# Create filter with mock item
|
286
|
+
filter = Nanoc::Filters::RelativizePaths.new
|
287
|
+
|
288
|
+
# Mock item
|
289
|
+
filter.instance_eval do
|
290
|
+
@item_rep = Nanoc::ItemRep.new(
|
291
|
+
Nanoc::Item.new(
|
292
|
+
'content',
|
293
|
+
{},
|
294
|
+
'/foo/bar/baz/'),
|
295
|
+
:blah)
|
296
|
+
@item_rep.path = '/woof/meow/'
|
297
|
+
end
|
298
|
+
|
299
|
+
# Set content
|
300
|
+
raw_content = %[<a href="example">Example</a>]
|
301
|
+
expected_content = %[<a href="example">Example</a>]
|
302
|
+
|
303
|
+
# Test
|
304
|
+
actual_content = filter.run(raw_content, :type => :html)
|
305
|
+
assert_equal(expected_content, actual_content)
|
306
|
+
end
|
307
|
+
|
248
308
|
def test_filter_implicit
|
249
309
|
# Create filter with mock item
|
250
310
|
filter = Nanoc::Filters::RelativizePaths.new
|
@@ -544,10 +604,9 @@ XML
|
|
544
604
|
</html>
|
545
605
|
XML
|
546
606
|
|
547
|
-
|
548
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
607
|
+
expected_match = %r{^<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
549
608
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
550
|
-
<head
|
609
|
+
<head>.*<meta.*charset.*>
|
551
610
|
<link rel="stylesheet" href="../../../css" />
|
552
611
|
<script src="../../../js"></script>
|
553
612
|
</head>
|
@@ -555,12 +614,11 @@ XML
|
|
555
614
|
<a href="../..">bar</a>
|
556
615
|
<img src="../../../img" />
|
557
616
|
</body>
|
558
|
-
</html>
|
559
|
-
XML
|
617
|
+
</html>}
|
560
618
|
|
561
619
|
# Test
|
562
620
|
actual_content = filter.run(raw_content, :type => :xhtml)
|
563
|
-
|
621
|
+
assert_match expected_match, actual_content
|
564
622
|
end
|
565
623
|
end
|
566
624
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cri
|