nanoc3 3.2.0b2 → 3.2.0b3

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,6 +34,7 @@ module Nanoc3::ArrayExtensions
34
34
  #
35
35
  # @since 3.2.0
36
36
  def freeze_recursively
37
+ return if self.frozen?
37
38
  freeze
38
39
  each do |value|
39
40
  if value.respond_to?(:freeze_recursively)
@@ -44,6 +45,16 @@ module Nanoc3::ArrayExtensions
44
45
  end
45
46
  end
46
47
 
48
+ # Calculates the checksum for this array. Any change to this array will
49
+ # result in a different checksum.
50
+ #
51
+ # @return [String] The checksum for this array
52
+ #
53
+ # @api private
54
+ def checksum
55
+ Marshal.dump(self).checksum
56
+ end
57
+
47
58
  end
48
59
 
49
60
  class Array
@@ -34,6 +34,7 @@ module Nanoc3::HashExtensions
34
34
  #
35
35
  # @since 3.2.0
36
36
  def freeze_recursively
37
+ return if self.frozen?
37
38
  freeze
38
39
  each_pair do |key, value|
39
40
  if value.respond_to?(:freeze_recursively)
@@ -51,7 +52,8 @@ module Nanoc3::HashExtensions
51
52
  #
52
53
  # @api private
53
54
  def checksum
54
- Marshal.dump(self).checksum
55
+ array = self.to_a.sort_by { |kv| kv[0] }
56
+ array.checksum
55
57
  end
56
58
 
57
59
  end
@@ -391,19 +391,21 @@ module Nanoc3
391
391
  Nanoc3::NotificationCenter.post(:visit_started, layout)
392
392
  Nanoc3::NotificationCenter.post(:visit_ended, layout)
393
393
 
394
- # Notify start
395
- Nanoc3::NotificationCenter.post(:processing_started, layout)
396
- Nanoc3::NotificationCenter.post(:filtering_started, self, filter_name)
397
-
398
- # Layout
399
- @content[:last] = filter.run(layout.raw_content, filter_args)
400
-
401
- # Create "post" snapshot
402
- snapshot(:post, :final => false)
403
- ensure
404
- # Notify end
405
- Nanoc3::NotificationCenter.post(:filtering_ended, self, filter_name)
406
- Nanoc3::NotificationCenter.post(:processing_ended, layout)
394
+ begin
395
+ # Notify start
396
+ Nanoc3::NotificationCenter.post(:processing_started, layout)
397
+ Nanoc3::NotificationCenter.post(:filtering_started, self, filter_name)
398
+
399
+ # Layout
400
+ @content[:last] = filter.run(layout.raw_content, filter_args)
401
+
402
+ # Create "post" snapshot
403
+ snapshot(:post, :final => false)
404
+ ensure
405
+ # Notify end
406
+ Nanoc3::NotificationCenter.post(:filtering_ended, self, filter_name)
407
+ Nanoc3::NotificationCenter.post(:processing_ended, layout)
408
+ end
407
409
  end
408
410
 
409
411
  # Creates a snapshot of the current compiled item content.
@@ -60,6 +60,25 @@ module Nanoc3::CLI
60
60
  def run
61
61
  end
62
62
 
63
+ # Gets the site ({Nanoc3::Site} instance) in the current directory and
64
+ # loads its data.
65
+ #
66
+ # @return [Nanoc3::Site] The site in the current working directory
67
+ def site
68
+ # Load site if possible
69
+ @site ||= nil
70
+ if File.file?('config.yaml') && @site.nil?
71
+ begin
72
+ @site = Nanoc3::Site.new('.')
73
+ rescue Nanoc3::Errors::UnknownDataSource => e
74
+ $stderr.puts "Unknown data source: #{e}"
75
+ exit 1
76
+ end
77
+ end
78
+
79
+ @site
80
+ end
81
+
63
82
  protected
64
83
 
65
84
  # @return [Boolean] true if debug output is enabled, false if not
@@ -83,25 +102,6 @@ module Nanoc3::CLI
83
102
  end
84
103
  end
85
104
 
86
- # Gets the site ({Nanoc3::Site} instance) in the current directory and
87
- # loads its data.
88
- #
89
- # @return [Nanoc3::Site] The site in the current working directory
90
- def site
91
- # Load site if possible
92
- @site ||= nil
93
- if File.file?('config.yaml') && @site.nil?
94
- begin
95
- @site = Nanoc3::Site.new('.')
96
- rescue Nanoc3::Errors::UnknownDataSource => e
97
- $stderr.puts "Unknown data source: #{e}"
98
- exit 1
99
- end
100
- end
101
-
102
- @site
103
- end
104
-
105
105
  # Sets the data source's VCS to the VCS with the given name. Does nothing
