Module: Arbre::Rails::Layouts

Defined in:
lib/arbre/rails/layouts.rb

Overview

Provides a content-template / layout-template construct to be used with Arbre.

The idea is that the ‘content’ view defines the type of document to use, through the ContextMethods#document method, and that the ‘layout’ view/views provide post-processing steps to the document, and subsequently render the document class.

Usage example

*app/views/session/new.html.arb:*

document LoginScreen do
  ...
end

*app/views/layouts/application.html.arb:*

layout do
  self.title = "#{self.title} | Application Name"
end

In this case, the content template (session/new.html.arb) defines that the content document should be a LoginScreen class, and provides a block to customize the screen.

The layout template (layouts/application.html.arb) provides some common steps that should be applied to all pages using this layout. This block is executed after the content customization block.

Content block

The content block that is specified will be passed to the document class’ build method, meaning that it can be used to customize the document in place. However, if the block is not used by the class, it is “instance-exec’d” on the document instance, so that all documents can be customized in a content template.

For example, imagine that class LoginScreen < Arbre::Html::Document does not accept or call the block passed into its build method. The following will still be possible:

*app/views/session/new.html.arb:*

document LoginScreen do
  after 'fieldset.password' do
    link forgot_password_path, 'forgot password?'
  end
end

Defined Under Namespace

Modules: ContextMethods, ControllerMethods Classes: ContentDocument