lib/jekyll/watcher.rb in jekyll-watch-2.0.0 vs lib/jekyll/watcher.rb in jekyll-watch-2.1.0

- old
+ new

@@ -28,60 +28,59 @@ Jekyll.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'" unless options["serving"] trap("INT") do listener.stop - puts " Halting auto-regeneration." + Jekyll.logger.info "", "Halting auto-regeneration." exit 0 end sleep_forever end rescue ThreadError # You pressed Ctrl-C, oh my! end private + def build_listener(site, options) Listen.to( options["source"], :ignore => listen_ignore_paths(options), :force_polling => options["force_polling"], &listen_handler(site) ) end - private def listen_handler(site) proc do |modified, added, removed| t = Time.now - c = modified + added + removed + c = normalize_encoding(modified + added + removed, site.source.encoding) n = c.length + Jekyll.logger.info "Regenerating:", - "#{n} file(s) changed at #{t.strftime("%Y-%m-%d %H:%M:%S")}" + "#{n} file(s) changed at #{t.strftime("%Y-%m-%d %H:%M:%S")}" - c.map { |path| path.sub("#{site.source}/", "") }.each do |file| - Jekyll.logger.info "", file - end - + c.each { |path| Jekyll.logger.info "", path.sub("#{source_path}/", "") } process(site, t) end end - private + def normalize_encoding(list, desired_encoding) + list.map { |entry| entry.encode!(desired_encoding, entry.encoding) } + end + def custom_excludes(options) Array(options["exclude"]).map { |e| Jekyll.sanitized_path(options["source"], e) } end - private def config_files(options) %w(yml yaml toml).map do |ext| Jekyll.sanitized_path(options["source"], "_config.#{ext}") end end - private def to_exclude(options) [ config_files(options), options["destination"], custom_excludes(options), @@ -91,18 +90,18 @@ # Paths to ignore for the watch option # # options - A Hash of options passed to the command # # Returns a list of relative paths from source that should be ignored - private def listen_ignore_paths(options) source = Pathname.new(options["source"]).expand_path paths = to_exclude(options) paths.map do |p| absolute_path = Pathname.new(p).expand_path next unless absolute_path.exist? + begin relative_path = absolute_path.relative_path_from(source).to_s unless relative_path.start_with?("../") path_to_ignore = Regexp.new(Regexp.escape(relative_path)) Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}" @@ -112,23 +111,21 @@ # Could not find a relative path end end.compact + [%r!\.jekyll\-metadata!] end - private def sleep_forever loop { sleep 1000 } end - private def process(site, time) begin site.process Jekyll.logger.info "", "...done in #{Time.now - time} seconds." rescue => e Jekyll.logger.warn "Error:", e.message Jekyll.logger.warn "Error:", "Run jekyll build --trace for more information." end - puts "" + Jekyll.logger.info "" end end end