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, #dependencies, #execute_shell, #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.



7
8
9
# File 'lib/awestruct/handlers/layout_handler.rb', line 7

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

Instance Method Details

#for_layout_chain(page, &block) ⇒ Object



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

def for_layout_chain(page, &block)
  current_page = page
  $LOG.debug "layout_chain for #{current_page.source_path}" if $LOG.debug?
  while ( ! ( current_page.nil? || current_page.layout.nil? ) )
    current_page = site.layouts.find_matching( current_page.layout, current_page.output_extension )
    $LOG.debug "found matching layout for #{current_page}" if $LOG.debug?
    if ( ! current_page.nil? )
      $LOG.debug "calling: #{block.inspect}" if $LOG.debug?
      block.call( current_page )
    end
  end
end

#inherit_front_matter(page) ⇒ Object



25
26
27
28
29
30
# File 'lib/awestruct/handlers/layout_handler.rb', line 25

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



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/awestruct/handlers/layout_handler.rb', line 11

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



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

def rendered_content(context, with_layouts=true)
  $LOG.debug "rendering content with layout #{with_layouts} for #{context.page.output_path}" if $LOG.debug?
  content = delegate.rendered_content( context, with_layouts )

  if ( with_layouts )
    $LOG.debug "calling for_layout_chain" if $LOG.debug?
    for_layout_chain(context.__effective_page || context.page) do |layout|
      context.content = content
      context.__effective_page = layout
      context[:__is_layout] = true
      content = layout.rendered_content( context, false )
    end
  end

  $LOG.debug "finished rendering content for #{context.page.output_path}" if $LOG.debug?
  content
end