lib/awestruct/cli/auto.rb in awestruct-0.4.2.x6 vs lib/awestruct/cli/auto.rb in awestruct-0.4.2.x7

- old
+ new

@@ -1,34 +1,37 @@ -require 'guard/awestruct' +#require 'guard/awestruct' +require 'listen' + module Awestruct module CLI class Auto def initialize(config) @config = config end def run() - Guard.setup - Guard.start( :guardfile_contents=>guardfile_contents, - :watchdir=>@config.dir, - :watch_all_modifications=>true ) + listener = Listen.to( @config.dir, :relative_paths=>true ) + listener.ignore( %r(\.awestruct) ) + listener.ignore( %r(^#{File.basename( @config.tmp_dir )}) ) + listener.ignore( %r(^#{File.basename( @config.output_dir )}) ) + listener.change do |modified, added, removed| + puts "modified #{modified.inspect}" + puts "added #{added.inspect}" + puts "removed #{removed.inspect}" + modified.each do |path| + engine = ::Awestruct::Engine.instance + puts "path -> #{path}" + puts "bn -> #{File.basename( engine.config.output_dir )}" + unless ( path =~ %r(#{File.basename( engine.config.output_dir) }) || path =~ /.awestruct/ ) + engine.generate_page_by_output_path( path ) + end + end + end + listener.start( false ) end - def guardfile_contents - ignored = [ - "'.awestruct'", - "'#{File.basename( @config.tmp_dir )}'", - "'#{File.basename( @config.output_dir )}'", - ] - c = '' - c += "guard :awestruct do\n" - c += " watch %r(.*)\n" - c += " ignore_paths #{ignored.join(', ')}" - c += "end\n" - c - end end end end