106
106
  # when the site's data source does not support VCSes (i.e. does not
107
107
  # implement #vcs=).
@@ -97,17 +97,25 @@ module Nanoc3::CLI::Commands
97
97
  end
98
98
 
99
99
  # Debug notifications
100
- Nanoc3::NotificationCenter.on(:compilation_started) do |rep|
101
- puts "*** Started compilation of #{rep.inspect}" if self.debug?
102
- end
103
- Nanoc3::NotificationCenter.on(:compilation_ended) do |rep|
104
- puts "*** Ended compilation of #{rep.inspect}" if self.debug?
105
- end
106
- Nanoc3::NotificationCenter.on(:compilation_failed) do |rep|
107
- puts "*** Suspended compilation of #{rep.inspect} due to unmet dependencies" if self.debug?
108
- end
109
- Nanoc3::NotificationCenter.on(:cached_content_used) do |rep|
110
- puts "*** Used cached compiled content for #{rep.inspect} instead of recompiling" if self.debug?
100
+ if self.debug?
101
+ Nanoc3::NotificationCenter.on(:compilation_started) do |rep|
102
+ puts "*** Started compilation of #{rep.inspect}"
103
+ end
104
+ Nanoc3::NotificationCenter.on(:compilation_ended) do |rep|
105
+ puts "*** Ended compilation of #{rep.inspect}"
106
+ end
107
+ Nanoc3::NotificationCenter.on(:compilation_failed) do |rep|
108
+ puts "*** Suspended compilation of #{rep.inspect} due to unmet dependencies"
109
+ end
110
+ Nanoc3::NotificationCenter.on(:cached_content_used) do |rep|
111
+ puts "*** Used cached compiled content for #{rep.inspect} instead of recompiling"
112
+ end
113
+ Nanoc3::NotificationCenter.on(:filtering_started) do |rep, filter_name|
114
+ puts "*** Started filtering #{rep.inspect} with #{filter_name}"
115
+ end
116
+ Nanoc3::NotificationCenter.on(:filtering_ended) do |rep, filter_name|
117
+ puts "*** Ended filtering #{rep.inspect} with #{filter_name}"
118
+ end
111
119
  end
112
120
 
113
121
  # Timing notifications
@@ -3,7 +3,7 @@
3
3
  usage 'view [options]'
4
4
  summary 'start the web server that serves static files'
5
5
  description <<-EOS
6
- Start the static web server. Unless specified, the web server will run on port 3000 and listen on all IP addresses. Running the autocompiler requires 'adsf' and 'rack'.
6
+ Start the static web server. Unless specified, the web server will run on port 3000 and listen on all IP addresses. Running this static web server requires 'adsf' (not 'asdf'!).
7
7
  EOS
8
8
 
9
9
  option :H, :handler, 'specify the handler to use (webrick/mongrel/...)'
@@ -19,8 +19,8 @@ module Nanoc3::CLI::Commands
19
19
  class View < ::Nanoc3::CLI::Command
20
20
 
21
21
  def run
22
+ load_adsf
22
23
  require 'rack'
23
- require 'adsf'
24
24
 
25
25
  # Make sure we are in a nanoc site directory
26
26
  self.require_site
@@ -55,6 +55,30 @@ module Nanoc3::CLI::Commands
55
55
  handler.run(app, options_for_rack)
56
56
  end
57
57
 
58
+ protected
59
+
60
+ def load_adsf
61
+ # Load adsf
62
+ begin
63
+ require 'adsf'
64
+ return
65
+ rescue LoadError
66
+ $stderr.puts "Could not find the required 'adsf' gem, " \
67
+ "which is necessary for the view command."
68
+ end
69
+
70
+ # Check asdf
71
+ begin
72
+ require 'asdf'
73
+ $stderr.puts "You appear to have 'asdf' installed, " \
74
+ "but not 'adsf'. Please install 'adsf' (check the spelling)!"
75
+ rescue LoadError
76
+ end
77
+
78
+ # Done
79
+ exit 1
80
+ end
81
+
58
82
  end
59
83
 
60
84
  end
data/lib/nanoc3/cli.rb CHANGED
@@ -104,7 +104,7 @@ protected
104
104
  def self.load_command_at(filename, command_name=nil)
105
105
  # Load
106
106
  code = File.read(filename)
107
- cmd = Cri::Command.define(code)
107
+ cmd = Cri::Command.define(code, filename)
108
108
 
