Class: Stic::Layout

Inherits:
Object
  • Object
show all
Includes:
Metadata, Readable, Renderable, SiteBase
Defined in:
lib/stic/layout.rb

Overview

Stic::Layout

A Layout allows to wrap a blob into a layout. The rendered layout itself my be wrapped into another layout.

Instance Attribute Summary

Attributes included from Readable

#name, #path, #source

Attributes included from SiteBase

#data, #site

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metadata

#initialize, parse, parsers

Methods included from Renderable

#locals, #render_content, #renderer

Methods included from Readable

#content, #initialize, #read, #source_path

Methods included from SiteBase

#initialize

Class Method Details

.load(site, source, config) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/stic/layout.rb', line 44

def load(site, source, config)
  layouts = {}

  source.join(config['layouts'] || 'layouts').glob('*').each do |path|
    next unless path.file?

    layouts[path.pure_name] = new site: site, source: path
  end

  layouts
end

Instance Method Details

#layoutObject



25
26
27
# File 'lib/stic/layout.rb', line 25

def layout
  @layout ||= layout_name.blank? ? nil : site.layout(layout_name)
end

#layout_nameObject

Return name of layout this layout should be wrapped in.



31
32
33
# File 'lib/stic/layout.rb', line 31

def layout_name
  data[:layout]
end

#render(blob, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/stic/layout.rb', line 15

def render(blob, &block)
  locals = blob.locals.merge(data: data)

  if layout
    layout.render(blob) { render_content(locals, &block) }
  else
    render_content locals, &block
  end
end

#render_nameObject



35
36
37
# File 'lib/stic/layout.rb', line 35

def render_name
  @path.basename
end

#to_sObject



39
40
41
# File 'lib/stic/layout.rb', line 39

def to_s
  "#<#{self.class.name}:#{object_id} #{source_path}>"
end