class Middleman::Sitemap::Extensions::OnDisk
def initialize(sitemap)
def initialize(sitemap) @sitemap = sitemap @app = @sitemap.app @file_paths_on_disk = Set.new scoped_self = self @waiting_for_ready = true # Register file change callback @app.files.changed do |file| scoped_self.touch_file(file, !scoped_self.waiting_for_ready) end # Register file delete callback @app.files.deleted do |file| scoped_self.remove_file(file, !scoped_self.waiting_for_ready) end @app.ready do scoped_self.waiting_for_ready = false scoped_self.sitemap.rebuild_resource_list!(:on_disk_ready) end end
def manipulate_resource_list(resources)
-
(void)
-
def manipulate_resource_list(resources) resources + @file_paths_on_disk.map do |file| ::Middleman::Sitemap::Resource.new( @sitemap, @sitemap.file_to_path(file), File.expand_path(file, @app.root) ) end end
def remove_file(file, rebuild=true)
-
(void)
-
Parameters:
-
file
(String
) --
def remove_file(file, rebuild=true) if @file_paths_on_disk.delete?(file) @sitemap.rebuild_resource_list!(:removed_file) if rebuild end end
def touch_file(file, rebuild=true)
-
(Boolean)
-
Parameters:
-
file
(String
) --
def touch_file(file, rebuild=true) return false if file == @app.source_dir || File.directory?(file) path = @sitemap.file_to_path(file) return false unless path ignored = @app.ignored_sitemap_matchers.any? do |name, callback| callback.call(file, path) end @file_paths_on_disk << file unless ignored # Rebuild the sitemap any time a file is touched # in case one of the other manipulators # (like asset_hash) cares about the contents of this file, # whether or not it belongs in the sitemap (like a partial) @sitemap.rebuild_resource_list!(:touched_file) if rebuild end