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
157
158
159
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 157
def apple_favicon(source, options = {})
favicon(source, options.merge(rel: 'apple-touch-icon-precomposed', type: 'image/png'))
end
|
#assets(type, tag_method) ⇒ Object
74
75
76
77
78
79
80
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 74
def assets(type, tag_method)
safe_join do
send(type).collect do |asset|
template.send(tag_method, asset)
end
end
end
|
#assets_resolver ⇒ Object
111
112
113
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 111
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
safe_join{ body_content_blocks{ yield } }
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, "data-layout-features" => features.join(" ")}
end
|
#body_classes ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 82
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_blocks ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 40
def body_content_blocks
parts = []
parts << if feature_available?(:header)
parts << if feature_available?(:sidebar)
parts << tag(:main, id: :main){ yield } if feature_available?(:main)
parts << notifications
parts << assets(:javascripts, :javascript_include_tag)
parts
end
|
#content_type ⇒ Object
127
128
129
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 127
def content_type
meta(content: 'text/html; charset=utf-8', 'http-equiv': 'Content-Type')
end
|
#controller_body_classes ⇒ Object
97
98
99
100
101
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 97
def controller_body_classes
controller_classes.collect do|c_class|
"controller-" + c_class.name.gsub(/Controller$/, "").underscore.tr( '_/', '-' )
end
end
|
#controller_classes ⇒ Object
91
92
93
94
95
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 91
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
107
108
109
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 107
def controller_name
params[:controller]
end
|
#csrf ⇒ Object
123
124
125
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 123
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
153
154
155
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 153
def favicon(source, options = {})
controller.view_context.favicon_link_tag(File.join(favicon_path, source), options)
end
|
#favicon_path ⇒ Object
141
142
143
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 141
def favicon_path
File.join('releaf', 'icons')
end
|
#favicons ⇒ Object
161
162
163
164
165
166
167
168
169
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 161
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
|
#feature_available?(feature) ⇒ Boolean
36
37
38
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 36
def feature_available?(feature)
features.include? feature
end
|
#features ⇒ Object
70
71
72
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 70
def features
controller.layout_features
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
103
104
105
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 103
def head_blocks
[title, content_type, favicons, ms_tile, assets(:stylesheets, :stylesheet_link_tag), csrf]
end
|
54
55
56
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 54
def
tag(:header, .new(template).output)
end
|
#javascripts ⇒ Object
119
120
121
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 119
def javascripts
assets_resolver.controller_assets(controller_name, :javascripts)
end
|
62
63
64
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 62
def
tag(:aside, .new(template).output)
end
|
131
132
133
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 131
def meta(options)
tag(:meta, nil, options)
end
|
#ms_tile ⇒ Object
171
172
173
174
175
176
177
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 171
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
149
150
151
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 149
def ms_tile_color
'#151515'
end
|
#ms_tile_path ⇒ Object
145
146
147
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 145
def ms_tile_path
favicon_path
end
|
#notifications ⇒ Object
50
51
52
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 50
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
115
116
117
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 115
def stylesheets
assets_resolver.controller_assets(controller_name, :stylesheets)
end
|
#title ⇒ Object
135
136
137
138
139
|
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 135
def title
tag(:title) do
controller.page_title
end
end
|