Module: Vitreous::Share::Render

Defined in:
lib/vitreous/share/render.rb

Class Method Summary collapse

Class Method Details

.render(opts) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vitreous/share/render.rb', line 4

def self.render( opts )
  home    = Vitreous::Share::Element.new( opts[:index]['home'] )
  element = Vitreous::Share::IndexSearcher.search( home, opts[:resource] )
  status  = 200
  
  if element.nil?
    element = Vitreous::Share::Element.new( opts[:index]['not_found'] )
    status  = 404
  end
  
  Mustache.template_path = opts[:templates]
  
  body = 
    Mustache.render(
      File.read( "#{opts[:templates]}/layout.html" ),
      { 
        :home     => home, 
        :element  => element,
        :assets   => opts[:assets]
      }
    )
    
  OpenStruct.new(
    :status => status,
    :body   => body
  )
end