Add run_on option to specify when to run the rocco command #3

Merged
JeanMertz merged 6 commits from master into master 2011-11-15 15:42:10 +00:00
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!
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{^lib/.*\.rb$})
end
end
```
Options:
* `:dir` specifies the output dir (default `doc`)
* `:stylesheet` specifies a custom stylesheet to use (default is
http://jashkenas.github.com/docco/resources/docco.css)
* `:run_on` specifies when to update the docs
* `:start` - run on all documentation when the guard starts
* `: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!

View File

@ -9,19 +9,27 @@ module Guard
def initialize(watchers = [], options = {})
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
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
def run_all
all_paths.each { |path| build(path) }
all_paths.each { |path| build(path) } if run_for? :all
end
def run_on_change(paths = [])
paths.each { |path| build(path) }
paths.each { |path| build(path) } if run_for? :change
end
private
@ -39,14 +47,18 @@ module Guard
end
def filename_to_target(path)
File.join(@options[:dir], path).gsub(%r{\.[^\.]+$}, '.html')
File.join(@dir, path).gsub(%r{\.[^\.]+$}, '.html')
end
def rocco_options
opts = @options.dup
opts.delete(:dir)
opts.delete(:run_on)
opts
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
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