nanoc 3.6.2 → 3.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -273,10 +273,6 @@ module Nanoc::Filters
273
273
  stdout.read
274
274
  end
275
275
 
276
- protected
277
-
278
- KNOWN_COLORIZERS = [ :coderay, :dummy, :pygmentize, :pygmentsrb, :simon_highlight ]
279
-
280
276
  # Wraps the element in <div class="CodeRay"><div class="code">
281
277
  def coderay_postprocess(language, element)
282
278
  # Skip if we're a free <code>
@@ -296,6 +292,10 @@ module Nanoc::Filters
296
292
  element.swap div_outer
297
293
  end
298
294
 
295
+ protected
296
+
297
+ KNOWN_COLORIZERS = [ :coderay, :dummy, :pygmentize, :pygmentsrb, :simon_highlight ]
298
+
299
299
  # Removes the first blank lines and any whitespace at the end.
300
300
  def strip(s)
301
301
  s.lines.drop_while { |line| line.strip.empty? }.join.rstrip
@@ -90,14 +90,7 @@ module Nanoc::Filters
90
90
  end
91
91
  end
92
92
  end
93
- result = doc.send("to_#{type}")
94
-
95
- # FIXME cleanup because it is ugly
96
- # # Because using the `Nokogiri::XML::DocumentFragment` class DOCTYPE
97
- # pseudonodes becomes even more creepy than usual.
98
- result.sub!(/(!DOCTYPE.+?)(&gt;)/, '<\1>')
99
-
100
- result
93
+ doc.send("to_#{type}")
101
94
  end
102
95
 
103
96
  def path_is_relativizable?(s)
@@ -5,28 +5,8 @@ module Nanoc::Filters
5
5
 
6
6
  requires 'uglifier'
7
7
 
8
- # Runs the content through [UglifyJS](https://github.com/mishoo/UglifyJS/).
9
- # This method optionally takes options to pass directly to Uglifier:
10
- #
11
- # {
12
- # :mangle => true, # Mangle variables names
13
- # :toplevel => false, # Mangle top-level variable names
14
- # :except => [], # Variable names to be excluded from mangling
15
- # :max_line_length => 32 * 1024, # Maximum line length
16
- # :squeeze => true, # Squeeze code resulting in smaller, but less-readable code
17
- # :seqs => true, # Reduce consecutive statements in blocks into single statement
18
- # :dead_code => true, # Remove dead code (e.g. after return)
19
- # :unsafe => false, # Optimizations known to be unsafe in some situations
20
- # :copyright => true, # Show copyright message
21
- # :beautify => false, # Ouput indented code
22
- # :beautify_options => {
23
- # :indent_level => 4,
24
- # :indent_start => 0,
25
- # :quote_keys => false,
26
- # :space_colon => 0,
27
- # :ascii_only => false
28
- # }
29
- # }
8
+ # Runs the content through [UglifyJS](https://github.com/mishoo/UglifyJS2/).
9
+ # This method optionally takes options to pass directly to Uglifier.
30
10
  #
31
11
  # @param [String] content The content to filter
32
12
  #
@@ -89,6 +89,36 @@ EOS
89
89
  end
90
90
  end
91
91
 
92
+ def test_passthrough_with_ext_from_static_data_source
93
+ with_site do
94
+ # Create config
95
+ File.open('nanoc.yaml', 'w') do |io|
96
+ io.write "data_sources:\n"
97
+ io.write " - type: static\n"
98
+ end
99
+
100
+ # Create rules
101
+ File.open('Rules', 'w') do |io|
102
+ io.write <<EOS
103
+ passthrough "/foo.txt/"
104
+ EOS
105
+ end
106
+
107
+ # Create items
108
+ FileUtils.mkdir_p('static')
109
+ File.open('static/foo.txt', 'w') do |io|
110
+ io.write "Hello I am foo"
111
+ end
112
+
113
+ # Compile
114
+ site = Nanoc::Site.new('.')
115
+ site.compile
116
+
117
+ # Check paths
118
+ assert_equal [ 'output/foo.txt' ], Dir['output/*']
119
+ end
120
+ end
121
+
92
122
  def test_passthrough_priority
