diff --git a/features/clean_build.feature b/features/clean_build.feature index 88056495..268d65db 100644 --- a/features/clean_build.feature +++ b/features/clean_build.feature @@ -7,3 +7,14 @@ Feature: Build Clean Then "should_be_ignored.html" should not exist at "clean-app" And "should_be_ignored2.html" should not exist at "clean-app" And "should_be_ignored3.html" should not exist at "clean-app" + + Scenario: Clean an app with directory indexes + Given a built app at "clean-dir-app" + Then "about/index.html" should exist at "clean-dir-app" + Given a built app at "clean-dir-app" with flags "--clean" + Then "about/index.html" should exist at "clean-dir-app" + Then cleanup built app at "clean-dir-app" + + Scenario: Clean build an app that's never been built + Given a built app at "clean-dir-app" with flags "--clean" + Then "about/index.html" should exist at "clean-dir-app" diff --git a/fixtures/clean-dir-app/config.rb b/fixtures/clean-dir-app/config.rb new file mode 100644 index 00000000..2cc4c97d --- /dev/null +++ b/fixtures/clean-dir-app/config.rb @@ -0,0 +1,2 @@ + +activate :directory_indexes diff --git a/fixtures/clean-dir-app/source/about.html b/fixtures/clean-dir-app/source/about.html new file mode 100644 index 00000000..ae84f243 --- /dev/null +++ b/fixtures/clean-dir-app/source/about.html @@ -0,0 +1 @@ +Fun times diff --git a/lib/middleman/builder.rb b/lib/middleman/builder.rb index 23ef2a21..9bee25d6 100644 --- a/lib/middleman/builder.rb +++ b/lib/middleman/builder.rb @@ -30,6 +30,8 @@ module Middleman # @private module ThorActions + # Render a template to a file. + # @return [String] the actual destination file path that was created def tilt_template(source, *args, &block) config = args.last.is_a?(Hash) ? args.pop : {} destination = args.first || source @@ -41,6 +43,8 @@ module Middleman response = ::Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20")) create_file(destination, response.body, config) if response.status == 200 + + destination # rescue # say_status :error, destination, :red # end @@ -130,11 +134,11 @@ module Middleman def queue_current_paths @cleaning_queue = [] Find.find(@destination) do |path| - next if path.match(/\/\./) + next if path.match(/\/\./) && !path.match(/\.htaccess/) unless path == destination @cleaning_queue << path.sub(@destination, destination[/([^\/]+?)$/]) end - end + end if File.exist?(@destination) end def execute! @@ -154,7 +158,7 @@ module Middleman file_source = path file_destination = File.join(given_destination, file_source.gsub(source, '.')) file_destination.gsub!('/./', '/') - + if @app.sitemap.generic?(file_source) # no-op elsif @app.sitemap.proxied?(file_source) @@ -163,14 +167,14 @@ module Middleman next end - @cleaning_queue.delete(file_destination) if cleaning? - if @config[:glob] next unless File.fnmatch(@config[:glob], file_source) end - base.tilt_template(file_source, file_destination, { :force => true }) + file_destination = base.tilt_template(file_source, file_destination, { :force => true }) + + @cleaning_queue.delete(file_destination) if cleaning? end end end -end \ No newline at end of file +end