/
base.rb
139 lines (116 loc) · 3.79 KB
/
base.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
module ActiveAdmin
module Views
module Pages
class Base < Arbre::HTML::Document
def build(*args)
super
add_classes_to_body
build_active_admin_head
build_page
end
private
def add_classes_to_body
@body.add_class(params[:action])
@body.add_class(params[:controller].gsub('/', '_'))
@body.add_class("active_admin")
@body.add_class("logged_in")
@body.add_class(active_admin_namespace.name.to_s + "_namespace")
end
def build_active_admin_head
within @head do
insert_tag Arbre::HTML::Title, [title, render_or_call_method_or_proc_on(self, active_admin_application.site_title)].join(" | ")
active_admin_application.stylesheets.each do |style, options|
text_node stylesheet_link_tag(style, options).html_safe
end
active_admin_application.javascripts.each do |path|
text_node(javascript_include_tag(path))
end
if active_admin_application.favicon
text_node(favicon_link_tag(active_admin_application.favicon))
end
text_node csrf_meta_tag
end
end
def build_page
within @body do
div id: "wrapper" do
build_header
build_title_bar
build_page_content
build_footer
end
end
end
def build_header
insert_tag view_factory.header, active_admin_namespace, current_menu
end
def build_title_bar
insert_tag view_factory.title_bar, title, action_items_for_action
end
def build_page_content
build_flash_messages
div id: "active_admin_content", class: (skip_sidebar? ? "without_sidebar" : "with_sidebar") do
build_main_content_wrapper
build_sidebar unless skip_sidebar?
end
end
def build_flash_messages
if active_admin_flash_messages.any?
div class: 'flashes' do
active_admin_flash_messages.each do |type, message|
div message, class: "flash flash_#{type}"
end
end
end
end
def build_main_content_wrapper
div id: "main_content_wrapper" do
div id: "main_content" do
main_content
end
end
end
def main_content
I18n.t('active_admin.main_content', model: self.class.name).html_safe
end
def title
self.class.name
end
# Set's the page title for the layout to render
def set_page_title
set_ivar_on_view "@page_title", title
end
# Returns the sidebar sections to render for the current action
def sidebar_sections_for_action
if active_admin_config && active_admin_config.sidebar_sections?
active_admin_config.sidebar_sections_for(params[:action], self)
else
[]
end
end
def action_items_for_action
if active_admin_config && active_admin_config.action_items?
active_admin_config.action_items_for(params[:action], self)
else
[]
end
end
# Renders the sidebar
def build_sidebar
div id: "sidebar" do
sidebar_sections_for_action.collect do |section|
sidebar_section(section)
end
end
end
def skip_sidebar?
sidebar_sections_for_action.empty? || assigns[:skip_sidebar] == true
end
# Renders the content for the footer
def build_footer
insert_tag view_factory.footer
end
end
end
end
end