93
123
  with_site do
94
124
  # Create rules
@@ -111,7 +111,33 @@ class Nanoc::CLI::Commands::CompileTest < Nanoc::TestCase
111
111
  Nanoc::CLI.run %w( compile )
112
112
  refute File.file?('output/stray.html')
113
113
  assert File.directory?('output/excluded_dir'),
114
- 'excluded_dir should still be there'
114
+ 'excluded_dir should still be there'
115
115
  end
116
116
  end
117
+
118
+ def test_setup_and_teardown_listeners
119
+ with_site do
120
+ test_listener_class = Class.new(::Nanoc::CLI::Commands::Compile::Listener) do
121
+ def start ; @started = true ; end
122
+ def stop ; @stopped = true ; end
123
+ def started? ; @started ; end
124
+ def stopped? ; @stopped ; end
125
+ end
126
+
127
+ options = {}
128
+ arguments = []
129
+ cmd = nil
130
+ listener_classes = [ test_listener_class ]
131
+ cmd_runner = Nanoc::CLI::Commands::Compile.new(
132
+ options, arguments, cmd, :listener_classes => listener_classes)
133
+
134
+ cmd_runner.run
135
+
136
+ listeners = cmd_runner.send(:listeners)
137
+ assert listeners.size == 1
138
+ assert listeners.first.started?
139
+ assert listeners.first.stopped?
140
+ end
141
+ end
142
+
117
143
  end
@@ -56,6 +56,16 @@ class Nanoc::CLI::Commands::WatchTest < Nanoc::TestCase
56
56
  end
57
57
  end
58
58
 
59
+ def test_growlnotify_cmd
60
+ notifier = Nanoc::CLI::Commands::Watch::Notifier.new
61
+ assert_equal [ 'growlnotify', '-m', 'foo' ], notifier.send(:growlnotify_cmd_for, 'foo')
62
+ end
63
+
64
+ def test_growlnotify_windows_cmd
65
+ notifier = Nanoc::CLI::Commands::Watch::Notifier.new
66
+ assert_equal [ 'growlnotify', '/t:nanoc', 'foo' ], notifier.send(:growlnotify_windows_cmd_for, 'foo')
67
+ end
68
+
59
69
  def wait_until_exists(filename)
60
70
  20.times do
61
71
  break if File.file?(filename)
@@ -13,6 +13,34 @@ class Nanoc::DataSources::StaticTest < Nanoc::TestCase
13
13
  data_source
14
14
  end
15
15
 
16
+ def test_items_with_symlinks
17
+ # Create data source
18
+ data_source = new_data_source(:prefix => 'foo')
19
+
20
+ # Create sample files
21
+ FileUtils.mkdir_p('foo')
22
+ FileUtils.mkdir_p('foo-outside-1')
23
+ FileUtils.mkdir_p('foo-outside-2')
24
+ File.open('foo/a.png', 'w') { |io| io.write("random binary data") }
25
+ File.open('foo-outside-1/b.png', 'w') { |io| io.write("more binary data") }
26
+ File.open('foo-outside-2/c.png', 'w') { |io| io.write("yet more binary data") }
27
+
28
+ # Create symlinks
29
+ File.symlink('../foo-outside-1', 'foo/1')
30
+ File.symlink('../foo-outside-2/c.png', 'foo/c.png')
31
+
32
+ # Check all files
33
+ expected_filenames = [ 'foo/a.png', 'foo/1/b.png', 'foo/c.png' ].sort
34
+ actual_filenames = Nanoc::Extra::FilesystemTools.all_files_in('foo').sort
35
+ assert_equal expected_filenames, actual_filenames
36
+
37
+ # Check items
38
+ items = data_source.send(:items).sort_by { |i| i.identifier }
39
+ actual_item_identifiers = items.map { |i| i.identifier }.sort
40
+ expected_item_identifiers = %w( /a.png/ /1/b.png/ /c.png/ ).sort
41
+ assert_equal expected_item_identifiers, actual_item_identifiers
42
+ end
43
+
16
44
  def test_items
17
45
  # Create data source
