Sha256: c8734d11fa96c0c12d2f7b683fa2a1a2458d472e57a5f881b121bdd3c157ddf7

Contents?: true

Size: 611 Bytes

Versions: 1

Compression:

Stored size: 611 Bytes

Contents

require 'erb'

module Florby
  class Renderer
    DEFAULT_TEMPLATE = <<~ERB
      <html>
        <meta charset="utf-8">
        <body>
          <%= page.content %>
        </body>
      </html>
    ERB
    attr_reader :page, :collection

    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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
florby-0.1.0 lib/florby/renderer.rb