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.

Direct Known Subclasses

Spec::ExampleApp

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Core

Returns a new instance of Core.



15
16
17
18
19
20
# File 'lib/noumenon/core.rb', line 15

def initialize(options = {})
  @options = default_options.merge(options.symbolize_keys)
  @options[:mount_point] ||= "/"
  
  super nil
end

Instance Method Details

#contentNoumenon::Repository

Convenience method to access the current content repository.

Returns:

  • (Noumenon::Repository)

    the current content repository



52
53
54
# File 'lib/noumenon/core.rb', line 52

def content
  Noumenon.content_repository
end

#default_optionsObject



11
12
13
# File 'lib/noumenon/core.rb', line 11

def default_options
  {}
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.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/noumenon/core.rb', line 31

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

#route_missingObject



69
70
71
72
73
74
75
# File 'lib/noumenon/core.rb', line 69

def route_missing
  if content && page = content.get(File.join(@options[:mount_point], @request.path_info))
    render_page(page)
  else
    halt 404, "<h1>Page Not Found</h1>"
  end 
end