-
Notifications
You must be signed in to change notification settings - Fork 120
Add declarative smart answer helper methods #4527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a26dd3a
Add declarative smart answer helper methods
kevindew b4b44cd
Support templates with or without the .govspeak suffix
kevindew ec2fbe7
Remove unnecessary unit tests
kevindew d46f639
Raise errors when setting HTML for text content
kevindew a87ef94
Update documentation for the different helper methods
kevindew 28fb339
Set the all-smart-answer-questions answer as an example
kevindew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
# ERB templates | ||
|
||
Content is defined in `render_content_for` blocks and with the name of the intent of the content: | ||
Content is defined using one of three helpers to indicate the format with an argument to indicate the intent: | ||
|
||
```erb | ||
<% render_content_for :title do %> | ||
Some amazing title | ||
<% text_for :title do %> | ||
This is plain text, any HTML characters used will be espaced. Any indentation is automatically removed. | ||
<% end %> | ||
``` | ||
|
||
The type of content can be explicitly set with the `format:` option: | ||
```erb | ||
<% govspeak_for :body do %> | ||
This uses the GOV.UK markdown dialect, [govspeak](https://github.com/alphagov/govspeak), | ||
and will be converted to HTML. Any indentation is automatically removed. | ||
<% end %> | ||
``` | ||
|
||
```erb | ||
<% render_content_for :title, format: :html do %> | ||
<h1>Some amazing title</h1> | ||
<% html_for :body do %> | ||
<p>This is HTML, used when we need fine grained control over content</p> | ||
<% end %> | ||
``` | ||
|
||
We support Govspeak (`:govspeak`), plain text (`:text`) and HTML (`:html`). See docs for template pages for the default formats of different content blocks. | ||
See the template page documentation for the available contexts and their allowed formats: | ||
|
||
* [Landing page templates](erb-templates/landing-page-template.md) | ||
* [Question templates](erb-templates/question-templates.md) | ||
* [Outcome templates](erb-templates/outcome-templates.md) | ||
|
||
We remove all leading spaces from the content in the `render_content_for` blocks for Govspeak and Text formats. This allows us to indent the content in the `render_content_for` blocks without having to worry about it affecting the generated HTML when it's processed using Govspeak. | ||
|
||
Any state variable defined in the flow is available to be used in the ERB template. See [storing data](storing-data.md) for the various ways that you can set state variables. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
# Outcome templates | ||
|
||
Outcome templates live in `lib/smart_answer_flows/<flow-name>/outcomes/<outcome-name>.govspeak.erb`. | ||
Outcome templates live in `lib/smart_answer_flows/<flow-name>/outcomes/<outcome-name>.erb`. | ||
|
||
## Content types | ||
|
||
The templates can contain content for any of the following keys: | ||
|
||
### `:title` | ||
|
||
* Default format is `:text` | ||
* Used as the heading (currently "h1") | ||
|
||
### `:body` | ||
|
||
* Default format is `:govspeak` | ||
* Used as the main text | ||
|
||
### `next_steps(govspeak)` | ||
|
||
* Default format is `:govspeak` | ||
* Used to generate "next steps" content (at top of a right-hand sidebar) | ||
|
||
## Example | ||
Used as the h1 heading and can only be text. Example: | ||
|
||
```erb | ||
<% render_content_for :title do %> | ||
<% text_for :title do %> | ||
<% unless calculator.has_commodity_code? %> | ||
The product composition you indicated is not possible. | ||
<% else %> | ||
The Meursing code for a product with this composition is 7<%= calculator.commodity_code %>. | ||
<% end %> | ||
<% end %> | ||
``` | ||
|
||
### `:body` | ||
|
||
<% render_content_for :body do %> | ||
Used to generate the main content. Expected to be govspeak or HTML. Example: | ||
|
||
```erb | ||
<% govspeak_for :body do %> | ||
<% if calculator.has_commodity_code? %> | ||
Use these four digits together with the ten-digit commodity code from Trade Tariff. | ||
<% end %> | ||
<% end %> | ||
``` | ||
|
||
### `next_steps` | ||
|
||
Used to generate the "next steps" content (at the top of the right-hand sidebar). Expected to be govspeak or HTML. Example: | ||
|
||
```erb | ||
<% govspeak_for :next_steps do %> | ||
Find out what happens to [ownerless property](/unclaimed-estates-bona-vacantia "Ownerless property (bona vacantia)") | ||
<% end %> | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.