109
109
  # Set name
110
110
  command_name ||= File.basename(filename, '.rb')
@@ -91,23 +91,27 @@ module Nanoc3::Helpers
91
91
  # Create filter
92
92
  filter = filter_class.new(assigns)
93
93
 
94
- # Notify start
95
- Nanoc3::NotificationCenter.post(:processing_started, layout)
96
-
97
- # Layout
98
- result = filter.run(layout.raw_content, filter_args)
99
-
100
- # Append to erbout if we have a block
101
- if block_given?
102
- erbout = eval('_erbout', block.binding)
103
- erbout << result
94
+ begin
95
+ # Notify start
96
+ Nanoc3::NotificationCenter.post(:processing_started, layout)
97
+
98
+ # Layout
99
+ result = filter.run(layout.raw_content, filter_args)
100
+
101
+ # Append to erbout if we have a block
102
+ if block_given?
103
+ # Append result and return nothing
104
+ erbout = eval('_erbout', block.binding)
105
+ erbout << result
106
+ ''
107
+ else
108
+ # Return result
109
+ result
110
+ end
111
+ ensure
112
+ # Notify end
113
+ Nanoc3::NotificationCenter.post(:processing_ended, layout)
104
114
  end
105
-
106
- # Done
107
- result
108
- ensure
109
- # Notify end
110
- Nanoc3::NotificationCenter.post(:processing_ended, layout)
111
115
  end
112
116
 
113
117
  end
data/lib/nanoc3.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Nanoc3
4
4
 
5
5
  # The current nanoc version.
6
- VERSION = '3.2.0b2'
6
+ VERSION = '3.2.0b3'
7
7
 
8
8
  end
9
9
 
@@ -50,4 +50,24 @@ describe 'Array#freeze_recursively' do
50
50
  assert raised
51
51
  end
52
52
 
53
+ it 'should not freeze infinitely' do
54
+ a = []
55
+ a << a
56
+
57
+ a.freeze_recursively
58
+
59
+ assert a.frozen?
60
+ assert a[0].frozen?
61
+ assert_equal a, a[0]
62
+ end
63
+
64
+ end
65
+
66
+ describe 'Array#checksum' do
67
+
68
+ it 'should work' do
69
+ expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
70
+ [ [ :foo, 123 ]].checksum.must_equal expectation
71
+ end
72
+
53
73
  end
@@ -68,13 +68,31 @@ describe 'Hash#freeze_recursively' do
68
68
  assert raised
69
69
  end
70
70
 
71
+ it 'should not freeze infinitely' do
72
+ a = {}
73
+ a[:x] = a
74
+
75
+ a.freeze_recursively
76
+
77
+ assert a.frozen?
78
+ assert a[:x].frozen?
79
+ assert_equal a, a[:x]
80
+ end
81
+
71
82
  end
72
83
 
73
84
  describe 'Hash#checksum' do
74
85
 
75
86
  it 'should work' do
76
- expectation = 'fec9ae7163e8b8d57a15d51821d2c68d4a6bb169'
87
+ expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
77
88
  { :foo => 123 }.checksum.must_equal expectation
89
+ [ [ :foo, 123 ]].checksum.must_equal expectation
90
+ end
91
+
92
+ it 'should sort keys' do
93
+ a = { :a => 1, :c => 2, :b => 3 }.checksum
94
+ b = { :a => 1, :b => 3, :c => 2 }.checksum
95
+ a.must_equal b
78
96
  end
79
97
 
80
98
  end
data/test/cli/test_cli.rb CHANGED
@@ -95,6 +95,7 @@ EOS
95
95
  # Check error output
96
96
  stderr_addition = $stderr.string[position_before, position_after]
97
97
  assert_match(/=== BACKTRACE:/, stderr_addition)
98
+ assert_match(/commands\/_test.rb/, stderr_addition)
98
99
  end
99
100
  end
100
101
 
@@ -396,20 +396,22 @@ class Nanoc3::Extra::AutoCompilerTest < MiniTest::Unit::TestCase
396
396
  end
397
397
 
398
398
  def test_call_with_uri_encoded_path
