guard-nanoc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +52 -0
- data/lib/guard/nanoc.rb +37 -0
- data/lib/guard/nanoc/notifier.rb +34 -0
- data/lib/guard/nanoc/runner.rb +59 -0
- data/lib/guard/nanoc/runners/default_nanoc_runner.rb +161 -0
- data/lib/guard/nanoc/templates/Guardfile +6 -0
- data/lib/guard/nanoc/version.rb +6 -0
- metadata +142 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Yann Lugrin
|
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:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
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]
|
data/lib/guard/nanoc.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'guard'
|
3
|
+
require 'guard/guard'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class Nanoc < Guard
|
7
|
+
|
8
|
+
autoload :Runner, 'guard/nanoc/runner'
|
9
|
+
|
10
|
+
def initialize(watchers = [], options = {})
|
11
|
+
super
|
12
|
+
|
13
|
+
@runner = Runner.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def reload
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_all
|
29
|
+
@runner.run
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_on_change(paths = [])
|
33
|
+
@runner.run
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
@@ -0,0 +1,59 @@
|
|
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
|
+
|
@@ -0,0 +1,161 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
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
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Yann Lugrin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
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
|
88
|
+
executables: []
|
89
|
+
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
extra_rdoc_files: []
|
93
|
+
|
94
|
+
files:
|
95
|
+
- lib/guard/nanoc.rb
|
96
|
+
- lib/guard/nanoc/runners/default_nanoc_runner.rb
|
97
|
+
- lib/guard/nanoc/templates/Guardfile
|
98
|
+
- lib/guard/nanoc/notifier.rb
|
99
|
+
- lib/guard/nanoc/runner.rb
|
100
|
+
- 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
|
+
|
107
|
+
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:
|
113
|
+
- 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
|
134
|
+
requirements: []
|
135
|
+
|
136
|
+
rubyforge_project: guard-nanoc
|
137
|
+
rubygems_version: 1.3.7
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: Guard gem for Nanoc
|
141
|
+
test_files: []
|
142
|
+
|