-
Notifications
You must be signed in to change notification settings - Fork 11
/
layout_builder.rb
101 lines (82 loc) · 2.07 KB
/
layout_builder.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
class Releaf::Builders::Page::LayoutBuilder
include Releaf::Builders::Base
include Releaf::Builders::Template
def output(&block)
doctype.html_safe << tag(:html) do
head << body{ yield }
end
end
def doctype
"<!DOCTYPE html>"
end
def head
tag(:head) do
head_blocks
end
end
def body(&block)
tag(:body, class: body_classes) do
body_content{ yield } << assets(:javascripts, :javascript_include_tag)
end
end
def body_content(&block)
if access_control.authorized?
header << menu << tag(:main, id: "main"){ yield } << notifications
else
yield
end
end
def notifications
tag(:div, nil, class: "notifications", 'data-close-text' => t(:close, scope: "admin.global"))
end
def header
tag(:header, header_builder.new(template).output)
end
def header_builder
Releaf::Builders::Page::HeaderBuilder
end
def menu
tag(:aside, menu_builder.new(template).output)
end
def menu_builder
Releaf::Builders::Page::MenuBuilder
end
def assets(type, tag_method)
safe_join do
send(type).collect do |asset|
template.send(tag_method, asset)
end
end
end
def body_classes
list = []
list << "application-#{Rails.application.class.parent_name.downcase}"
list << "controller-#{params[:controller].tr( '_/', '-' )}"
list << "view-#{controller.active_view}" if controller.respond_to? :active_view
list << "side-compact" if layout_settings("releaf.side.compact")
list
end
def head_blocks
[title, meta, assets(:stylesheets, :stylesheet_link_tag), csrf]
end
def controller_name
params[:controller]
end
def stylesheets
Releaf::AssetsResolver.controller_assets(controller_name, :stylesheets)
end
def javascripts
Releaf::AssetsResolver.controller_assets(controller_name, :javascripts)
end
def csrf
template.csrf_meta_tags
end
def meta
tag(:meta, nil, content: "text/html; charset=utf-8", "http-equiv" => "Content-Type")
end
def title
tag(:title) do
controller.page_title
end
end
end