-
Notifications
You must be signed in to change notification settings - Fork 2
/
with_type.rb
125 lines (102 loc) · 3.09 KB
/
with_type.rb
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
module Communication::Website::Page::WithType
extend ActiveSupport::Concern
included do
# Types are listed in the order we want them to be created
TYPES = [
# Home always first
Communication::Website::Page::Home,
# Global objects
Communication::Website::Page::CommunicationPost,
Communication::Website::Page::CommunicationAgenda,
Communication::Website::Page::CommunicationAgendaArchive,
Communication::Website::Page::CommunicationPortfolio,
Communication::Website::Page::Person,
Communication::Website::Page::Organization,
# Education
Communication::Website::Page::EducationDiploma,
Communication::Website::Page::EducationProgram,
# Research
Communication::Website::Page::ResearchVolume,
Communication::Website::Page::ResearchPaper,
Communication::Website::Page::ResearchPublication,
# Administration
Communication::Website::Page::AdministrationLocation,
# People facets
Communication::Website::Page::Administrator,
Communication::Website::Page::Author,
Communication::Website::Page::Researcher,
Communication::Website::Page::Teacher,
# Legal pages always at the end
Communication::Website::Page::LegalTerm,
Communication::Website::Page::PrivacyPolicy,
Communication::Website::Page::Accessibility,
Communication::Website::Page::Sitemap
]
before_validation :initialize_special_page, on: :create, if: :is_special_page?
end
# Communication::Website::Page::CommunicationPosts -> communication_posts
# Used for i18n
def type_key
type.demodulize.underscore
end
def is_home?
type == 'Communication::Website::Page::Home'
end
def is_special_page?
type.present?
end
def is_regular_page?
type.blank?
end
def is_necessary_for_website?
true
end
def is_listed_among_children?
true
end
def editable_width?
true
end
def full_width_by_default?
false
end
def published_by_default?
true
end
# Can it be unpublished?
def draftable?
true
end
# All special pages are undeletable
def deletable?
is_regular_page?
end
# Some pages need a specific Hugo layout
def static_layout
nil
end
def default_menu_identifier
'primary'
end
def generate_from_template
end
protected
def default_parent
website.special_page(Communication::Website::Page::Home, language: language)
end
def initialize_special_page
i18n_key = "communication.website.pages.defaults.#{type_key}"
self.title = I18n.t("#{i18n_key}.title", locale: language.iso_code)
self.slug = I18n.t("#{i18n_key}.slug", locale: language.iso_code)
self.parent = default_parent
self.full_width = full_width_by_default?
self.published = published_by_default?
# note: published_at will be set by WithPublication concern
end
def generate_heading(title)
headings.create(university: university, title: title)
end
def generate_block(heading, kind, data)
blocks.create(university: university, heading: heading, template_kind: kind, data: data.to_json)
end
end