nanoc3 3.2.0b1 → 3.2.0b2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.md +1 -1
- data/Rakefile +4 -1
- data/lib/nanoc3/cli/command.rb +2 -125
- data/lib/nanoc3/cli/commands/watch.rb +1 -1
- data/lib/nanoc3/cli/error_handler.rb +182 -0
- data/lib/nanoc3/cli.rb +44 -15
- data/lib/nanoc3/helpers/xml_sitemap.rb +1 -1
- data/lib/nanoc3.rb +1 -1
- data/nanoc3.gemspec +5 -0
- data/test/cli/test_cli.rb +61 -0
- data/test/cli/test_error_handler.rb +29 -0
- metadata +48 -2
data/NEWS.md
CHANGED
@@ -34,7 +34,7 @@ Extensions:
|
|
34
34
|
## 3.1.8 (2011-06-25)
|
35
35
|
|
36
36
|
* Made link validator accept https: URLs
|
37
|
-
* Fixed
|
37
|
+
* Fixed erroneous handling of layouts with names ending in index
|
38
38
|
* Fixed dependency generation between Sass partials
|
39
39
|
* Fixed errors related to thread requires
|
40
40
|
* Fixed crash while handling load errors
|
data/Rakefile
CHANGED
data/lib/nanoc3/cli/command.rb
CHANGED
@@ -47,23 +47,9 @@ module Nanoc3::CLI
|
|
47
47
|
#
|
48
48
|
# @return [void]
|
49
49
|
def call
|
50
|
-
|
51
|
-
|
52
|
-
Signal.trap(signal) do
|
53
|
-
puts
|
54
|
-
exit!(0)
|
55
|
-
end
|
50
|
+
Nanoc3::CLI::ErrorHandler.handle_while(:command => self) do
|
51
|
+
self.run
|
56
52
|
end
|
57
|
-
|
58
|
-
# Set attributes
|
59
|
-
|
60
|
-
# Run
|
61
|
-
self.run
|
62
|
-
rescue Interrupt => e
|
63
|
-
exit(1)
|
64
|
-
rescue StandardError, ScriptError => e
|
65
|
-
self.print_error(e)
|
66
|
-
exit(1)
|
67
53
|
end
|
68
54
|
|
69
55
|
# Performs the actual execution of the command.
|
@@ -83,115 +69,6 @@ module Nanoc3::CLI
|
|
83
69
|
Nanoc3::CLI.debug?
|
84
70
|
end
|
85
71
|
|
86
|
-
# A hash that contains the name of the gem for a given required file. If a
|
87
|
-
# `#require` fails, the gem name is looked up in this hash.
|
88
|
-
GEM_NAMES = {
|
89
|
-
'adsf' => 'adsf',
|
90
|
-
'bluecloth' => 'bluecloth',
|
91
|
-
'builder' => 'builder',
|
92
|
-
'coderay' => 'coderay',
|
93
|
-
'cri' => 'cri',
|
94
|
-
'erubis' => 'erubis',
|
95
|
-
'escape' => 'escape',
|
96
|
-
'fssm' => 'fssm',
|
97
|
-
'haml' => 'haml',
|
98
|
-
'json' => 'json',
|
99
|
-
'kramdown' => 'kramdown',
|
100
|
-
'less' => 'less',
|
101
|
-
'markaby' => 'markaby',
|
102
|
-
'maruku' => 'maruku',
|
103
|
-
'mime/types' => 'mime-types',
|
104
|
-
'nokogiri' => 'nokogiri',
|
105
|
-
'rack' => 'rack',
|
106
|
-
'rack/cache' => 'rack-cache',
|
107
|
-
'rainpress' => 'rainpress',
|
108
|
-
'rdiscount' => 'rdiscount',
|
109
|
-
'redcarpet' => 'redcarpet',
|
110
|
-
'redcloth' => 'redcloth',
|
111
|
-
'rubypants' => 'rubypants',
|
112
|
-
'sass' => 'sass',
|
113
|
-
'systemu' => 'systemu',
|
114
|
-
'w3c_validators' => 'w3c_validators'
|
115
|
-
}
|
116
|
-
|
117
|
-
# Prints the given error to stderr. Includes message, possible resolution
|
118
|
-
# (see {#resolution_for}), compilation stack, backtrace, etc.
|
119
|
-
#
|
120
|
-
# @param [Error] error The error that should be described
|
121
|
-
#
|
122
|
-
# @return [void]
|
123
|
-
def print_error(error)
|
124
|
-
$stderr.puts
|
125
|
-
|
126
|
-
# Header
|
127
|
-
$stderr.puts '+--- /!\ ERROR /!\ -------------------------------------------+'
|
128
|
-
$stderr.puts '| An exception occured while running nanoc. If you think this |'
|
129
|
-
$stderr.puts '| is a bug in nanoc, please do report it at |'
|
130
|
-
$stderr.puts '| <http://projects.stoneship.org/trac/nanoc/newticket> -- |'
|
131
|
-
$stderr.puts '| thanks in advance! |'
|
132
|
-
$stderr.puts '+-------------------------------------------------------------+'
|
133
|
-
|
134
|
-
# Exception and resolution (if any)
|
135
|
-
$stderr.puts
|
136
|
-
$stderr.puts '=== MESSAGE:'
|
137
|
-
$stderr.puts
|
138
|
-
$stderr.puts "#{error.class}: #{error.message}"
|
139
|
-
resolution = self.resolution_for(error)
|
140
|
-
$stderr.puts "#{resolution}" if resolution
|
141
|
-
|
142
|
-
# Compilation stack
|
143
|
-
$stderr.puts
|
144
|
-
$stderr.puts '=== COMPILATION STACK:'
|
145
|
-
$stderr.puts
|
146
|
-
if self.stack.empty?
|
147
|
-
$stderr.puts " (empty)"
|
148
|
-
else
|
149
|
-
self.stack.reverse.each do |obj|
|
150
|
-
if obj.is_a?(Nanoc3::ItemRep)
|
151
|
-
$stderr.puts " - [item] #{obj.item.identifier} (rep #{obj.name})"
|
152
|
-
else # layout
|
153
|
-
$stderr.puts " - [layout] #{obj.identifier}"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
# Backtrace
|
159
|
-
$stderr.puts
|
160
|
-
$stderr.puts '=== BACKTRACE:'
|
161
|
-
$stderr.puts
|
162
|
-
$stderr.puts error.backtrace.to_enum(:each_with_index).map { |item, index| " #{index}. #{item}" }.join("\n")
|
163
|
-
end
|
164
|
-
|
165
|
-
# Attempts to find a resolution for the given error, or nil if no
|
166
|
-
# resolution can be automatically obtained.
|
167
|
-
#
|
168
|
-
# @param [Error] error The error to find a resolution for
|
169
|
-
#
|
170
|
-
# @return [String] The resolution for the given error
|
171
|
-
def resolution_for(error)
|
172
|
-
case error
|
173
|
-
when LoadError
|
174
|
-
# Get gem name
|
175
|
-
matches = error.message.match(/no such file to load -- ([^\s]+)/)
|
176
|
-
return nil if matches.size == 0
|
177
|
-
lib_name = matches[1]
|
178
|
-
gem_name = GEM_NAMES[$1]
|
179
|
-
|
180
|
-
# Build message
|
181
|
-
if gem_name
|
182
|
-
"Try installing the '#{gem_name}' gem (`gem install #{gem_name}`) and then re-running the command."
|
183
|
-
end
|
184
|
-
when RuntimeError
|
185
|
-
if error.message =~ /^can't modify frozen/
|
186
|
-
"You attempted to modify immutable data. Some data, such as " \
|
187
|
-
"item/layout attributes and raw item/layout content, can not " \
|
188
|
-
"be modified once compilation has started. (This was " \
|
189
|
-
"unintentionally possible in 3.1.x and before, but has been " \
|
190
|
-
"disabled in 3.2.x in order to allow compiler optimisations.)"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
72
|
# Asserts that the current working directory contains a site
|
196
73
|
# ({Nanoc3::Site} instance). If no site is present, prints an error
|
197
74
|
# message and exits.
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Nanoc3::CLI
|
4
|
+
|
5
|
+
# Catches errors and prints nice diagnostic messages, then exits.
|
6
|
+
class ErrorHandler
|
7
|
+
|
8
|
+
# @option params [Nanoc3::CLI::Command, nil] command The command that is
|
9
|
+
# currently being executed, or nil if there is none
|
10
|
+
def initialize(params={})
|
11
|
+
@command = params[:command]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Enables error handling in the given block.
|
15
|
+
#
|
16
|
+
# @option params [Nanoc3::CLI::Command, nil] command The command that is
|
17
|
+
# currently being executed, or nil if there is none
|
18
|
+
#
|
19
|
+
# @return [void]
|
20
|
+
def self.handle_while(params={}, &block)
|
21
|
+
self.new(params).handle_while(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Enables error handling in the given block. This method should not be
|
25
|
+
# called directly; use {Nanoc3::CLI::ErrorHandler.handle_while} instead.
|
26
|
+
#
|
27
|
+
# @return [void]
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
def handle_while(&block)
|
31
|
+
# Set exit handler
|
32
|
+
[ 'INT', 'TERM' ].each do |signal|
|
33
|
+
Signal.trap(signal) do
|
34
|
+
puts
|
35
|
+
exit!(0)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Run
|
40
|
+
yield
|
41
|
+
rescue Interrupt => e
|
42
|
+
exit(1)
|
43
|
+
rescue StandardError, ScriptError => e
|
44
|
+
self.print_error(e)
|
45
|
+
exit(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
# @return [Boolean] true if debug output is enabled, false if not
|
51
|
+
#
|
52
|
+
# @see Nanoc3::CLI.debug?
|
53
|
+
def debug?
|
54
|
+
Nanoc3::CLI.debug?
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Nanoc3::Site] The site that is currently being processed
|
58
|
+
def site
|
59
|
+
@command && @command.site
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [Nanoc3::Compiler] The compiler for the current site
|
63
|
+
def compiler
|
64
|
+
site && site.compiler
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array] The current compilation stack
|
68
|
+
def stack
|
69
|
+
(compiler && compiler.stack) || []
|
70
|
+
end
|
71
|
+
|
72
|
+
# A hash that contains the name of the gem for a given required file. If a
|
73
|
+
# `#require` fails, the gem name is looked up in this hash.
|
74
|
+
GEM_NAMES = {
|
75
|
+
'adsf' => 'adsf',
|
76
|
+
'bluecloth' => 'bluecloth',
|
77
|
+
'builder' => 'builder',
|
78
|
+
'coderay' => 'coderay',
|
79
|
+
'cri' => 'cri',
|
80
|
+
'erubis' => 'erubis',
|
81
|
+
'escape' => 'escape',
|
82
|
+
'fssm' => 'fssm',
|
83
|
+
'haml' => 'haml',
|
84
|
+
'json' => 'json',
|
85
|
+
'kramdown' => 'kramdown',
|
86
|
+
'less' => 'less',
|
87
|
+
'markaby' => 'markaby',
|
88
|
+
'maruku' => 'maruku',
|
89
|
+
'mime/types' => 'mime-types',
|
90
|
+
'nokogiri' => 'nokogiri',
|
91
|
+
'rack' => 'rack',
|
92
|
+
'rack/cache' => 'rack-cache',
|
93
|
+
'rainpress' => 'rainpress',
|
94
|
+
'rdiscount' => 'rdiscount',
|
95
|
+
'redcarpet' => 'redcarpet',
|
96
|
+
'redcloth' => 'redcloth',
|
97
|
+
'rubypants' => 'rubypants',
|
98
|
+
'sass' => 'sass',
|
99
|
+
'systemu' => 'systemu',
|
100
|
+
'w3c_validators' => 'w3c_validators'
|
101
|
+
}
|
102
|
+
|
103
|
+
# Prints the given error to stderr. Includes message, possible resolution
|
104
|
+
# (see {#resolution_for}), compilation stack, backtrace, etc.
|
105
|
+
#
|
106
|
+
# @param [Error] error The error that should be described
|
107
|
+
#
|
108
|
+
# @return [void]
|
109
|
+
def print_error(error)
|
110
|
+
# Header
|
111
|
+
$stderr.puts
|
112
|
+
$stderr.puts "Captain! We’ve been hit!"
|
113
|
+
|
114
|
+
# Exception and resolution (if any)
|
115
|
+
$stderr.puts
|
116
|
+
$stderr.puts '=== MESSAGE:'
|
117
|
+
$stderr.puts
|
118
|
+
$stderr.puts "#{error.class}: #{error.message}"
|
119
|
+
resolution = self.resolution_for(error)
|
120
|
+
$stderr.puts "#{resolution}" if resolution
|
121
|
+
|
122
|
+
# Compilation stack
|
123
|
+
$stderr.puts
|
124
|
+
$stderr.puts '=== COMPILATION STACK:'
|
125
|
+
$stderr.puts
|
126
|
+
if self.stack.empty?
|
127
|
+
$stderr.puts " (empty)"
|
128
|
+
else
|
129
|
+
self.stack.reverse.each do |obj|
|
130
|
+
if obj.is_a?(Nanoc3::ItemRep)
|
131
|
+
$stderr.puts " - [item] #{obj.item.identifier} (rep #{obj.name})"
|
132
|
+
else # layout
|
133
|
+
$stderr.puts " - [layout] #{obj.identifier}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Backtrace
|
139
|
+
$stderr.puts
|
140
|
+
$stderr.puts '=== BACKTRACE:'
|
141
|
+
$stderr.puts
|
142
|
+
$stderr.puts error.backtrace.to_enum(:each_with_index).map { |item, index| " #{index}. #{item}" }.join("\n")
|
143
|
+
|
144
|
+
# Issue link
|
145
|
+
$stderr.puts
|
146
|
+
$stderr.puts "If you believe this is a bug in nanoc, please do report it at"
|
147
|
+
$stderr.puts "<https://github.com/ddfreyne/nanoc/issues/new>--thanks!"
|
148
|
+
end
|
149
|
+
|
150
|
+
# Attempts to find a resolution for the given error, or nil if no
|
151
|
+
# resolution can be automatically obtained.
|
152
|
+
#
|
153
|
+
# @param [Error] error The error to find a resolution for
|
154
|
+
#
|
155
|
+
# @return [String] The resolution for the given error
|
156
|
+
def resolution_for(error)
|
157
|
+
case error
|
158
|
+
when LoadError
|
159
|
+
# Get gem name
|
160
|
+
matches = error.message.match(/no such file to load -- ([^\s]+)/)
|
161
|
+
return nil if matches.size == 0
|
162
|
+
lib_name = matches[1]
|
163
|
+
gem_name = GEM_NAMES[$1]
|
164
|
+
|
165
|
+
# Build message
|
166
|
+
if gem_name
|
167
|
+
"Try installing the '#{gem_name}' gem (`gem install #{gem_name}`) and then re-running the command."
|
168
|
+
end
|
169
|
+
when RuntimeError
|
170
|
+
if error.message =~ /^can't modify frozen/
|
171
|
+
"You attempted to modify immutable data. Some data, such as " \
|
172
|
+
"item/layout attributes and raw item/layout content, can not " \
|
173
|
+
"be modified once compilation has started. (This was " \
|
174
|
+
"unintentionally possible in 3.1.x and before, but has been " \
|
175
|
+
"disabled in 3.2.x in order to allow compiler optimisations.)"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
data/lib/nanoc3/cli.rb
CHANGED
@@ -7,6 +7,10 @@ module Nanoc3::CLI
|
|
7
7
|
module Commands
|
8
8
|
end
|
9
9
|
|
10
|
+
autoload 'Logger', 'nanoc3/cli/logger'
|
11
|
+
autoload 'Command', 'nanoc3/cli/command'
|
12
|
+
autoload 'ErrorHandler', 'nanoc3/cli/error_handler'
|
13
|
+
|
10
14
|
# @return [Boolean] true if debug output is enabled, false if not
|
11
15
|
#
|
12
16
|
# @since 3.2.0
|
@@ -24,18 +28,17 @@ module Nanoc3::CLI
|
|
24
28
|
@debug = boolean
|
25
29
|
end
|
26
30
|
|
27
|
-
autoload 'Logger', 'nanoc3/cli/logger'
|
28
|
-
autoload 'Command', 'nanoc3/cli/command'
|
29
|
-
|
30
31
|
# Invokes the nanoc commandline tool with the given arguments.
|
31
32
|
#
|
32
33
|
# @param [Array<String>] args An array of commandline arguments
|
33
34
|
#
|
34
35
|
# @return [void]
|
35
36
|
def self.run(args)
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
Nanoc3::CLI::ErrorHandler.handle_while do
|
38
|
+
self.setup
|
39
|
+
self.load_custom_commands
|
40
|
+
self.root_command.run(args)
|
41
|
+
end
|
39
42
|
end
|
40
43
|
|
41
44
|
# Adds the given command to the collection of available commands.
|
@@ -53,8 +56,8 @@ protected
|
|
53
56
|
#
|
54
57
|
# @return [void]
|
55
58
|
def self.setup
|
56
|
-
#
|
57
|
-
|
59
|
+
# Reinit
|
60
|
+
@root_command = nil
|
58
61
|
|
59
62
|
# Add help command
|
60
63
|
help_cmd = Cri::Command.new_basic_help
|
@@ -67,17 +70,29 @@ protected
|
|
67
70
|
cmd = self.load_command_at(filename)
|
68
71
|
self.add_command(cmd)
|
69
72
|
end
|
70
|
-
|
71
|
-
@setup = true
|
72
73
|
end
|
73
74
|
|
74
75
|
# Loads the commands in `commands/`.
|
75
76
|
#
|
76
77
|
# @return [void]
|
77
78
|
def self.load_custom_commands
|
78
|
-
|
79
|
-
|
80
|
-
Nanoc3::CLI.
|
79
|
+
self.recursive_contents_of('commands').each do |filename|
|
80
|
+
# Create command
|
81
|
+
command = Nanoc3::CLI.load_command_at(filename)
|
82
|
+
|
83
|
+
# Get supercommand
|
84
|
+
pieces = filename.gsub(/^commands\/|\.rb$/, '').split('/')
|
85
|
+
pieces = pieces[0, pieces.size-1] || []
|
86
|
+
root = Nanoc3::CLI.root_command
|
87
|
+
supercommand = pieces.inject(root) do |cmd, piece|
|
88
|
+
cmd.nil? ? nil : cmd.command_named(piece)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Add to supercommand
|
92
|
+
if supercommand.nil?
|
93
|
+
raise "Cannot load command at #{filename} because its supercommand cannot be found"
|
94
|
+
end
|
95
|
+
supercommand.add_command(command)
|
81
96
|
end
|
82
97
|
end
|
83
98
|
|
@@ -86,10 +101,16 @@ protected
|
|
86
101
|
# @param [String] filename The name of the file that contains the command
|
87
102
|
#
|
88
103
|
# @return [Cri::Command] The loaded command
|
89
|
-
def self.load_command_at(filename)
|
104
|
+
def self.load_command_at(filename, command_name=nil)
|
105
|
+
# Load
|
90
106
|
code = File.read(filename)
|
91
107
|
cmd = Cri::Command.define(code)
|
92
|
-
|
108
|
+
|
109
|
+
# Set name
|
110
|
+
command_name ||= File.basename(filename, '.rb')
|
111
|
+
cmd.modify { name command_name }
|
112
|
+
|
113
|
+
# Done
|
93
114
|
cmd
|
94
115
|
end
|
95
116
|
|
@@ -101,4 +122,12 @@ protected
|
|
101
122
|
end
|
102
123
|
end
|
103
124
|
|
125
|
+
# @return [Array] The directory contents
|
126
|
+
def self.recursive_contents_of(path)
|
127
|
+
return [] unless File.directory?(path)
|
128
|
+
files, dirs = *Dir[path + '/*'].sort.partition { |e| File.file?(e) }
|
129
|
+
dirs.each { |d| files.concat self.recursive_contents_of(d) }
|
130
|
+
files
|
131
|
+
end
|
132
|
+
|
104
133
|
end
|
@@ -53,7 +53,7 @@ module Nanoc3::Helpers
|
|
53
53
|
|
54
54
|
# Build sitemap
|
55
55
|
xml.instruct!
|
56
|
-
xml.urlset(:xmlns => 'http://www.
|
56
|
+
xml.urlset(:xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9') do
|
57
57
|
# Add item
|
58
58
|
items.each do |item|
|
59
59
|
item.reps.reject { |r| r.raw_path.nil? }.each do |rep|
|
data/lib/nanoc3.rb
CHANGED
data/nanoc3.gemspec
CHANGED
@@ -25,6 +25,11 @@ Gem::Specification.new do |s|
|
|
25
25
|
|
26
26
|
s.add_runtime_dependency('cri', '~> 2.0')
|
27
27
|
|
28
|
+
s.add_development_dependency('minitest')
|
29
|
+
s.add_development_dependency('mocha')
|
30
|
+
s.add_development_dependency('rdiscount')
|
31
|
+
s.add_development_dependency('yard')
|
32
|
+
|
28
33
|
s.post_install_message = %q{------------------------------------------------------------------------------
|
29
34
|
Thanks for installing nanoc 3.2! Here are some resources to help you get
|
30
35
|
started:
|
data/test/cli/test_cli.rb
CHANGED
@@ -14,6 +14,18 @@ description 'longer meh'
|
|
14
14
|
run do |opts, args, cmd|
|
15
15
|
File.open('_test.out', 'w') { |io| io.write('It works!') }
|
16
16
|
end
|
17
|
+
EOS
|
18
|
+
|
19
|
+
SUBCOMMAND_CODE = <<EOS
|
20
|
+
# encoding: utf-8
|
21
|
+
|
22
|
+
usage '_sub [options]'
|
23
|
+
summary 'meh sub'
|
24
|
+
description 'longer meh sub'
|
25
|
+
|
26
|
+
run do |opts, args, cmd|
|
27
|
+
File.open('_test_sub.out', 'w') { |io| io.write('It works sub!') }
|
28
|
+
end
|
17
29
|
EOS
|
18
30
|
|
19
31
|
def test_load_custom_commands
|
@@ -37,4 +49,53 @@ EOS
|
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
52
|
+
def test_load_custom_commands_nested
|
53
|
+
Nanoc3::CLI.run %w( create_site foo )
|
54
|
+
FileUtils.cd('foo') do
|
55
|
+
# Create command
|
56
|
+
FileUtils.mkdir_p('commands')
|
57
|
+
File.open('commands/_test.rb', 'w') do |io|
|
58
|
+
io.write(COMMAND_CODE)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create subcommand
|
62
|
+
FileUtils.mkdir_p('commands/_test')
|
63
|
+
File.open('commands/_test/_sub.rb', 'w') do |io|
|
64
|
+
io.write(SUBCOMMAND_CODE)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Run command
|
68
|
+
begin
|
69
|
+
Nanoc3::CLI.run %w( _test _sub )
|
70
|
+
rescue SystemExit
|
71
|
+
assert false, 'Running _test sub should not cause system exit'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Check
|
75
|
+
assert File.file?('_test_sub.out')
|
76
|
+
assert_equal 'It works sub!', File.read('_test_sub.out')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_load_custom_commands_broken
|
81
|
+
Nanoc3::CLI.run %w( create_site foo )
|
82
|
+
|
83
|
+
FileUtils.cd('foo') do
|
84
|
+
# Create command
|
85
|
+
FileUtils.mkdir_p('commands')
|
86
|
+
File.open('commands/_test.rb', 'w') { |io| io.write('raise "meh"') }
|
87
|
+
|
88
|
+
# Run command
|
89
|
+
position_before = $stderr.tell
|
90
|
+
assert_raises SystemExit do
|
91
|
+
Nanoc3::CLI.run %w( _test )
|
92
|
+
end
|
93
|
+
position_after = $stderr.tell
|
94
|
+
|
95
|
+
# Check error output
|
96
|
+
stderr_addition = $stderr.string[position_before, position_after]
|
97
|
+
assert_match(/=== BACKTRACE:/, stderr_addition)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
40
101
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc3::CLI::ErrorHandlerTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc3::TestHelpers
|
6
|
+
|
7
|
+
def test_resolution_for_with_unknown_gem
|
8
|
+
error = LoadError.new('no such file to load -- afjlrestjlsgrshter')
|
9
|
+
assert_nil handler.send(:resolution_for, error)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_resolution_for_with_known_gem
|
13
|
+
$loud = true
|
14
|
+
error = LoadError.new('no such file to load -- kramdown')
|
15
|
+
assert_match /^Try installing /, handler.send(:resolution_for, error)
|
16
|
+
ensure
|
17
|
+
$loud = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_resolution_for_with_not_load_error
|
21
|
+
error = RuntimeError.new('nuclear meltdown detected')
|
22
|
+
assert_nil handler.send(:resolution_for, error)
|
23
|
+
end
|
24
|
+
|
25
|
+
def handler
|
26
|
+
Nanoc3::CLI::ErrorHandler.new
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
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.
|
5
|
+
version: 3.2.0b2
|
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-
|
13
|
+
date: 2011-07-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cri
|
@@ -23,6 +23,50 @@ dependencies:
|
|
23
23
|
version: "2.0"
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: minitest
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mocha
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rdiscount
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: yard
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id005
|
26
70
|
description: "nanoc is a simple but very flexible static site generator written in Ruby. It operates on local files, and therefore does not run on the server. nanoc \xE2\x80\x9Ccompiles\xE2\x80\x9D the local source files into HTML (usually), by evaluating eRuby, Markdown, etc."
|
27
71
|
email: denis.defreyne@stoneship.org
|
28
72
|
executables:
|
@@ -90,6 +134,7 @@ files:
|
|
90
134
|
- lib/nanoc3/cli/commands/update.rb
|
91
135
|
- lib/nanoc3/cli/commands/view.rb
|
92
136
|
- lib/nanoc3/cli/commands/watch.rb
|
137
|
+
- lib/nanoc3/cli/error_handler.rb
|
93
138
|
- lib/nanoc3/cli/logger.rb
|
94
139
|
- lib/nanoc3/cli.rb
|
95
140
|
- lib/nanoc3/data_sources/deprecated/delicious.rb
|
@@ -192,6 +237,7 @@ files:
|
|
192
237
|
- test/cli/commands/test_info.rb
|
193
238
|
- test/cli/commands/test_update.rb
|
194
239
|
- test/cli/test_cli.rb
|
240
|
+
- test/cli/test_error_handler.rb
|
195
241
|
- test/cli/test_logger.rb
|
196
242
|
- test/data_sources/test_filesystem.rb
|
197
243
|
- test/data_sources/test_filesystem_unified.rb
|