Module: MegaBar::PageProcessing

Included in:
LayoutEngine
Defined in:
lib/mega_bar/page_processing.rb

Instance Method Summary collapse

Instance Method Details

#get_template_section(layout_section, page_layout) ⇒ Object



55
56
57
58
59
# File 'lib/mega_bar/page_processing.rb', line 55

def get_template_section(layout_section, page_layout)
  MegaBar::TemplateSection.find(
    layout_section.layables.where(layout_id: page_layout.id).first.template_section_id
  ).code_name
end

#process_layout_section(layout_section, page_layout, page_info, rout, orig_query_hash, pagination, site, env, final_layout_sections) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/mega_bar/page_processing.rb', line 44

def process_layout_section(layout_section, page_layout, page_info, rout, orig_query_hash, pagination, site, env, final_layout_sections)
  template_section = get_template_section(layout_section, page_layout)
  blocks = get_filtered_blocks(layout_section, rout, page_info)
  return unless blocks.present?

  final_layout_sections[template_section] = []
  env[:mega_layout_section] = layout_section
  
  process_blocks(blocks, page_info, rout, orig_query_hash, pagination, site, env, final_layout_sections, template_section)
end

#process_layouts(env, orig_query_hash) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mega_bar/page_processing.rb', line 16

def process_layouts(env, orig_query_hash)
  page_layouts = MegaBar::Layout.by_page(env[:mega_page][:page_id]).includes(:sites, :themes)
  final_layouts = []
  
  page_layouts.each do |page_layout|
    next if mega_filtered(page_layout, env[:mega_site])
    
    env[:mega_layout] = page_layout
    final_layout_sections = process_page_layout(page_layout, env[:mega_page], env[:mega_rout], orig_query_hash, env[:mega_pagination], env[:mega_site], env)
    
    env["mega_final_layout_sections"] = final_layout_sections
    @status, @headers, @layouts = MegaBar::MasterLayoutsController.action(:render_layout_with_sections).call(env)
    final_layouts << (@layouts.blank? ? "" : @layouts.body.html_safe)
  end
  
  final_layouts
end

#process_page_layout(page_layout, page_info, rout, orig_query_hash, pagination, site, env) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/mega_bar/page_processing.rb', line 34

def process_page_layout(page_layout, page_info, rout, orig_query_hash, pagination, site, env)
  final_layout_sections = {}
  
  page_layout.layout_sections.each do |layout_section|
    process_layout_section(layout_section, page_layout, page_info, rout, orig_query_hash, pagination, site, env, final_layout_sections)
  end
  
  final_layout_sections
end

#render_megabar_page(env) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/mega_bar/page_processing.rb', line 3

def render_megabar_page(env)
  orig_query_hash = Rack::Utils.parse_nested_query(env["QUERY_STRING"])
  final_layouts = process_layouts(env, orig_query_hash)
  
  env["mega_final_layouts"] = final_layouts
  @status, @headers, @page = MegaBar::MasterPagesController.action(:render_page).call(env)
  
  final_page_content = @page.blank? ? "" : @page.body.html_safe
  final_page = [final_page_content]
  
  @redirect ? [@redirect[0], @redirect[1], ["you are being redirected"]] : [@status, @headers, final_page]
end