Class: Releaf::Builders::Page::LayoutBuilder

Inherits:
Object
  • Object
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_resolverObject



111
112
113
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 111

def assets_resolver
  Releaf::AssetsResolver
end

#bodyObject



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_atttributesObject



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_classesObject



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_blocksObject



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 << header if feature_available?(:header)
  parts << menu 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_typeObject



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_classesObject



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_classesObject



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_nameObject



107
108
109
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 107

def controller_name
  params[:controller]
end

#csrfObject



123
124
125
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 123

def csrf
  template.csrf_meta_tags
end

#doctypeObject



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_pathObject



141
142
143
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 141

def favicon_path
  File.join('releaf', 'icons')
end

#faviconsObject



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

Returns:

  • (Boolean)


36
37
38
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 36

def feature_available?(feature)
  features.include? feature
end

#featuresObject



70
71
72
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 70

def features
  controller.layout_features
end

#headObject



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_blocksObject



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

#headerObject



54
55
56
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 54

def header
  tag(:header, header_builder.new(template).output)
end

#header_builderObject



58
59
60
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 58

def header_builder
  Releaf::Builders::Page::HeaderBuilder
end

#javascriptsObject



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 menu
  tag(:aside, menu_builder.new(template).output)
end


66
67
68
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 66

def menu_builder
  Releaf::Builders::Page::MenuBuilder
end

#meta(options) ⇒ Object



131
132
133
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 131

def meta(options)
  tag(:meta, nil, options)
end

#ms_tileObject



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_colorObject



149
150
151
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 149

def ms_tile_color
  '#151515'
end

#ms_tile_pathObject



145
146
147
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 145

def ms_tile_path
  favicon_path
end

#notificationsObject



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_pathObject



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

#stylesheetsObject



115
116
117
# File 'app/builders/releaf/builders/page/layout_builder.rb', line 115

def stylesheets
  assets_resolver.controller_assets(controller_name, :stylesheets)
end

#titleObject



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