lib/awestruct/dependencies.rb in awestruct-0.4.8 vs lib/awestruct/dependencies.rb in awestruct-0.5.0.cr

- old
+ new

@@ -25,41 +25,43 @@ @pages ||= [] @pages.first end def self.push_page(page) - #puts "push #{page.output_path}" + $LOG.debug "push #{page.output_path}" if $LOG.debug? if ( top_page.nil? ) + $LOG.debug "clearing dependencies" if $LOG.debug? page.dependencies.clear else + $LOG.debug "adding page as a dependency to top_page" if $LOG.debug? top_page.dependencies.add_dependency( page ) end @pages.push( page ) end def self.pop_page page = @pages.pop - #puts "pop #{page.output_path} #{@pages.empty?}" + $LOG.debug "pop #{page.output_path} #{@pages.empty?}" if $LOG.debug? if ( @pages.empty? && ! page.nil? ) page.dependencies.persist! end end def self.track_dependency(dep) return if top_page.nil? return if top_page == dep - #puts "dep #{top_page.relative_source_path} - #{dep.relative_source_path}" + $LOG.debug "dep #{top_page.relative_source_path} - #{dep.relative_source_path}" if $LOG.debug? top_page.dependencies.add_dependency(dep) end def self.track_key_dependency(dep, key) return if !Awestruct::Dependencies.should_track_dependencies return if top_page.nil? return if top_page == dep - #puts "dep key #{top_page.relative_source_path} - #{dep.relative_source_path} -> #{key}" - #puts Kernel.caller(4)[0] + $LOG.debug "dep key #{top_page.relative_source_path} - #{dep.relative_source_path} -> #{key}" if $LOG.debug? + $LOG.debug "callers #{Kernel.caller}" if $LOG.debug? top_page.dependencies.add_key_dependency(dep) end def initialize(page) @@ -73,11 +75,11 @@ @has_changed_content = false @has_changed_keys = false end def key_hash=(key) - #puts "key_hash #{key}" + $LOG.debug "key_hash #{key}" if $LOG.debug? if @key_hash.nil? @has_changed_keys = false else if key.eql? @key_hash @has_changed_keys = false @@ -87,11 +89,11 @@ end @key_hash = key end def content_hash=(key) - #puts "content_hash #{key}" + $LOG.debug "content_hash #{key}" if $LOG.debug? if @content_hash.nil? @has_changed_content = false else if key.eql? @content_hash @has_changed_content = false @@ -108,10 +110,11 @@ def add_dependency(dep) return if @page.do_not_track_dependencies return if @page.output_path.nil? return if dep == @page + $LOG.debug "adding dependency #{dep.source_path} to #{page.source_path}" if $LOG.debug? @dependencies << dep dep.dependencies.add_dependent( page ) end def add_key_dependency(dep) @@ -139,12 +142,12 @@ @dependents.each{|d| d.remove_dependent( page ) } end def persist! return if page.output_path.nil? || page.output_path == '' - file = File.join( @page.site.config.dir, '.awestruct', 'dependency-cache', page.output_path ) - #puts "store #{file}" + file = File.join( @page.site.config.dir.to_s, '.awestruct', 'dependency-cache', page.output_path ) + $LOG.debug "store #{file}" if $LOG.debug? FileUtils.mkdir_p( File.dirname( file ) ) File.open( file, 'w' ) do |file| file.puts "ch:#{@content_hash}" file.puts "kh:#{@key_hash}" @dependencies.collect{|e| e.relative_source_path }.uniq.each do |d| @@ -157,13 +160,13 @@ end def load! return if page.output_path.nil? || page.output_path == '' file = File.join( @page.site.config.dir, '.awestruct', 'dependency-cache', page.output_path ) - #puts "load #{file}" + $LOG.debug "load #{file}" if $LOG.debug? if ( File.exist?( file ) ) File.open( file, 'r' ) do |file| - file.lines.each do |line| + file.each_line do |line| type, path = line.split(':') path ||= "" path.strip! if type.eql? 'c' or type.eql? 'k' d = find_page_by_path( path )