Class: Noumenon::Core

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/noumenon/core.rb

Overview

The core Noumenon web application, responsible for loading content from the repository, and then either rendering it with the appropriate template, or passing it to the specified application.

Instance Method Summary collapse

Instance Method Details

#contentNoumenon::Repository

Convenience method to access the current content repository.

Returns:

  • (Noumenon::Repository)

    the current content repository



41
42
43
# File 'lib/noumenon/core.rb', line 41

def content
  Noumenon.content_repository
end

#render_page(page) ⇒ String

Renders a content item within it’s template and layout.

If the template or layout is not specified then it will be set to “default”.

Parameters:

  • page (Hash)

    The content item to render.

Options Hash (page):

  • :template (String)

    The template to use when rendering the item.

  • :layout (String)

    The layout to put the template within.

Returns:

  • (String)

    The rendered page, or an error message if any templates could not be rendered.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/noumenon/core.rb', line 20

def render_page(page)
  page[:template] ||= "default"
  page[:layout] ||= "default"

  begin
    template = Noumenon.theme.template("#{page[:template]}.nou.html")
    content = template.render(page)
    
    wrap_with_layout(content, page)
  rescue Noumenon::Template::NotFoundError => e
    halt 500, "<h1>Missing Template</h1><p>The template '#{page[:template]}' does not exist within the current theme.</p>"
  rescue Noumenon::Template::MissingContentError => e
    halt 500, "<h1>Missing Fields</h1><p>#{e}</p>"
  end
end