guard-nanoc 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWQ4M2MyYjYwNzg2YmI4NThhNTcxZDMwM2U4MjUxY2UyY2UxOGI5Mw==
5
+ data.tar.gz: !binary |-
6
+ MzBjNmFjZTBmNDg5YmE4MTkwYjJkOTYxNWM2MDdiOGY4MWJiN2U2Nw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OGM3YWU0N2Y1MGRkOGRjNWQ3M2FhMjRkZTA1MmEzMWNjMTRjOTEzNWQ4MmRj
10
+ YjlmYjM4ZDg0OGZlOTFlZDk3Njg3N2QwOGRkOTlhNzQ5MDdjZDAwZWE2NzE3
11
+ OTg4ZjBlZDgzODYxNzFmYWE4MDY5ZGRiZGFiZDI1YzMyMWRhMjI=
12
+ data.tar.gz: !binary |-
13
+ OWNkMjdiN2EzMGU2YmE4NTFkNTc3YzgxYjlhNjJjMDUwZDIzZWMxZGQ0Yzlk
14
+ OTI0NGRjMmJjZjRlZThlYjQyZjQzZDgzZGRjNjg4YTk5NTA2Y2VjMjY4Yjc4
15
+ NWQ5NmU5MzBjNjgxOTU3NTIzZjBmMjY5ZjhmODUwMDAzYTE0ZjU=
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'guard'
6
+ gem 'nanoc'
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ guard-nanoc (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.0.9)
10
+ formatador (0.2.4)
11
+ guard (1.7.0)
12
+ formatador (>= 0.2.4)
13
+ listen (>= 0.6.0)
14
+ lumberjack (>= 1.0.2)
15
+ pry (>= 0.9.10)
16
+ thor (>= 0.14.6)
17
+ listen (0.7.3)
18
+ lumberjack (1.0.3)
19
+ method_source (0.8.1)
20
+ pry (0.9.12)
21
+ coderay (~> 1.0.5)
22
+ method_source (~> 0.8)
23
+ slop (~> 3.4)
24
+ rake (10.0.4)
25
+ slop (3.4.4)
26
+ thor (0.18.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bundler (~> 1.3)
33
+ guard
34
+ guard-nanoc!
35
+ rake
data/LICENSE CHANGED
@@ -1,20 +1,19 @@
1
- Copyright (c) 2010 Yann Lugrin
1
+ Copyright (c) 2013 Denis Defreyne
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
10
9
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
13
12
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Guard::Nanoc
2
+
3
+ This is a guard for [nanoc](http://nanoc.ws/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'guard-nanoc'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install guard-nanoc
18
+
19
+ ## Usage
20
+
21
+ Create a Guardfile using `guard init`:
22
+
23
+ $ guard init nanoc
24
+
25
+ Execute guard:
26
+
27
+ $ guard
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('../lib/', __FILE__))
4
+ require 'guard/nanoc/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'guard-nanoc'
8
+ s.version = Guard::Nanoc::VERSION
9
+ s.homepage = 'http://nanoc.ws/'
10
+ s.summary = 'guard gem for nanoc'
11
+ s.description = 'Automatically rebuilds nanoc sites'
12
+ s.license = 'MIT'
13
+
14
+ s.author = 'Denis Defreyne'
15
+ s.email = 'denis.defreyne@stoneship.org'
16
+
17
+ s.files = Dir['[A-Z]*'] + Dir['lib/**/*'] + [ 'guard-nanoc.gemspec' ]
18
+ s.require_paths = [ 'lib' ]
19
+ end
@@ -1,6 +1,5 @@
1
1
  guard 'nanoc' do
2
- watch('^config.yaml')
3
- watch('^Rules')
4
- watch('^layouts\/')
5
- watch('^content\/')
6
- end
2
+ watch('nanoc.yaml') # Change this to config.yaml if you use the old config file name
3
+ watch('Rules')
4
+ watch(%r{^(content|layouts|lib)/.*$})
5
+ end
@@ -1,6 +1,11 @@
1
1
  # encoding: utf-8
2
+
2
3
  module Guard
3
- module NanocVersion
4
- VERSION = '0.1.0'
4
+
5
+ module Nanoc
6
+
7
+ VERSION = '1.0.0'
8
+
5
9
  end
10
+
6
11
  end
data/lib/guard/nanoc.rb CHANGED
@@ -1,37 +1,88 @@
1
1
  # encoding: utf-8
2
+
2
3
  require 'guard'
3
4
  require 'guard/guard'
4
5
 
6
+ require 'nanoc'
7
+ require 'nanoc/cli'
8
+
5
9
  module Guard
6
- class Nanoc < Guard
7
10
 
8
- autoload :Runner, 'guard/nanoc/runner'
11
+ class Nanoc < Guard
9
12
 
10
- def initialize(watchers = [], options = {})
13
+ def initialize(watchers=[], options={})
14
+ @dir = options[:dir] || '.'
11
15
  super
12
-
13
- @runner = Runner.new(options)
14
16
  end
15
17
 
16
18
  def start
17
- true
19
+ self.setup_nanoc_notifications
20
+ self.recompile_in_subprocess
18
21
  end
19
22
 
20
- def stop
21
- true
23
+ def run_all
24
+ self.recompile
22
25
  end
23
26
 
24
- def reload
25
- true
27
+ def run_on_changes(paths)
28
+ self.recompile
26
29
  end
27
30
 
28
- def run_all
29
- @runner.run
31
+ def run_on_removals(paths)
32
+ self.recompile
30
33
  end
31
34
 
32
- def run_on_change(paths = [])
33
- @runner.run
35
+ protected
36
+
37
+ def setup_nanoc_notifications
38
+ @rep_times = {}
39
+ ::Nanoc::NotificationCenter.on(:compilation_started) do |rep|
40
+ @rep_times[rep.raw_path] = Time.now
41
+ end
42
+ ::Nanoc::NotificationCenter.on(:compilation_ended) do |rep|
43
+ @rep_times[rep.raw_path] = Time.now - @rep_times[rep.raw_path]
44
+ end
45
+ ::Nanoc::NotificationCenter.on(:rep_written) do |rep, path, is_created, is_modified|
46
+ action = (is_created ? :create : (is_modified ? :update : :identical))
47
+ level = (is_created ? :high : (is_modified ? :high : :low))
48
+ duration = Time.now - @rep_times[rep.raw_path] if @rep_times[rep.raw_path]
49
+ ::Nanoc::CLI::Logger.instance.file(level, action, path, duration)
50
+ end
51
+ end
52
+
53
+ def recompile_in_subprocess
54
+ if Process.respond_to?(:fork)
55
+ pid = Process.fork { self.recompile }
56
+ Process.waitpid(pid)
57
+ else
58
+ self.recompile
59
+ end
60
+ end
61
+
62
+ def recompile
63
+ Dir.chdir(@dir) do
64
+ site = ::Nanoc::Site.new('.')
65
+ site.compile
66
+ end
67
+ self.notify_success
68
+ rescue ::Nanoc::Errors::GenericTrivial => e
69
+ self.notify_failure
70
+ $stderr.puts e.message
71
+ rescue Exception => e
72
+ self.notify_failure
73
+ ::Nanoc::CLI::ErrorHandler.print_error(e)
74
+ end
75
+
76
+ def notify_success
77
+ Notifier.notify('Compilation succeeded', :title => 'nanoc', :image => :success)
78
+ ::Guard::UI.info 'Compilation succeeded.'
79
+ end
80
+
81
+ def notify_failure
82
+ Notifier.notify('Compilation FAILED', :title => 'nanoc', :image => :failed)
83
+ ::Guard::UI.error 'Compilation failed!'
34
84
  end
35
85
 
36
86
  end
87
+
37
88
  end
metadata CHANGED
@@ -1,142 +1,52 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guard-nanoc
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
13
- - Yann Lugrin
6
+ authors:
7
+ - Denis Defreyne
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-10-28 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: guard
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 21
30
- segments:
31
- - 0
32
- - 2
33
- - 1
34
- version: 0.2.1
35
- type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: nanoc
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 9
46
- segments:
47
- - 3
48
- - 1
49
- - 5
50
- version: 3.1.5
51
- type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: bundler
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 19
62
- segments:
63
- - 1
64
- - 0
65
- - 2
66
- version: 1.0.2
67
- type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 13
78
- segments:
79
- - 2
80
- - 0
81
- - 1
82
- version: 2.0.1
83
- type: :development
84
- version_requirements: *id004
85
- description: Guard::Nanoc automatically rebuilds nanoc site files when modified (like nanoc watch)
86
- email:
87
- - yann.lugrin@sans-savoir.net
11
+ date: 2013-04-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Automatically rebuilds nanoc sites
14
+ email: denis.defreyne@stoneship.org
88
15
  executables: []
89
-
90
16
  extensions: []
91
-
92
17
  extra_rdoc_files: []
93
-
94
- files:
95
- - lib/guard/nanoc.rb
96
- - lib/guard/nanoc/runners/default_nanoc_runner.rb
18
+ files:
19
+ - Gemfile
20
+ - Gemfile.lock
21
+ - LICENSE
22
+ - README.md
97
23
  - lib/guard/nanoc/templates/Guardfile
98
- - lib/guard/nanoc/notifier.rb
99
- - lib/guard/nanoc/runner.rb
100
24
  - lib/guard/nanoc/version.rb
101
- - LICENSE
102
- - README.rdoc
103
- has_rdoc: true
104
- homepage: http://rubygems.org/gems/guard-nanoc
105
- licenses: []
106
-
25
+ - lib/guard/nanoc.rb
26
+ - guard-nanoc.gemspec
27
+ homepage: http://nanoc.ws/
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
107
31
  post_install_message:
108
- rdoc_options:
109
- - --charset=UTF-8
110
- - --main=README.rdoc
111
- - --exclude='(lib|test|spec)|(Gem|Guard|Rake)file'
112
- require_paths:
32
+ rdoc_options: []
33
+ require_paths:
113
34
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
123
- required_rubygems_version: !ruby/object:Gem::Requirement
124
- none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 23
129
- segments:
130
- - 1
131
- - 3
132
- - 6
133
- version: 1.3.6
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
134
45
  requirements: []
135
-
136
- rubyforge_project: guard-nanoc
137
- rubygems_version: 1.3.7
46
+ rubyforge_project:
47
+ rubygems_version: 2.0.3
138
48
  signing_key:
139
- specification_version: 3
140
- summary: Guard gem for Nanoc
49
+ specification_version: 4
50
+ summary: guard gem for nanoc
141
51
  test_files: []
142
-
52
+ has_rdoc:
data/README.rdoc DELETED
@@ -1,52 +0,0 @@
1
- = Guard::Nanoc
2
-
3
- Nanoc guard automatically rebuilds nanoc site files when modified (like nanoc watch)
4
-
5
- - Compatible with Nanoc 3.1.x
6
- - Tested on Ruby 1.8.6, 1.8.7 & 1.9.2.
7
-
8
- == Install
9
-
10
- Please be sure to have {guard}[http://github.com/guard/guard] installed before continue.
11
-
12
- Install the gem:
13
-
14
- gem install guard-nanoc
15
-
16
- Add it to your Gemfile (inside test group):
17
-
18
- gem 'guard-nanoc'
19
-
20
- Add guard definition to your Guardfile by running this command:
21
-
22
- guard init nanoc
23
-
24
- == Usage
25
-
26
- Please read {guard usage doc}[http://github.com/guard/guard#readme]
27
-
28
- == Guardfile
29
-
30
- Nanoc guard can be really be adapated to all kind of projects.
31
- Please read {guard doc}[http://github.com/guard/guard#readme] for more info about Guardfile DSL.
32
-
33
- === Standard ruby gems
34
-
35
- guard 'nanoc' do
36
- watch('^config.yaml')
37
- watch('^Rules')
38
- watch('^layouts/*')
39
- watch('^content/**/*')
40
- end
41
-
42
- == Development
43
-
44
- - Source hosted at {GitHub}[http://github.com/guard/guard-nanoc]
45
- - Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/guard/guard-nanoc/issues]
46
-
47
- Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
48
- you make.
49
-
50
- == Authors
51
-
52
- {Yann Lugrin}[http://github.com/yannlugrin]
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
- require 'guard'
3
-
4
- module Guard
5
- class NanocNotifier
6
-
7
- def self.guard_message(result, created, updated, skipped, duration)
8
- message = ''
9
- if result
10
- message << "%d created, %d updated, %d skipped\nin %.1f seconds." % [created, updated, skipped, duration]
11
- else
12
- message << "Site can't be compiled,\nplease check."
13
- end
14
- message
15
- end
16
-
17
- # failed | success
18
- def self.guard_image(result)
19
- icon = if result
20
- :success
21
- else
22
- :failed
23
- end
24
- end
25
-
26
- def self.notify(result, created, updated, skipped, duration)
27
- message = guard_message(result, created, updated, skipped, duration)
28
- image = guard_image(result)
29
-
30
- ::Guard::Notifier.notify(message, :title => 'Nanoc site', :image => image)
31
- end
32
-
33
- end
34
- end
@@ -1,59 +0,0 @@
1
- # encoding: utf-8
2
- module Guard
3
- class Nanoc
4
- class Runner
5
- class << self
6
-
7
- def run(options = {})
8
- Runner.new(options).run
9
- end
10
-
11
- end
12
-
13
- def initialize(options = {})
14
- @options = {
15
- :bundler => File.exist?("#{Dir.pwd}/Gemfile"),
16
- :rubygems => false,
17
- :notify => true
18
- }.merge(options)
19
- end
20
-
21
- def run(options = {})
22
- message = options[:message] || 'Running Nanoc compiler'
23
- UI.info message, :reset => true
24
- system(nanoc_command)
25
- end
26
-
27
- def notify?
28
- @options[:notify]
29
- end
30
-
31
- def bundler?
32
- @options[:bundler]
33
- end
34
-
35
- def rubygems?
36
- !bundler? && @options[:rubygems]
37
- end
38
-
39
- private
40
-
41
- def nanoc_command
42
- cmd_parts = []
43
- cmd_parts << "bundle exec" if bundler?
44
- cmd_parts << 'ruby'
45
- cmd_parts << '-r rubygems' if rubygems?
46
- cmd_parts << '-r bundler/setup' if bundler?
47
- cmd_parts << "-r #{File.expand_path('../runners/default_nanoc_runner.rb', __FILE__)}"
48
- if notify?
49
- cmd_parts << '-e \'GUARD_NOTIFY=true; DefaultNanocRunner.run\''
50
- else
51
- cmd_parts << '-e \'GUARD_NOTIFY=false; DefaultNanocRunner.run\''
52
- end
53
- cmd_parts.join(' ')
54
- end
55
-
56
- end
57
- end
58
- end
59
-
@@ -1,161 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Some parts of this code come from Nanoc3 and is licenced under MIT
4
- # with copyright 2007-2010 Denis Defreyne and contributors
5
- #
6
- require 'nanoc3'
7
- require 'nanoc3/cli/logger'
8
- require 'guard/nanoc/notifier'
9
-
10
- class DefaultNanocRunner
11
- attr_reader :site, :compiled_reps, :skipped_reps
12
-
13
- class << self
14
-
15
- def run
16
- DefaultNanocRunner.new.run
17
- end
18
-
19
- end
20
-
21
- def initialize
22
- @site = Nanoc3::Site.new('.')
23
-
24
- @compiled_reps = 0
25
- @skipped_reps = 0
26
- @rep_times = {}
27
-
28
- setup_notifications
29
- end
30
-
31
- def run
32
- start_at = Time.now
33
-
34
- @created_reps = 0
35
- @updated_reps = 0
36
- @skipped_reps = 0
37
- @rep_times = {}
38
-
39
- begin
40
- puts 'Compiling site...'
41
- site.load_data
42
- site.compiler.run(nil, :force => false)
43
-
44
- # success
45
- reps = site.items.map { |i| i.reps }.flatten
46
-
47
- reps.select { |r| !r.compiled? }.each do |rep|
48
- next if rep.raw_path.nil?
49
- duration = @rep_times[rep.raw_path]
50
- Nanoc3::CLI::Logger.instance.file(:high, :skip, rep.raw_path, duration)
51
- @skipped_reps += 1
52
- end
53
-
54
- end_at = Time.now - start_at
55
- puts
56
- puts "Site compiled in %.2f seconds" % end_at
57
- Guard::NanocNotifier.notify(true, @created_reps, @updated_reps, @skipped_reps, end_at) if GUARD_NOTIFY
58
-
59
- rescue Exception => e
60
- # failure
61
- puts 'Failed to compile site'
62
- print_error(e)
63
- Guard::NanocNotifier.notify(false, 0, 0, 0, Time.now - start_at) if GUARD_NOTIFY
64
- end
65
-
66
- end
67
-
68
- private
69
-
70
- def setup_notifications
71
- Nanoc3::NotificationCenter.on(:compilation_started) do |rep|
72
- @rep_times[rep.raw_path] = Time.now
73
- end
74
-
75
- Nanoc3::NotificationCenter.on(:compilation_ended) do |rep|
76
- @rep_times[rep.raw_path] = Time.now - @rep_times[rep.raw_path]
77
-
78
- action = if rep.created?
79
- @created_reps += 1
80
- :create
81
- elsif rep.modified?
82
- @updated_reps += 1
83
- :update
84
- elsif !rep.compiled?
85
- nil
86
- else
87
- :identical
88
- end
89
-
90
- unless action.nil?
91
- duration = @rep_times[rep.raw_path]
92
- Nanoc3::CLI::Logger.instance.file(:high, action, rep.raw_path, duration)
93
- end
94
-
95
- end
96
- end
97
-
98
- def print_error(error)
99
- $stderr.puts
100
-
101
- # Header
102
- $stderr.puts '+--- /!\ ERROR /!\ -------------------------------------------+'
103
- $stderr.puts '| An exception occured while running nanoc. If you think this |'
104
- $stderr.puts '| is a bug in nanoc, please do report it at |'
105
- $stderr.puts '| <http://projects.stoneship.org/trac/nanoc/newticket> -- |'
106
- $stderr.puts '| thanks in advance! |'
107
- $stderr.puts '+-------------------------------------------------------------+'
108
-
109
- # Exception and resolution (if any)
110
- $stderr.puts
111
- $stderr.puts '=== MESSAGE:'
112
- $stderr.puts
113
- $stderr.puts "#{error.class}: #{error.message}"
114
- resolution = resolution_for(error)
115
- $stderr.puts "#{resolution}" if resolution
116
-
117
- # Compilation stack
118
- $stderr.puts
119
- $stderr.puts '=== COMPILATION STACK:'
120
- $stderr.puts
121
- if ((self.site && self.site.compiler.stack) || []).empty?
122
- $stderr.puts " (empty)"
123
- else
124
- self.site.compiler.stack.reverse.each do |obj|
125
- if obj.is_a?(Nanoc3::ItemRep)
126
- $stderr.puts " - [item] #{obj.item.identifier} (rep #{obj.name})"
127
- else # layout
128
- $stderr.puts " - [layout] #{obj.identifier}"
129
- end
130
- end
131
- end
132
-
133
- # Backtrace
134
- require 'enumerator'
135
- $stderr.puts
136
- $stderr.puts '=== BACKTRACE:'
137
- $stderr.puts
138
- $stderr.puts error.backtrace.to_enum(:each_with_index).map { |item, index| " #{index}. #{item}" }.join("\n")
139
- end
140
-
141
- def resolution_for(error)
142
- case error
143
- when LoadError
144
- # Get gem name
145
- lib_name = error.message.match(/no such file to load -- ([^\s]+)/)[1]
146
- gem_name = GEM_NAMES[$1]
147
-
148
- # Build message
149
- if gem_name
150
- "Try installing the '#{gem_name}' gem (`gem install #{gem_name}`) and then re-running the command."
151
- end
152
- when RuntimeError
153
- if error.message =~ /^can't modify frozen/
154
- "You attempted to modify immutable data. Some data, such as " \
155
- "item/layout attributes and raw item/layout content, can no " \
156
- "longer be modified once compilation has started."
157
- end
158
- end
159
- end
160
-
161
- end