Class: Florby::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/florby/renderer.rb

Constant Summary collapse

DEFAULT_TEMPLATE =
<<~ERB
  <html>
    <meta charset="utf-8">
    <body>
      <%= page.content %>
    </body>
  </html>
ERB

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, collection:) ⇒ Renderer

Returns a new instance of Renderer.



15
16
17
18
19
20
21
22
# File 'lib/florby/renderer.rb', line 15

def initialize(page:, collection:)
  @page = page
  @collection = collection

  if File.exist?(File.join(Dir.pwd, 'layouts', "#{page.layout}.erb"))
    @layout = File.read(File.join(Dir.pwd, 'layouts', "#{page.layout}.erb"))
  end
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



13
14
15
# File 'lib/florby/renderer.rb', line 13

def collection
  @collection
end

#pageObject (readonly)

Returns the value of attribute page.



13
14
15
# File 'lib/florby/renderer.rb', line 13

def page
  @page
end

Instance Method Details

#renderObject



24
25
26
27
# File 'lib/florby/renderer.rb', line 24

def render
  erb = ERB.new(@layout || DEFAULT_TEMPLATE)
  erb.result(binding)
end