-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_layout.rb
More file actions
70 lines (58 loc) · 1.76 KB
/
default_layout.rb
File metadata and controls
70 lines (58 loc) · 1.76 KB
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
# frozen_string_literal: true
module TinyAdmin
module Views
class DefaultLayout < BasicLayout
attr_accessor :flash_component, :head_component, :messages, :navbar_component, :options, :title
def view_template
extra_styles = TinyAdmin.settings.extra_styles
flash_component&.messages = messages
head_component&.update_attributes(page_title: title, style_links: style_links, extra_styles: extra_styles)
doctype
html {
render head_component if head_component
body(class: body_class) {
render navbar_component if navbar_component
main_content {
render flash_component if flash_component
yield
}
render_scripts
}
}
end
private
def body_class
"module-#{self.class.to_s.split('::').last.downcase}"
end
def main_content
div(class: "container main-content py-4") do
if options&.include?(:compact_layout)
div(class: "row justify-content-center") {
div(class: "col-6") {
yield
}
}
else
yield
end
end
end
def style_links
TinyAdmin.settings.style_links || [
# Bootstrap CDN
{
href: "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css",
rel: "stylesheet",
integrity: "sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65",
crossorigin: "anonymous"
}
]
end
def render_scripts
(TinyAdmin.settings.scripts || []).each do |script_attrs|
script(**script_attrs)
end
end
end
end
end