Class: PandaCms::DemoSiteGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/lib/panda_cms/demo_site_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDemoSiteGenerator

Returns a new instance of DemoSiteGenerator.



5
6
7
8
9
# File 'app/lib/panda_cms/demo_site_generator.rb', line 5

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

Instance Attribute Details

Returns the value of attribute menus.



3
4
5
# File 'app/lib/panda_cms/demo_site_generator.rb', line 3

def menus
  @menus
end

#pagesObject

Returns the value of attribute pages.



3
4
5
# File 'app/lib/panda_cms/demo_site_generator.rb', line 3

def pages
  @pages
end

#templatesObject

Returns the value of attribute templates.



3
4
5
# File 'app/lib/panda_cms/demo_site_generator.rb', line 3

def templates
  @templates
end

Instance Method Details

#create_menusHash

Creates initial menus

Returns:

  • (Hash)

    A hash containing the created menus



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/lib/panda_cms/demo_site_generator.rb', line 50

def create_menus
  @menus = {}
  @menus[:main] = PandaCms::Menu.find_or_create_by(name: "Main Menu")
  @menus[:footer] = PandaCms::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



35
36
37
38
39
40
41
42
43
44
# File 'app/lib/panda_cms/demo_site_generator.rb', line 35

def create_pages
  @pages[:home] = PandaCms::Page.find_or_create_by({path: "/", title: "Home", template: @templates[:homepage]})
  @pages[:about] = PandaCms::Page.find_or_create_by({path: "/about", title: "About", template: @templates[:page], parent: @pages[:home]})
  @pages[:terms] = PandaCms::Page.find_or_create_by({path: "/terms-and-conditions", title: "Terms & Conditions", template: @templates[:page], parent: @pages[:home], status: "hidden"})

  PandaCms::Page.reset_column_information
  PandaCms::Page.rebuild!

  @pages
end

#create_templatesObject

Creates initial templates and empty blocks

Returns:

  • void



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/lib/panda_cms/demo_site_generator.rb', line 15

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] = PandaCms::Template.find_or_create_by(template)
  end

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