Class: Panda::CMS::DemoSiteGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/panda/cms/demo_site_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDemoSiteGenerator

Returns a new instance of DemoSiteGenerator.



8
9
10
11
12
# File 'lib/panda/cms/demo_site_generator.rb', line 8

def initialize
  @menus = {}
  @pages = {}
  @templates = {}
end

Instance Attribute Details

Returns the value of attribute menus.



6
7
8
# File 'lib/panda/cms/demo_site_generator.rb', line 6

def menus
  @menus
end

#pagesObject

Returns the value of attribute pages.



6
7
8
# File 'lib/panda/cms/demo_site_generator.rb', line 6

def pages
  @pages
end

#templatesObject

Returns the value of attribute templates.



6
7
8
# File 'lib/panda/cms/demo_site_generator.rb', line 6

def templates
  @templates
end

Instance Method Details

#create_menusHash

Creates initial menus

Returns:

  • (Hash)

    A hash containing the created menus



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/panda/cms/demo_site_generator.rb', line 75

def create_menus
  @menus = {}
  @menus[:main] = Panda::CMS::Menu.find_or_create_by(name: "Main Menu")
  @menus[:footer] = Panda::CMS::Menu.find_or_create_by(name: "Footer Menu")

  # Automatically create main menu from homepage
  unless @pages[:home].nil?
    @menus[:main].update(kind: :auto, start_page: @pages[:home], depth: 1)
    @menus[:main].generate_auto_menu_items
  end

  @menus
end

#create_pagesHash

Creates initial pages

Returns:

  • (Hash)

    A hash containing the created pages



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/panda/cms/demo_site_generator.rb', line 38

def create_pages
  @pages[:home] = Panda::CMS::Page.find_or_create_by({
    path: "/",
    title: "Home",
    panda_cms_template_id: @templates[:homepage].id
  })
  @pages[:about] = Panda::CMS::Page.find_or_create_by({
    path: "/about",
    title: "About",
    panda_cms_template_id: @templates[:page].id,
    parent: @pages[:home]
  })
  @pages[:not_found] = Panda::CMS::Page.find_or_create_by({
    path: "/404",
    title: "Page Not Found",
    panda_cms_template_id: @templates[:page].id,
    parent: @pages[:home],
    status: "hidden"
  })
  @pages[:internal_error] = Panda::CMS::Page.find_or_create_by({
    path: "/500",
    title: "Internal Server Error",
    panda_cms_template_id: @templates[:page].id,
    parent: @pages[:home],
    status: "hidden"
  })

  Panda::CMS::Page.reset_column_information
  Panda::CMS::Page.rebuild!

  @pages
end

#create_templatesObject

Creates initial templates and empty blocks

Returns:

  • void



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/panda/cms/demo_site_generator.rb', line 18

def create_templates
  # Templates
  initial_templates = [
    {name: "Homepage", file_path: "layouts/homepage"},
    {name: "Page", file_path: "layouts/page"}
  ]

  initial_templates.each do |template|
    key = template[:name].downcase.to_sym
    @templates[key] = Panda::CMS::Template.find_or_create_by(template)
  end

  @templates[:homepage].update(max_uses: 1)
  @templates
end