MetadataPresenter
Rails engine responsible for rendering the MoJ Form Builder metadata into GOV.UK design system components.
Installation
gem 'metadata_presenter'
And then execute:
$ bundle
Or install it yourself as:
$ gem install metadata_presenter
Setup & Mount
To mount the application:
mount MetadataPresenter::Engine => '/'
Or if you are using for another route (like the MoJ Editor as preview feature):
mount MetadataPresenter::Engine => '/preview', as: :preview
The MetadataPresenter controllers inherits from your main
::ApplicationController
as default but you can overwrite if you need:
MetadataPresenter.parent_controller = '::MyAwesomeController'
The application that you mount requires to save and load user data from some store (session or a backend API or direct to a database). In order to do that you need to write the following methods in your controller:
- save_user_data
- load_user_data
- editable?
- create_submission
The user answers can be accessed via params[:answers]
.
An example of implementation:
class MyAwesomeController
def save_user_data
session[:user_data] = params[:answers]
end
def load_user_data
session[:user_data]
end
end
The editable?
is related if the pages and components could be editable in the
mountable app:
class MyAwesomeController
def editable?
false
end
helper_method :editable?
end
The create_submission
is related to process the submission in a backend
service.
Generate documentation
Run rake doc
and open the doc/index.html