399
- # Create autocompiler
400
- autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
401
-
402
- # Mock dependencies
403
- site = mock
404
- site.stubs(:config).returns({ :output_dir => 'output/' })
405
- site.stubs(:items).returns([])
406
- autocompiler.stubs(:build_site)
407
- autocompiler.stubs(:site).returns(site)
408
-
409
- # Test
410
- result = autocompiler.call('PATH_INFO' => '/%73oftware')
411
- assert_equal 404, result[0]
412
- assert_match "File not found: /software\n", result[2][0]
399
+ if_have 'rack' do
400
+ # Create autocompiler
401
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
402
+
403
+ # Mock dependencies
404
+ site = mock
405
+ site.stubs(:config).returns({ :output_dir => 'output/' })
406
+ site.stubs(:items).returns([])
407
+ autocompiler.stubs(:build_site)
408
+ autocompiler.stubs(:site).returns(site)
409
+
410
+ # Test
411
+ result = autocompiler.call('PATH_INFO' => '/%73oftware')
412
+ assert_equal 404, result[0]
413
+ assert_match "File not found: /software\n", result[2][0]
414
+ end
413
415
  end
414
416
 
415
417
  end
@@ -5,16 +5,18 @@ class Nanoc3::Filters::AsciiDocTest < MiniTest::Unit::TestCase
5
5
  include Nanoc3::TestHelpers
6
6
 
7
7
  def test_filter
8
- if `which asciidoc`.strip.empty?
9
- skip "could not find asciidoc"
10
- end
8
+ if_have 'systemu' do
9
+ if `which asciidoc`.strip.empty?
10
+ skip "could not find asciidoc"
11
+ end
11
12
 
12
- # Create filter
13
- filter = ::Nanoc3::Filters::AsciiDoc.new
13
+ # Create filter
14
+ filter = ::Nanoc3::Filters::AsciiDoc.new
14
15
 
15
- # Run filter
16
- result = filter.run("== Blah blah")
17
- assert_match %r{<h2 id="_blah_blah">Blah blah</h2>}, result
16
+ # Run filter
17
+ result = filter.run("== Blah blah")
18
+ assert_match %r{<h2 id="_blah_blah">Blah blah</h2>}, result
19
+ end
18
20
  end
19
21
 
20
22
  end
@@ -65,7 +65,7 @@ class Nanoc3::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase
65
65
  end
66
66
 
67
67
  def test_pygmentize
68
- if_have 'nokogiri' do
68
+ if_have 'nokogiri', 'systemu' do
69
69
  if `which pygmentize`.strip.empty?
70
70
  skip "could not find pygmentize"
71
71
  end
@@ -84,7 +84,7 @@ class Nanoc3::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase
84
84
  end
85
85
 
86
86
  def test_simon_highlight
87
- if_have 'nokogiri' do
87
+ if_have 'nokogiri', 'systemu' do
88
88
  if `which highlight`.strip.empty?
89
89
  skip "could not find `highlight`"
90
90
  end
@@ -150,7 +150,7 @@ class Nanoc3::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase
150
150
  return
151
151
  end
152
152
 
153
- if_have 'nokogiri' do
153
+ if_have 'nokogiri', 'systemu' do
154
154
  # Create filter
155
155
  filter = ::Nanoc3::Filters::ColorizeSyntax.new
156
156
 
@@ -165,7 +165,7 @@ class Nanoc3::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase
165
165
  end
166
166
 
167
167
  def test_colorize_syntax_with_missing_executables
168
- if_have 'nokogiri' do
168
+ if_have 'nokogiri', 'systemu' do
169
169
  begin
170
170
  original_path = ENV['PATH']
171
171
  ENV['PATH'] = './blooblooblah'
@@ -5,7 +5,9 @@ class Nanoc3::Filters::RedcarpetTest < MiniTest::Unit::TestCase
5
5
  include Nanoc3::TestHelpers
6
6
 
7
7
  def test_find
8
- refute Nanoc3::Filter.named(:redcarpet).nil?
8
+ if_have 'redcarpet' do
9
+ refute Nanoc3::Filter.named(:redcarpet).nil?
10
+ end
9
11
  end
10
12
 
11
13
  def test_filter
@@ -77,11 +77,12 @@ class Nanoc3::Helpers::RenderingTest < MiniTest::Unit::TestCase
77
77
  end
78
78
 
79
79
  _erbout = '[erbout-before]'
80
- render '/foo/' do
80
+ result = render '/foo/' do
81
81
  _erbout << "This is some extra content"
82
82
  end
83
83
 
84
84
  assert_equal('[erbout-before][partial-before]This is some extra content[partial-after]', _erbout)
85
+ assert_equal '', result
85
86
  end
86
87
  end
87
88
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: nanoc3
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 5
5
- version: 3.2.0b2
5
+ version: 3.2.0b3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Denis Defreyne
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-16 00:00:00 Z
13
+ date: 2011-07-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: cri