2011-06-17 20:01:49 +00:00
|
|
|
require 'rocco'
|
|
|
|
require 'guard/guard'
|
2011-06-18 19:33:21 +00:00
|
|
|
require 'fileutils'
|
2011-06-17 20:01:49 +00:00
|
|
|
|
|
|
|
module Guard
|
|
|
|
class Rocco < Guard
|
|
|
|
def initialize(watchers = [], options = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
@options = { :dir => 'doc' }.merge(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
UI.info "Guard::Rocco is waiting to build docs..."
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_all
|
|
|
|
all_paths.each { |path| build(path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_on_change(paths = [])
|
|
|
|
paths.each { |path| build(path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2011-06-18 16:33:23 +00:00
|
|
|
def build(path, target = nil)
|
2011-06-18 19:33:21 +00:00
|
|
|
target ||= filename_to_target(path)
|
2011-06-17 20:01:49 +00:00
|
|
|
puts "rocco: #{path} -> #{target}"
|
2011-06-18 19:33:21 +00:00
|
|
|
FileUtils.mkdir_p File.split(target).first
|
2011-06-17 20:01:49 +00:00
|
|
|
File.open(target, 'wb') { |fh| fh.print ::Rocco.new(path, all_paths).to_html }
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_paths
|
|
|
|
Watcher.match_files(self, Dir['**/*'])
|
|
|
|
end
|
2011-06-18 16:33:23 +00:00
|
|
|
|
2011-06-18 19:33:21 +00:00
|
|
|
def filename_to_target(path)
|
2011-06-18 16:33:23 +00:00
|
|
|
File.join(@options[:dir], path).gsub(%r{\.[^\.]+$}, '.html')
|
|
|
|
end
|
2011-06-17 20:01:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|