Class: Releaf::Builders::Page::LayoutBuilder
- Inherits:
-
Object
- Object
- Releaf::Builders::Page::LayoutBuilder
show all
- Includes:
- Base, Template
- Defined in:
- app/builders/releaf/builders/page/layout_builder.rb
Instance Attribute Summary
Attributes included from Template
#template
Instance Method Summary
collapse
Methods included from Template
#initialize
Methods included from Base
#default_translation_scope, #html_escape, #icon, #layout_settings, #locale_options, #resource_title, #safe_join, #t, #tag, #template_variable, #translate_locale, #wrapper
Instance Method Details
#apple_favicon(source, options = {}) ⇒ Object
143
144
145
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 143
def apple_favicon(source, options = {})
favicon(source, options.merge(rel: 'apple-touch-icon-precomposed', type: 'image/png'))
end
|
#assets(type, tag_method) ⇒ Object
60
61
62
63
64
65
66
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 60
def assets(type, tag_method)
safe_join do
send(type).collect do |asset|
template.send(tag_method, asset)
end
end
end
|
#assets_resolver ⇒ Object
97
98
99
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 97
def assets_resolver
Releaf::AssetsResolver
end
|
#body ⇒ Object
22
23
24
25
26
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 22
def body
tag(:body, body_atttributes) do
body_content{ yield } << assets(:javascripts, :javascript_include_tag)
end
end
|
#body_atttributes ⇒ Object
28
29
30
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 28
def body_atttributes
{class: body_classes, "data-settings-path" => settings_path}
end
|
#body_classes ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 68
def body_classes
list = []
list << "application-#{Rails.application.class.parent_name.downcase}"
list += controller_body_classes
list << "view-#{controller.active_view}" if controller.respond_to? :active_view
list << "side-compact" if layout_settings("releaf.side.compact")
list
end
|
#body_content(&block) ⇒ Object
36
37
38
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 36
def body_content(&block)
<< << tag(:main, id: "main", &block) << notifications
end
|
#content_type ⇒ Object
113
114
115
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 113
def content_type
meta(content: 'text/html; charset=utf-8', 'http-equiv': 'Content-Type')
end
|
#controller_body_classes ⇒ Object
83
84
85
86
87
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 83
def controller_body_classes
controller_classes.collect do|c_class|
"controller-" + c_class.name.gsub(/Controller$/, "").underscore.tr( '_/', '-' )
end
end
|
#controller_classes ⇒ Object
77
78
79
80
81
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 77
def controller_classes
ancestors = controller.class.ancestors.grep(Class)
slice_index = ancestors.index(Releaf::ActionController) || (ancestors.index(controller.class) + 1)
ancestors[0, slice_index].reverse
end
|
#controller_name ⇒ Object
93
94
95
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 93
def controller_name
params[:controller]
end
|
#csrf ⇒ Object
109
110
111
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 109
def csrf
template.csrf_meta_tags
end
|
#doctype ⇒ Object
12
13
14
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 12
def doctype
"<!DOCTYPE html>"
end
|
#favicon(source, options = {}) ⇒ Object
139
140
141
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 139
def favicon(source, options = {})
controller.view_context.favicon_link_tag(File.join(favicon_path, source), options)
end
|
#favicon_path ⇒ Object
127
128
129
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 127
def favicon_path
File.join('releaf', 'icons')
end
|
#favicons ⇒ Object
147
148
149
150
151
152
153
154
155
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 147
def favicons
[
apple_favicon("favicon.png"),
apple_favicon("apple-touch-icon-152x152-precomposed.png", sizes: "152x152"),
apple_favicon("apple-touch-icon-114x114-precomposed.png", sizes: "114x114"),
apple_favicon("apple-touch-icon-72x72-precomposed.png", sizes: "72x72"),
favicon("favicon.png", type: 'image/png', rel: 'icon'),
]
end
|
#head ⇒ Object
16
17
18
19
20
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 16
def head
tag(:head) do
head_blocks
end
end
|
#head_blocks ⇒ Object
89
90
91
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 89
def head_blocks
[title, content_type, favicons, ms_tile, assets(:stylesheets, :stylesheet_link_tag), csrf]
end
|
44
45
46
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 44
def
tag(:header, .new(template).output)
end
|
#javascripts ⇒ Object
105
106
107
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 105
def javascripts
assets_resolver.controller_assets(controller_name, :javascripts)
end
|
52
53
54
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 52
def
tag(:aside, .new(template).output)
end
|
117
118
119
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 117
def meta(options)
tag(:meta, nil, options)
end
|
#ms_tile ⇒ Object
157
158
159
160
161
162
163
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 157
def ms_tile
tile_path = ActionController::Base.helpers.image_path(File.join(ms_tile_path, 'msapplication-tile-144x144.png'))
[
meta(name: 'msapplication-TileColor', content: ms_tile_color),
meta(name: 'msapplication-TileImage', content: tile_path)
]
end
|
#ms_tile_color ⇒ Object
135
136
137
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 135
def ms_tile_color
'#151515'
end
|
#ms_tile_path ⇒ Object
131
132
133
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 131
def ms_tile_path
favicon_path
end
|
#notifications ⇒ Object
40
41
42
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 40
def notifications
tag(:div, nil, class: 'notifications', 'data' => {'close-text' => t("Close")})
end
|
#output(&block) ⇒ Object
6
7
8
9
10
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 6
def output(&block)
doctype.html_safe << tag(:html) do
head << body(&block)
end
end
|
#settings_path ⇒ Object
32
33
34
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 32
def settings_path
url_for(action: "store_settings", controller: "/releaf/root", only_path: true)
end
|
#stylesheets ⇒ Object
101
102
103
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 101
def stylesheets
assets_resolver.controller_assets(controller_name, :stylesheets)
end
|
#title ⇒ Object
121
122
123
124
125
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 121
def title
tag(:title) do
controller.page_title
end
end
|