Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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.
def load_data(force=false)
  # Don't load data twice
  return if @data_loaded and !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 }
    next if parent.nil? or page.path == '/'

    # Link
    page.parent = parent
    parent.children << page
  end

  # Set loaded
  @data_loaded = true
end