Merge pull request #3 from JeanMertz/master

Add run_on option to specify when to run the rocco command
This commit is contained in:
John Bintz 2011-11-15 07:42:10 -08:00
commit 1c9a9fa9d8
3 changed files with 46 additions and 14 deletions

View File

@ -1,15 +1,21 @@
It's a [Guard](http://github.com/guard/guard) for the [Rocco](http://github.com/rtomayko/rocco) documentation system! It's a [Guard](http://github.com/guard/guard) for the [Rocco](http://github.com/rtomayko/rocco) documentation system!
guard 'rocco' do ``` ruby
# default values
guard 'rocco', :run_on => [:start, :change], :dir => 'doc', :stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css' do
watch(%r{^app/.*\.(rb|coffee)$}) watch(%r{^app/.*\.(rb|coffee)$})
watch(%r{^lib/.*\.rb$}) watch(%r{^lib/.*\.rb$})
end end
```
Options: Options:
* `:dir` specifies the output dir (default `doc`) * `:run_on` specifies when to update the docs
* `:stylesheet` specifies a custom stylesheet to use (default is * `:start` - run on all documentation when the guard starts
http://jashkenas.github.com/docco/resources/docco.css) * `:change` - run when watched files change
* `:reload` - run when the guard is reloaded
* `:all` - run when running all the guards
* `:dir` specifies the output dir
* `:stylesheet` specifies a custom stylesheet to use
`gem install guard-rocco` or Bundle it up with `gem 'guard-rocco'`. Then `guard init rocco`. Yeah! `gem install guard-rocco` or Bundle it up with `gem 'guard-rocco'`. Then `guard init rocco`. Yeah!

View File

@ -9,19 +9,27 @@ module Guard
def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})
super super
@options = { :dir => 'doc' }.merge(options) @options = options || {}
@dir = @options[:dir] || 'doc'
@run_on = @options[:run_on] || [:start, :change]
@run_on = [@run_on] unless @run_on.respond_to?(:include?)
end end
def start def start
UI.info "Guard::Rocco is waiting to build docs..." all_paths.each { |path| build(path) } if run_for? :start
end
def reload
all_paths.each { |path| build(path) } if run_for? :reload
end end
def run_all def run_all
all_paths.each { |path| build(path) } all_paths.each { |path| build(path) } if run_for? :all
end end
def run_on_change(paths = []) def run_on_change(paths = [])
paths.each { |path| build(path) } paths.each { |path| build(path) } if run_for? :change
end end
private private
@ -39,14 +47,18 @@ module Guard
end end
def filename_to_target(path) def filename_to_target(path)
File.join(@options[:dir], path).gsub(%r{\.[^\.]+$}, '.html') File.join(@dir, path).gsub(%r{\.[^\.]+$}, '.html')
end end
def rocco_options def rocco_options
opts = @options.dup opts = @options.dup
opts.delete(:dir) opts.delete(:dir)
opts.delete(:run_on)
opts opts
end end
end
end
def run_for? command
@run_on.include?(command)
end
end
end

View File

@ -36,5 +36,19 @@ describe Guard::Rocco do
File.file?(File.join(doc_dir, 'lib/guard/rocco.html')).should be_true File.file?(File.join(doc_dir, 'lib/guard/rocco.html')).should be_true
end end
end end
describe 'run options' do
it 'should allow array of symbols' do
guard = Guard::Rocco.new([], :run_on => [:start, :change])
guard.run_for?(:start).should be_true
guard.run_for?(:reload).should be_false
end
it 'should allow symbol' do
guard = Guard::RailsAssets.new([], :run_on => :start)
guard.run_for?(:start).should be_true
guard.run_for?(:reload).should be_false
end
end
end end