Class: Awestruct::Handlers::LayoutHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/awestruct/handlers/layout_handler.rb

Instance Attribute Summary

Attributes inherited from BaseHandler

#delegate, #site

Instance Method Summary collapse

Methods inherited from BaseHandler

#content_line_offset, #content_syntax, #front_matter, #output_extension, #output_filename, #output_path, #path, #raw_content, #relative_source_path, #simple_name, #stale?, #to_chain

Constructor Details

#initialize(site, delegate) ⇒ LayoutHandler

Returns a new instance of LayoutHandler.



10
11
12
# File 'lib/awestruct/handlers/layout_handler.rb', line 10

def initialize(site, delegate)
  super( site, delegate )
end

Instance Method Details

#for_layout_chain(page, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/awestruct/handlers/layout_handler.rb', line 35

def for_layout_chain(page, &block)
  # puts "for_layout_chain #{page.inspect}" 
  current_page = page 
  while ( ! ( current_page.nil? || current_page.layout.nil? ) )
    current_page = site.layouts.find_matching( current_page.layout, current_page.output_extension )
    # puts "layout #{current_page.inspect}" 
    if ( ! current_page.nil? )
      block.call( current_page )
    end
  end
end

#inherit_front_matter(page) ⇒ Object



28
29
30
31
32
33
# File 'lib/awestruct/handlers/layout_handler.rb', line 28

def inherit_front_matter(page)
  delegate.inherit_front_matter( page )
  for_layout_chain(page) do |layout|
    page.inherit_front_matter_from( layout )
  end 
end

#input_mtime(page) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/awestruct/handlers/layout_handler.rb', line 14

def input_mtime(page)
  t = delegate.input_mtime( page )
  for_layout_chain(page) do |layout|
    layout_mtime = layout.input_mtime
    if ( t == nil )
      t = layout_mtime
    elsif ( layout_mtime > t )
      t = layout_mtime
    end
  end
  page_mtime = delegate.input_mtime( page )
  t
end

#rendered_content(context, with_layouts = true) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/awestruct/handlers/layout_handler.rb', line 47

def rendered_content(context, with_layouts=true)
  content = delegate.rendered_content( context, with_layouts )

  if ( with_layouts ) 
    for_layout_chain(context.__effective_page || context.page) do |layout|
      context.content = content
      context.__effective_page = layout
      content = layout.rendered_content( context, false )
     end
  end

  content
end