18
46
  data_source = new_data_source(:prefix => 'foo')
@@ -21,7 +21,7 @@ class Nanoc::Extra::Checking::Checks::ExternalLinksTest < Nanoc::TestCase
21
21
  end
22
22
  end
23
23
 
24
- def test_valid?
24
+ def test_valid_by_path
25
25
  with_site do |site|
26
26
  # Create check
27
27
  check = Nanoc::Extra::Checking::Checks::ExternalLinks.new(site)
@@ -36,6 +36,20 @@ class Nanoc::Extra::Checking::Checks::ExternalLinksTest < Nanoc::TestCase
36
36
  end
37
37
  end
38
38
 
39
+ def test_valid_by_query
40
+ with_site do |site|
41
+ # Create check
42
+ check = Nanoc::Extra::Checking::Checks::ExternalLinks.new(site)
43
+ def check.request_url_once(url)
44
+ Net::HTTPResponse.new('1.1', url.query == 'status=200' ? '200' : '404', 'okay')
45
+ end
46
+
47
+ # Test
48
+ assert_nil check.validate('http://example.com/?status=200')
49
+ refute_nil check.validate('http://example.com/?status=404')
50
+ end
51
+ end
52
+
39
53
  def test_fallback_to_get_when_head_is_not_allowed
40
54
  with_site do |site|
41
55
  #Create check
@@ -50,4 +64,16 @@ class Nanoc::Extra::Checking::Checks::ExternalLinksTest < Nanoc::TestCase
50
64
  end
51
65
  end
52
66
 
67
+ def test_path_for_url
68
+ with_site do |site|
69
+ check = Nanoc::Extra::Checking::Checks::ExternalLinks.new(site)
70
+
71
+ assert_equal '/', check.send(:path_for_url, URI.parse('http://example.com'))
72
+ assert_equal '/', check.send(:path_for_url, URI.parse('http://example.com/'))
73
+ assert_equal '/?foo=bar', check.send(:path_for_url, URI.parse('http://example.com?foo=bar'))
74
+ assert_equal '/?foo=bar', check.send(:path_for_url, URI.parse('http://example.com/?foo=bar'))
75
+ assert_equal '/meow?foo=bar', check.send(:path_for_url, URI.parse('http://example.com/meow?foo=bar'))
76
+ end
77
+ end
78
+
53
79
  end
@@ -6,7 +6,7 @@ class Nanoc::Extra::Checking::Checks::HTMLTest < Nanoc::TestCase
6
6
  with_site do |site|
7
7
  # Create files
8
8
  FileUtils.mkdir_p('output')
