Skip to content

Commit a87ef94

Browse files
committed
Update documentation for the different helper methods
This updates the documentation to remove references to .govspeak.erb files and to make suggestions of which helper method (text_for, govspeak_for, html_for) in each scenario. Along the way I noticed that the label field may not be working (issue prior to these changes) so I left a note about that so the next person who wants it can investigate. I removed the information on error_* as I believe that is mostly set on a custom basis so doesn't need to be included in the general documentation.
1 parent d46f639 commit a87ef94

File tree

6 files changed

+142
-116
lines changed

6 files changed

+142
-116
lines changed

doc/smart-answer-flow-development/creating-a-new-smart-answer.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Create a new file for our landing page template.
4343

4444
```
4545
$ mkdir lib/smart_answer_flows/example-smart-answer
46-
$ touch lib/smart_answer_flows/example-smart-answer/example_smart_answer.govspeak.erb
46+
$ touch lib/smart_answer_flows/example-smart-answer/example_smart_answer.erb
4747
```
4848

4949
Although the landing page template needs to exist, it doesn't actually need to contain anything!
@@ -53,11 +53,11 @@ Assuming you're still running `rails server`, visit [http://localhost:3000/examp
5353
Open the new landing page template your editor and copy/paste the following content:
5454

5555
```erb
56-
<% render_content_for :title do %>
56+
<% text_for :title do %>
5757
Smart Answer title
5858
<% end %>
5959
60-
<% render_content_for :body do %>
60+
<% govspeak_for :body do %>
6161
Landing page body.
6262
<% end %>
6363
```
@@ -74,7 +74,7 @@ Create a new file for our question page template.
7474

7575
```
7676
$ mkdir lib/smart_answer_flows/example-smart-answer/questions
77-
$ touch lib/smart_answer_flows/example-smart-answer/questions/question_1.govspeak.erb
77+
$ touch lib/smart_answer_flows/example-smart-answer/questions/question_1.erb
7878
```
7979

8080
Although the question page template needs to exist, it doesn't actually need to contain anything!
@@ -84,11 +84,11 @@ Assuming you're still running `rails server`, visit [http://localhost:3000/examp
8484
Open the new question page template in your editor and copy/paste the following content:
8585

8686
```erb
87-
<% render_content_for :title do %>
87+
<% text_for :title do %>
8888
Question page title
8989
<% end %>
9090
91-
<% render_content_for :body do %>
91+
<% govspeak_for :body do %>
9292
Question page body.
9393
<% end %>
9494
```
@@ -105,7 +105,7 @@ Create a new file for our outcome page template.
105105

106106
```
107107
$ mkdir lib/smart_answer_flows/example-smart-answer/outcomes
108-
$ touch lib/smart_answer_flows/example-smart-answer/outcomes/outcome_1.govspeak.erb
108+
$ touch lib/smart_answer_flows/example-smart-answer/outcomes/outcome_1.erb
109109
```
110110

111111
Although the question page template needs to exist, it doesn't actually need to contain anything!
@@ -115,11 +115,11 @@ Assuming you're still running `rails server`, visit [http://localhost:3000/examp
115115
Open the new outcome page template in your editor and copy/paste the following content:
116116

117117
```erb
118-
<% render_content_for :title do %>
118+
<% text_for :title do %>
119119
Outcome page title
120120
<% end %>
121121
122-
<% render_content_for :body do %>
122+
<% govspeak_for :body do %>
123123
Outcome page body.
124124
<% end %>
125125
```

doc/smart-answers/erb-templates.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
# ERB templates
22

3-
Content is defined in `render_content_for` blocks and with the name of the intent of the content:
3+
Content is defined using one of three helpers to indicate the format with an argument to indicate the intent:
44

55
```erb
6-
<% render_content_for :title do %>
7-
Some amazing title
6+
<% text_for :title do %>
7+
This is plain text, any HTML characters used will be espaced. Any indentation is automatically removed.
88
<% end %>
99
```
1010

11-
The type of content can be explicitly set with the `format:` option:
11+
```erb
12+
<% govspeak_for :body do %>
13+
This uses the GOV.UK markdown dialect, [govspeak](https://github.com/alphagov/govspeak),
14+
and will be converted to HTML. Any indentation is automatically removed.
15+
<% end %>
16+
```
1217

1318
```erb
14-
<% render_content_for :title, format: :html do %>
15-
<h1>Some amazing title</h1>
19+
<% html_for :body do %>
20+
<p>This is HTML, used when we need fine grained control over content</p>
1621
<% end %>
1722
```
1823

19-
We support Govspeak (`:govspeak`), plain text (`:text`) and HTML (`:html`). See docs for template pages for the default formats of different content blocks.
24+
See the template page documentation for the available contexts and their allowed formats:
2025

2126
* [Landing page templates](erb-templates/landing-page-template.md)
2227
* [Question templates](erb-templates/question-templates.md)
2328
* [Outcome templates](erb-templates/outcome-templates.md)
2429

