lib/awestruct/cli/auto.rb in awestruct-0.5.4.2 vs lib/awestruct/cli/auto.rb in awestruct-0.5.5

- old
+ new

@@ -1,9 +1,10 @@ require 'awestruct/util/exception_helper' require 'listen' require 'guard/livereload' +require 'compass' module Awestruct module CLI class Auto @@ -27,12 +28,13 @@ force_polling = ( RUBY_PLATFORM =~ /mingw/ ? true : false ) listener = Listen.to( @config.dir, :latency=>0.5, :force_polling=>force_polling ) do |modified, added, removed| modified.each do |path| # path is absolute path engine = ::Awestruct::Engine.instance - unless ( path =~ %r(#{File.basename( engine.config.output_dir) }) || path =~ /.awestruct/ ) + unless ( path =~ %r(#{File.basename( engine.config.output_dir) }) || path =~ /.awestruct/ || path =~ /sass-cache/ ) begin + $LOG.info "Change detected for file #{path}" if $LOG.info? if path.eql? current_path unless generate_thread.nil? $LOG.info "Same path triggered, stopping previous generation" if generate_thread.alive? && $LOG.info? generate_thread.kill end @@ -41,28 +43,32 @@ current_path = path end generate_thread = Thread.new { begin - - # TODO: Have to figure something out for extensions and other files without an output path - # Probably add another method in engin to to do the regen w/o mucking with site.pages and run through things again - page = engine.page_by_output_path(path) - if ( page ) - pages = engine.generate_page_and_dependencies( page ) - - if ( guard ) - urls = pages.map do |p| - @base_url + p.url.to_s + if ( File.extname(path) == '.sass' || File.extname(path) == '.scss' ) + ::Compass::Commands::UpdateProject.new(engine.site.dir, {}).perform + else + page = engine.page_by_output_path(path) + pages = [] + if ( page ) + pages = engine.generate_page_and_dependencies( page ) + else + if File.exist? path + # chances are this is an extension or yaml file + pages = engine.run_auto_for_non_page(path) end - - guard.run_on_modifications(urls) end + end - $LOG.info "Regeneration finished." if $LOG.info? + $LOG.info "Regeneration finished." if $LOG.info? - else - $LOG.error "Failed to find page from path #{path}" + if ( guard ) + urls = pages.map do |p| + @base_url + p.url.to_s + end + + guard.run_on_modifications(urls) end rescue => e ExceptionHelper.log_building_error e, path end