9
- File.open('output/blah.html', 'w') { |io| io.write('<!DOCTYPE html><html><head><title>Hello</title></head><body><h1>Hi!</h1></body>') }
9
+ File.open('output/blah.html', 'w') { |io| io.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Hello</title></head><body><h1>Hi!</h1></body>') }
10
10
  File.open('output/style.css', 'w') { |io| io.write('h1 { coxlor: rxed; }') }
11
11
 
12
12
  # Run check
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Extra::FilesystemToolsTest < Nanoc::TestCase
4
+
5
+ def test_all_files_in_follows_symlinks_to_dirs
6
+ # Write sample files
7
+ (0..15).each do |i|
8
+ FileUtils.mkdir_p("dir#{i}")
9
+ File.open("dir#{i}/foo.md", 'w') { |io| io.write('o hai') }
10
+ end
11
+ (1..10).each do |i|
12
+ File.symlink("../dir#{i}", "dir#{i-1}/sub")
13
+ end
14
+
15
+ # Check
16
+ # 11 expected files (follow symlink 10 times)
17
+ # sort required because 10 comes before 2
18
+ expected_files = [
19
+ 'dir0/foo.md',
20
+ 'dir0/sub/foo.md',
21
+ 'dir0/sub/sub/foo.md',
22
+ 'dir0/sub/sub/sub/foo.md',
23
+ 'dir0/sub/sub/sub/sub/foo.md',
24
+ 'dir0/sub/sub/sub/sub/sub/foo.md',
25
+ 'dir0/sub/sub/sub/sub/sub/sub/foo.md',
26
+ 'dir0/sub/sub/sub/sub/sub/sub/sub/foo.md',
27
+ 'dir0/sub/sub/sub/sub/sub/sub/sub/sub/foo.md',
28
+ 'dir0/sub/sub/sub/sub/sub/sub/sub/sub/sub/foo.md',
29
+ 'dir0/sub/sub/sub/sub/sub/sub/sub/sub/sub/sub/foo.md'
30
+ ]
31
+ actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir0').sort
32
+ assert_equal expected_files, actual_files
33
+ end
34
+
35
+ def test_all_files_in_follows_symlinks_to_dirs_too_many
36
+ # Write sample files
37
+ (0..15).each do |i|
38
+ FileUtils.mkdir_p("dir#{i}")
39
+ File.open("dir#{i}/foo.md", 'w') { |io| io.write('o hai') }
40
+ end
41
+ (1..15).each do |i|
42
+ File.symlink("../dir#{i}", "dir#{i-1}/sub")
43
+ end
44
+
45
+ assert_raises Nanoc::Extra::FilesystemTools::MaxSymlinkDepthExceededError do
46
+ Nanoc::Extra::FilesystemTools.all_files_in('dir0')
47
+ end
48
+ end
49
+
50
+ def test_all_files_in_relativizes_directory_names
51
+ FileUtils.mkdir('foo')
52
+ FileUtils.mkdir('bar')
53
+
54
+ File.open('foo/x.md', 'w') { |io| io.write('o hai from foo/x') }
55
+ File.open('bar/y.md', 'w') { |io| io.write('o hai from bar/y') }
56
+
57
+ File.symlink('../bar', 'foo/barlink')
58
+
59
+ expected_files = [ 'foo/barlink/y.md', 'foo/x.md' ]
60
+ actual_files = Nanoc::Extra::FilesystemTools.all_files_in('foo').sort
61
+ assert_equal expected_files, actual_files
62
+ end
63
+
64
+ def test_all_files_in_follows_symlinks_to_files
65
+ # Write sample files
66
+ File.open('bar', 'w') { |io| io.write('o hai from bar') }
67
+ FileUtils.mkdir_p('dir')
68
+ File.open('dir/foo', 'w') { |io| io.write('o hai from foo') }
69
+ File.symlink('../bar', 'dir/bar-link')
70
+
71
+ # Check
72
+ expected_files = [ 'dir/bar-link', 'dir/foo' ]
73
+ actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir').sort
74
+ assert_equal expected_files, actual_files
75
+ end
76
+
77
+ def test_resolve_symlink
78
+ File.open('foo', 'w') { |io| io.write('o hai') }
79
+ File.symlink('foo', 'bar')
80
+ File.symlink('bar', 'baz')
81
+ File.symlink('baz', 'qux')
82
+
83
+ expected = File.expand_path('foo')
84
+ actual = Nanoc::Extra::FilesystemTools.resolve_symlink('qux')
85
+ assert_equal expected, actual
86
+ end
87
+
88
+ def test_resolve_symlink_too_many
89
+ File.open('foo', 'w') { |io| io.write('o hai') }
90
+ File.symlink('foo', 'symlin-0')
91
+ (1..7).each do |i|
92
+ File.symlink("symlink-#{i-1}", "symlink-#{i}")
93
+ end
94
+
95
+ assert_raises Nanoc::Extra::FilesystemTools::MaxSymlinkDepthExceededError do
96
+ Nanoc::Extra::FilesystemTools.resolve_symlink('symlink-7')
97
+ end
98
+ end
99
+
100
+ end
@@ -13,7 +13,7 @@ class Nanoc::Filters::PandocTest < Nanoc::TestCase
13
13
 
14
14
  # Run filter
15
15
  result = filter.setup_and_run("# Heading\n")
16
- assert_equal("<h1 id=\"heading\">Heading</h1>", result)
16
+ assert_match(%r{<h1 id=\"heading\">Heading</h1>\s*}, result)
17
17
  end
18
18
  end
19
19
 
@@ -750,5 +750,28 @@ XML
750
750
  end
751
751
  end
752
752
 
753
+ def test_filter_html_doctype
754
+ # Create filter with mock item
755
+ filter = Nanoc::Filters::RelativizePaths.new
756
+
757
+ # Mock item
758
+ filter.instance_eval do
759
+ @item_rep = Nanoc::ItemRep.new(
760
+ Nanoc::Item.new(
761
+ 'content',
762
+ {},
763
+ '/foo/bar/baz/'),
764
+ :blah)
765
+ @item_rep.path = '/foo/bar/baz/'
766
+ end
767
+
768
+ # Set content
769
+ raw_content = %[&lt;!DOCTYPE html>]
770
+ expected_content = %[&lt;!DOCTYPE html&gt;]
771
+
772
+ # Test
773
+ actual_content = filter.setup_and_run(raw_content, :type => :html)
774
+ assert_equal(expected_content, actual_content)
775
+ end
753
776
 
754
777
  end
@@ -8,20 +8,22 @@ class Nanoc::Filters::UglifyJSTest < Nanoc::TestCase
8
8
  filter = ::Nanoc::Filters::UglifyJS.new
9
9
 
10
10
  # Run filter
11
- result = filter.setup_and_run("foo = 1; (function(bar) { if (true) alert(bar); })(foo)")
11
+ input = "foo = 1; (function(bar) { if (true) alert(bar); })(foo)"
12
+ result = filter.setup_and_run(input)
12
13
  assert_match(/foo=1,function\((.)\)\{alert\(\1\)\}\(foo\);/, result)
13
14
  end
14
15
  end
15
16
 
16
17
  def test_filter_with_options
17
-
18
18
  if_have 'uglifier' do
19
- # Create filter
20
19
  filter = ::Nanoc::Filters::UglifyJS.new
20
+ input = "if(donkey) alert('It is a donkey!');"
21
21
 
22
- # Run filter
23
- result = filter.setup_and_run("foo = 1; (function(bar) { if (true) alert(bar); })(foo)", :toplevel => true)
24
- assert_match(/foo=1,function\((.)\)\{alert\(\1\)\}\(foo\);/, result)
22
+ result = filter.setup_and_run(input, output: { beautify: false })
23
+ assert_equal 'donkey&&alert("It is a donkey!");', result
24
+
25
+ result = filter.setup_and_run(input, output: { beautify: true })
26
+ assert_equal 'donkey && alert("It is a donkey!");', result
25
27
  end
26
28
  end
27
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.2
4
+ version: 3.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-23 00:00:00.000000000 Z
11
+ date: 2013-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cri
@@ -108,6 +108,7 @@ extra_rdoc_files:
108
108
  - README.md
109
109
  - NEWS.md
110
110
  files:
111
+ - Architecture.md
111
112
  - ChangeLog
112
113
  - CONTRIBUTING.md
113
114
  - Gemfile
@@ -116,6 +117,7 @@ files:
116
117
  - NEWS.md
117
118
  - Rakefile
118
119
  - README.md
120
+ - TODO.md
119
121
  - doc/yardoc_templates/default/layout/html/footer.erb
120
122
  - bin/nanoc
121
123
  - lib/nanoc/base/compilation/checksum_store.rb
@@ -216,6 +218,7 @@ files:
216
218
  - lib/nanoc/extra/deployers/rsync.rb
217
219
  - lib/nanoc/extra/deployers.rb
218
220
  - lib/nanoc/extra/file_proxy.rb
221
+ - lib/nanoc/extra/filesystem_tools.rb
219
222
  - lib/nanoc/extra/link_collector.rb
220
223
  - lib/nanoc/extra/pruner.rb
221
224
  - lib/nanoc/extra/validators/links.rb
@@ -341,6 +344,7 @@ files:
341
344
  - test/extra/deployers/test_rsync.rb
342
345
  - test/extra/test_auto_compiler.rb
343
346
  - test/extra/test_file_proxy.rb
347
+ - test/extra/test_filesystem_tools.rb
344
348
  - test/extra/test_link_collector.rb
345
349
  - test/extra/test_vcs.rb
346
350
  - test/extra/validators/test_links.rb