class Middleman::Sources
def watch(type_or_handler, options={})
def watch(type_or_handler, options={}) handler = if type_or_handler.is_a? Symbol SourceWatcher.new(self, type_or_handler, options.delete(:path), options) else type_or_handler end @watchers << handler # The index trick is used so that the sort is stable - watchers with the same priority # will always be ordered in the same order as they were registered. n = 0 @sorted_watchers = @watchers.sort_by do |w| priority = w.options.fetch(:priority, 50) n += 1 [priority, n] end.reverse.freeze handler.on_change(&method(:did_change)) if @running handler.poll_once! handler.listen! end handler end