From c0234b835d5f703a28816081ceff7511d193549e Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Sun, 13 Nov 2011 14:07:19 +0100 Subject: [PATCH 1/6] Allow for run_on: [:start, :reload, :all, :change] option --- lib/guard/rocco.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/guard/rocco.rb b/lib/guard/rocco.rb index ada419d..d5842d1 100644 --- a/lib/guard/rocco.rb +++ b/lib/guard/rocco.rb @@ -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 - -- 2.45.2 From 5411646f44cd86af5a405c87e933474d1b79565d Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Sun, 13 Nov 2011 14:16:09 +0100 Subject: [PATCH 2/6] Add run options tests --- spec/lib/guard/rocco_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/lib/guard/rocco_spec.rb b/spec/lib/guard/rocco_spec.rb index cab5520..a1c4a69 100644 --- a/spec/lib/guard/rocco_spec.rb +++ b/spec/lib/guard/rocco_spec.rb @@ -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 -- 2.45.2 From 48f92f4452464e4bbd8d0a73ce51f2955973b3a0 Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Sun, 13 Nov 2011 14:28:15 +0100 Subject: [PATCH 3/6] Update documentation to tidy things up and explain run_all option --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b34c01c..2aed4dc 100644 --- a/README.md +++ b/README.md @@ -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 - watch(%r{^app/.*\.(rb|coffee)$}) - watch(%r{^lib/.*\.rb$}) - end - +``` ruby +# default values +guard 'rocco', :run_all => [:start, :change], :dir => 'doc', :stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css' do + watch(%r{^app/.*\.(rb|coffee)$}) + watch(%r{^lib/.*\.rb$}) +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! -- 2.45.2 From dee529853352c186ce1346d5a48ccb9d00148ccd Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Sun, 13 Nov 2011 14:29:24 +0100 Subject: [PATCH 4/6] add all default options to the Guard template --- lib/guard/rocco/templates/Guardfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guard/rocco/templates/Guardfile b/lib/guard/rocco/templates/Guardfile index 36cc21a..af71055 100644 --- a/lib/guard/rocco/templates/Guardfile +++ b/lib/guard/rocco/templates/Guardfile @@ -1,4 +1,4 @@ -guard 'rocco' do +guard 'rocco', :run_all => [:start, :change], :dir => 'doc', :stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css' do # For Rails 3.0.x and 3.1 watch(%r{^app/.*\.(rb|coffee)$}) watch(%r{^lib/.*\.rb$}) -- 2.45.2 From 2ad80d4aebfd0539dc797e91ea626f0d8eadde8e Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Mon, 14 Nov 2011 10:56:36 +0100 Subject: [PATCH 5/6] Fix typo: run_all should be run_on --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2aed4dc..6a332a4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ It's a [Guard](http://github.com/guard/guard) for the [Rocco](http://github.com/ ``` ruby # default values -guard 'rocco', :run_all => [:start, :change], :dir => 'doc', :stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css' do +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 -- 2.45.2 From 76f781ec0899d096703baac260a77cbcc72713ed Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Mon, 14 Nov 2011 10:57:41 +0100 Subject: [PATCH 6/6] Revert always showing default values. it's a preference of mine, but I guess we shouldn't bother people with long lines of code when they are the default anyway. --- lib/guard/rocco/templates/Guardfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guard/rocco/templates/Guardfile b/lib/guard/rocco/templates/Guardfile index af71055..36cc21a 100644 --- a/lib/guard/rocco/templates/Guardfile +++ b/lib/guard/rocco/templates/Guardfile @@ -1,4 +1,4 @@ -guard 'rocco', :run_all => [:start, :change], :dir => 'doc', :stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css' do +guard 'rocco' do # For Rails 3.0.x and 3.1 watch(%r{^app/.*\.(rb|coffee)$}) watch(%r{^lib/.*\.rb$}) -- 2.45.2