# Loads the site data. This will query the Nanoc::DataSource associated
# with the site and fetch all site data. The site data is cached, so
# calling this method will not have any effect the second time, unless
# +force+ is true.
## +force+:: If true, will force load the site data even if it has been
# loaded before, to circumvent caching issues.
defload_data(force=false)# Don't load data twice
returnif@data_loadedand!force
log(:low,"Loading data...")# Load data
@data_source.loading do
# Code
@code=@data_source.code
@code.site =self# FIXME move responsibility for loading site code elsewhere, so
# potentially dangerous code can be put in a sandbox.
@code.load
# Pages
@pages=@data_source.pages
@pages.each {|p| p.site =self}# Page defaults
@page_defaults=@data_source.page_defaults
@page_defaults.site =self# Layouts
@layouts=@data_source.layouts
@layouts.each {|l| l.site =self}# Templates
@templates=@data_source.templates
@templates.each {|t| t.site =self}end# Setup child-parent links
@pages.each do |page|# Get parent
parent_path = page.path.sub(/[^\/]+\/$/,'')
parent =@pages.find {|p| p.path == parent_path }nextif parent.nil? or page.path =='/'# Link
page.parent = parent
parent.children << page
end# Set loaded
@data_loaded=trueend