Class: Noumenon::Core
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Noumenon::Core
- 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
Instance Method Summary collapse
-
#content ⇒ Noumenon::Repository
Convenience method to access the current content repository.
- #default_options ⇒ Object
-
#initialize(options = {}) ⇒ Core
constructor
A new instance of Core.
-
#render_page(page) ⇒ String
Renders a content item within it’s template and layout.
- #route_missing ⇒ Object
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 = .merge(.symbolize_keys) @options[:mount_point] ||= "/" super nil end |
Instance Method Details
#content ⇒ Noumenon::Repository
Convenience method to access the current content repository.
52 53 54 |
# File 'lib/noumenon/core.rb', line 52 def content Noumenon.content_repository end |
#default_options ⇒ Object
11 12 13 |
# File 'lib/noumenon/core.rb', line 11 def {} 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”.
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_missing ⇒ Object
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 |