25-
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.
26-
2730
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.

doc/smart-answers/erb-templates/landing-page-template.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,53 @@
11
# Landing page template
22

3-
Landing page templates live in `lib/smart_answer_flows/<flow-name>/<flow-name-with-underscores>.govspeak.erb`.
3+
Landing page templates live in `lib/smart_answer_flows/<flow-name>/<flow-name-with-underscores>.erb`.
44

55
## Content types
66

77
The templates can contain content for any of the following keys:
88

99
### `:title`
1010

11-
* Default format is `:text`
12-
* Used as the heading (currently "h1")
11+
Used as the h1 heading and can only be text. Example:
1312

14-
### `:meta_description`
15-
16-
* Default format is `:text`
17-
* Used as the content for the [meta description tag][meta-description]
13+
```erb
14+
<% text_for :title do %>
15+
Look up Meursing code
16+
<% end %>
17+
```
1818

19-
### `:body`
19+
### `:meta_description`
2020

21-
* Default format is `:govspeak`
22-
* Used to generate the main content (appearing above the start button)
21+
Used as the content for the [meta description tag][meta-description]. Can only be text. Example:
2322

24-
### `:post_body`
23+
```erb
24+
<% text_for :meta_description do %>
25+
Look up the additional code (Meursing code) required for import or export of goods containing certain types of milk and sugars
26+
<% end %>
27+
```
2528

26-
* Default format is `:govspeak`
27-
* Used to generate supplementary content (appearing below the start button)
29+
### `:body`
2830

29-
## Example
31+
Used to generate the main content (appearing above the start button). Expected to be govspeak or HTML. Example:
3032

3133
```erb
32-
<% render_content_for :title do %>
33-
Look up Meursing code
34+
<% govspeak_for :body do %>
35+
Use this tool to look up the additional code (Meursing code) for import or export of goods containing certain types of milk and sugars covered Regulation (EC) No. 1216/09.
3436
<% end %>
37+
```
3538

36-
<% render_content_for :meta_description do %>
37-
Look up the additional code (Meursing code) required for import or export of goods containing certain types of milk and sugars
39+
```erb
40+
<% html_for :body do %>
41+
<p>Use this tool to look up the additional code (Meursing code) for import or export of goods containing certain types of milk and sugars covered Regulation (EC) No. 1216/09.</p>
3842
<% end %>
43+
```
44+
### `:post_body`
3945

40-
<% render_content_for :body do %>
41-
Use this tool to look up the additional code (Meursing code) for import or export of goods containing certain types of milk and sugars covered Regulation (EC) No. 1216/09.
46+
Used to generate supplementary content (appearing below the start button). Expected to be govspeak or HTML. Example:
47+
48+
```erb
49+
<% govspeak_for :post_body do %>
50+
Code of measuring practice became globally effective in May 2015.
4251
<% end %>
4352
```
4453

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
# Outcome templates
22

3-
Outcome templates live in `lib/smart_answer_flows/<flow-name>/outcomes/<outcome-name>.govspeak.erb`.
3+
Outcome templates live in `lib/smart_answer_flows/<flow-name>/outcomes/<outcome-name>.erb`.
44

55
## Content types
66

77
The templates can contain content for any of the following keys:
88

99
### `:title`
1010

11-
* Default format is `:text`
12-
* Used as the heading (currently "h1")
13-
14-
### `:body`
15-
16-
* Default format is `:govspeak`
17-
* Used as the main text
18-
19-
### `next_steps(govspeak)`
20-
21-
* Default format is `:govspeak`
22-
* Used to generate "next steps" content (at top of a right-hand sidebar)
23-
24-
## Example
11+
Used as the h1 heading and can only be text. Example:
2512

2613
```erb
27-
<% render_content_for :title do %>
14+
<% text_for :title do %>
2815
<% unless calculator.has_commodity_code? %>
2916
The product composition you indicated is not possible.
3017
<% else %>
3118
The Meursing code for a product with this composition is 7<%= calculator.commodity_code %>.
3219
<% end %>
3320
<% end %>
21+
```
22+
23+
### `:body`
3424

35-
<% render_content_for :body do %>
25+
Used to generate the main content. Expected to be govspeak or HTML. Example:
26+
27+
```erb
28+
<% govspeak_for :body do %>
3629
<% if calculator.has_commodity_code? %>
3730
Use these four digits together with the ten-digit commodity code from Trade Tariff.
3831
<% end %>
3932
<% end %>
4033
```
34+
35+
### `next_steps`
36+
37+
Used to generate the "next steps" content (at the top of the right-hand sidebar). Expected to be govspeak or HTML. Example:
38+
39+
```erb
40+
<% govspeak_for :next_steps do %>
41+
Find out what happens to [ownerless property](/unclaimed-estates-bona-vacantia "Ownerless property (bona vacantia)")
42+
<% end %>
43+
```

0 commit comments

Comments
 (0)