Class: PageStructureMigration

Inherits:
Migration
  • Object
show all
Defined in:
lib/migrations/site/02_page_structure.rb

Class Method Summary collapse

Class Method Details

.down(site) ⇒ Object



55
56
57
# File 'lib/migrations/site/02_page_structure.rb', line 55

def self.down(site)
  site.pages.all.each(&:destroy)
end

.up(site) ⇒ Object



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
# File 'lib/migrations/site/02_page_structure.rb', line 2

def self.up(site)
  # remove the default home page
  home = site.pages.where(path: '/').first
  home.destroy
  
  # home redirects to users
  home = site.redirect_pages.new
  home.title = 'Home'
  home.url = '/users'
  home.save
  
  # sites
  # work around eigenmodel/record_class_name bug
  site.record_proxy_pages.create_model :sites_page do |sites_pages|
    sites_pages.record_class_name = 'ProductionSitesPage'
  end
  sites = site.sites_pages.new
  sites.title = 'Sites'
  sites.parent = home
  sites.page_layout = 'sites'
  sites.show_record_layout = 'site'
  sites.save
  
  # users
  users = site.pages.new
  users.title = 'Users'
  users.parent = home
  users.page_layout = 'users'
  users.save
  users.create_eigenmodel
  users.model.default_child_model = site.users
  users.model.save
  
  # git
  site.glob_pages.create_model :git_page do |git_pages|
    git_pages.record_class_name = 'GitPage'
  end
  git = site.git_pages.new
  git.title = "git"
  git.parent = home
  git.save
  
  # menu
  nav = site.menus.new
  nav.name = 'nav'
  nav.root = home
  ge = nav.exceptions.new
  ge.page = git
  ge.show = false
  ge.save
  nav.save
end