-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
base.rb
168 lines (143 loc) · 4.56 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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("logged_in")
@body.add_class(active_admin_namespace.name.to_s + "_namespace")
end
def build_active_admin_head
within @head do
meta :"http-equiv" => "Content-type", :content => "text/html; charset=utf-8"
insert_tag Arbre::HTML::Title, [title, active_admin_application.site_title].join(" | ")
active_admin_application.stylesheets.each do |style|
text_node(stylesheet_link_tag(style.path, style.options).html_safe)
end
active_admin_application.javascripts.each do |path|
script :src => javascript_path(path), :type => "text/javascript"
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
div :id => "header" do
render view_factory.header
end
end
def build_title_bar
div :id => "title_bar" do
build_titlebar_left
build_titlebar_right
end
end
def build_titlebar_left
div :id => "titlebar_left" do
build_breadcrumb
build_title_tag
end
end
def build_titlebar_right
div :id => "titlebar_right" do
build_action_items
end
end
def build_breadcrumb(separator = "/")
links = breadcrumb_links
return if links.empty?
span :class => "breadcrumb" do
links.each do |link|
text_node link
span(separator, :class => "breadcrumb_sep")
end
end
end
def build_title_tag
h2(title, :id => 'page_title')
end
def build_action_items
if active_admin_config && active_admin_config.action_items?
items = active_admin_config.action_items_for(params[:action], self)
insert_tag view_factory.action_items, items
end
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 flash.keys.any?
div :class => 'flashes' do
flash.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
# 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
div :id => "footer" do
para "Powered by #{link_to("Active Admin", "http://www.activeadmin.info")} #{ActiveAdmin::VERSION}".html_safe
end
end
end
end
end
end