Class: Brite::Layout

Inherits:
Model
  • Object
show all
Defined in:
lib/brite/layout.rb

Overview

Layout class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#[], #[]=, #config, #method_missing, #part, #rendering_fields, #to_binding, #to_h, #update

Constructor Details

#initialize(site, file) ⇒ Layout

Returns a new instance of Layout.



9
10
11
12
13
14
15
# File 'lib/brite/layout.rb', line 9

def initialize(site, file)
  @site = site
  @file = file

  @name = file.chomp('.layout')
  @path = File.expand_path(file)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Brite::Model

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



21
22
23
# File 'lib/brite/layout.rb', line 21

def file
  @file
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/brite/layout.rb', line 24

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/brite/layout.rb', line 27

def path
  @path
end

#siteObject (readonly)

Returns the value of attribute site.



18
19
20
# File 'lib/brite/layout.rb', line 18

def site
  @site
end

Instance Method Details

#render(model, &content) ⇒ Object

Render layout.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/brite/layout.rb', line 32

def render(model, &content)
  template = Neapolitan.file(path, :stencil=>site.config.stencil)

  # update the model's metadata
  #model.update(template.metadata)

  result = template.render(model, &content).to_s

  layout_name = template.['layout']

  if layout_name
    layout = site.lookup_layout(layout_name)

    raise "No such layout -- #{layout}" unless layout

    result = layout.render(model){ result }
  end

  result.to_s
end