lib/awestruct/engine.rb in awestructx-0.4.0 vs lib/awestruct/engine.rb in awestructx-0.4.1.x1
- old
+ new
@@ -8,10 +8,11 @@
require 'awestruct/page_loader'
require 'awestruct/extensions/pipeline'
require 'fileutils'
+require 'set'
class OpenStruct
def inspect
"OpenStruct{...}"
end
@@ -36,29 +37,44 @@
Engine.instance = self
@site = Site.new( self, config)
@pipeline = Pipeline.new
@site_page_loader = PageLoader.new( @site )
@layout_page_loader = PageLoader.new( @site, :layouts )
- adjust_load_path
end
def config
site.config
end
def run(profile, base_url, default_base_url, force=false)
+ adjust_load_path
load_site_yaml(profile)
set_base_url( base_url, default_base_url )
load_yamls
load_pipeline
load_pages
execute_pipeline
configure_compass
set_urls( site.pages )
+ build_page_index
generate_output
end
+ def build_page_index
+ site.pages_by_relative_source_path = {}
+ site.pages.each do |p|
+ if ( p.relative_source_path )
+ site.pages_by_relative_source_path[ p.relative_source_path ] = p
+ end
+ end
+ site.layouts.each do |p|
+ if ( p.relative_source_path )
+ site.pages_by_relative_source_path[ p.relative_source_path ] = p
+ end
+ end
+ end
+
def set_base_url(base_url, default_base_url)
if ( base_url )
site.base_url = base_url
end
@@ -189,30 +205,50 @@
def generate_output
@site.pages.each do |page|
generated_path = File.join( site.config.output_dir, page.output_path )
if ( page.stale_output?( generated_path ) )
generate_page( page, generated_path )
+ else
+ generate_page( page, generated_path, false )
end
end
end
- def generate_page(page, generated_path)
- puts "Generating: #{generated_path}"
- FileUtils.mkdir_p( File.dirname( generated_path ) )
- File.open( generated_path, 'w' ) do |file|
- file << page.rendered_content
+ def generate_page(page, generated_path, produce_output=true)
+ if ( produce_output )
+ puts "Generating: #{generated_path}"
+ FileUtils.mkdir_p( File.dirname( generated_path ) )
+ File.open( generated_path, 'w' ) do |file|
+ file << page.rendered_content
+ end
+ elsif ( site.config.track_dependencies )
+ if page.dependencies.load!
+ puts "Cached: #{generated_path}"
+ else
+ puts "Analyzing: #{generated_path}"
+ page.rendered_content
+ end
end
end
def generate_page_by_output_path(path)
full_path = File.join( '', path )
- #puts "regen path #{full_path}"
- page = site.pages.find{|p| p.relative_source_path.to_s==full_path}
- if ( page.nil? )
- #puts "Unable to locate page for #{path}"
- else
- generated_path = File.join( site.config.output_dir, page.output_path )
- generate_page(page, generated_path)
+ page = site.pages.find{|p| p.relative_source_path.to_s==full_path} || site.layouts.find{|p| p.relative_source_path.to_s==full_path}
+ return if page.nil?
+
+ #puts "regen page #{page.inspect}"
+ #puts "page.dependents #{page.dependencies.dependents.inspect}"
+
+ regen_pages = Set.new
+ regen_pages << page unless ( page.output_path.nil? )
+ regen_pages += page.dependencies.dependents
+
+ #puts regen_pages.collect{|e|e.output_path}.inspect
+ regen_pages.each do |p|
+ unless ( p.output_path.nil? || p.__is_layout )
+ generated_path = File.join( site.config.output_dir, p.output_path )
+ generate_page( p, generated_path )
+ end
end
end
####
##