Class: Brut::FrontEnd::Page
- Includes:
- HandlingResults
- Defined in:
- lib/brut/front_end/page.rb
Overview
A Page backs a web page, which handles rendering everything in a browser window when a URL is requested.
Technically, a page is identical to a Component, except that a page has a layout.
A Layout is common HTML that surrounds your page's HTML.
Your page is a Phlex component, but instead of implementing view_template
, you
implement #page_template to ensure the layout is used.
To create a page, after defining a route, subclass this class (or, more likely, your app's AppPage
) and
provide an initializer that accepts keyword arguments. The names of these arguments will be used to locate the
values that Brut will pass in when creating your page object.
Consult Brut's documentation on keyword injection to know what values you may use and how values are located.
Direct Known Subclasses
Class Method Summary collapse
-
.page_name ⇒ String
Name of this page for use in debugging or for whatever reason you may want to dynamically refer to the page's name.
Instance Method Summary collapse
-
#before_generate ⇒ URI|Brut::FrontEnd::HttpStatus|Object
Called after the page is created, but before #page_template is called.
-
#handle! ⇒ Object
Core method of this class.
-
#layout ⇒ String
Returns the name of the layout for this page.
-
#page_name ⇒ Object
Convienience method for Page.page_name.
-
#page_template ⇒ Object
Override this method to produce your page's HTML.
-
#view_template ⇒ Object
Phlex's API to produce markup.
Methods included from HandlingResults
Methods inherited from Component
component_name, #component_name
Methods included from Component::Helpers
#global_component, #inline_svg
Methods included from I18n::ForHTML
Methods included from I18n::BaseMethods
#l, #t, #t_direct, #this_field_value
Methods included from Brut::Framework::Errors
Class Method Details
.page_name ⇒ String
Returns name of this page for use in debugging or for whatever reason you may want to dynamically refer to the page's name. The default value is the class name.
70 |
# File 'lib/brut/front_end/page.rb', line 70 def self.page_name = self.name |
Instance Method Details
#before_generate ⇒ URI|Brut::FrontEnd::HttpStatus|Object
Called after the page is created, but before #page_template is called. This allows you to do any pre-flight checks and potentially redirect the user or produce an error.
38 |
# File 'lib/brut/front_end/page.rb', line 38 def before_generate = nil |
#handle! ⇒ Object
Core method of this class. Do not override. This handles the use of #before_generate and is what Brut calls to possibly render the page.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/brut/front_end/page.rb', line 42 def handle! case before_generate in URI => uri uri in Brut::FrontEnd::HttpStatus => http_status http_status else self.call end end |
#layout ⇒ String
Returns the name of the layout for this page. This string is used to find a class named
«camelized-layout»Layout
in your app. The default value is "default", meaning that the class
DefaultLayout
will be used.
Note that the layout can be dynamic. It is requested when #page_template is called, so you can override this method and use any ivar set in your constructor to change what layout is used.
If your page does not need a layout, you have two options:
- Create your own blank layout named, e.g.
BlankLayout
and have this method return"blank"
. - Implement
view_template
instead ofpage_template
, thus overriding this class' implementation that uses layouts.
32 |
# File 'lib/brut/front_end/page.rb', line 32 def layout = "default" |
#page_name ⇒ Object
Convienience method for page_name.
73 |
# File 'lib/brut/front_end/page.rb', line 73 def page_name = self.class.page_name |
#page_template ⇒ Object
Override this method to produce your page's HTML. You are intended to call Phlex
methods here. Anything you can do inside the Phlex-standard view_template
method, you can
do here. The only difference is that this will all be rendered in the context of your configured
#layout.
57 |
# File 'lib/brut/front_end/page.rb', line 57 def page_template = abstract_method! |
#view_template ⇒ Object
Phlex's API to produce markup. Do not override this or you will lose your layout. This implementation locates the configured layout, renders it, and renders #page_template inside.
62 63 64 65 66 |
# File 'lib/brut/front_end/page.rb', line 62 def view_template with_layout do page_template end end |