Skip to content
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

Add line break functionality to instruction and description #196

Merged
merged 13 commits into from
Jul 21, 2020
10 changes: 0 additions & 10 deletions app/jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,3 @@ def map_list_collector_config(
@blueprint.app_context_processor
def map_list_collector_config_processor():
return dict(map_list_collector_config=map_list_collector_config)


@blueprint.app_template_filter()
def format_paragraphs(text):
return "\n".join(f"<p>{paragraph}</p>" for paragraph in text.splitlines())


@blueprint.app_context_processor
def paragraphs_processor():
return dict(format_paragraphs=format_paragraphs)
2 changes: 1 addition & 1 deletion scripts/run_validator.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
tag=latest
tag=make-description-list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder to revert before merge

docker pull onsdigital/eq-questionnaire-validator:$tag
docker run -d -p 5001:5000 "onsdigital/eq-questionnaire-validator:$tag"
3 changes: 2 additions & 1 deletion templates/interstitial.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{% extends 'layouts/_questionnaire.html' %}
{% from 'macros/helpers.html' import format_paragraphs %}

{% set save_on_signout = true %}

{% set continue_button_text = _("Continue") %}

{% block form_content %}
{% set interstitial_instruction = format_paragraphs(block.content.instruction) if block.content.instruction else None %}
{% set interstitial_instruction = format_paragraphs(block.content.instruction) %}
{% if block.content.title %}
<h1>{{ block.content.title }}</h1>
{% endif %}
Expand Down
7 changes: 7 additions & 0 deletions templates/macros/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
{{attr|xmlattr}}
{%- endmacro -%}

{%- macro format_paragraphs(paragraphs) -%}
{%- for paragraph in paragraphs -%}
<p>{{paragraph}}</p>
{%- else -%}
{%- endfor -%}
{%- endmacro -%}

{%- macro telephone_number(tel="0300 1234 931", aria_describedby=None, class=None) -%}
{% set attr = {
"aria-describedby": aria_describedby,
Expand Down
5 changes: 3 additions & 2 deletions templates/partials/question.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% from "components/question/_macro.njk" import onsQuestion %}
{% from "components/fieldset/_macro.njk" import onsFieldset %}
{% from "components/panel/_macro.njk" import onsPanel %}
{% from 'macros/helpers.html' import format_paragraphs %}

{% set form = content.form %}

{% set question_title = question.title %}
{% set question_description = format_paragraphs(question.description) if question.description else None %}
{% set question_instruction = format_paragraphs(question.instruction) if question.instruction else None %}
{% set question_description = format_paragraphs(question.description) %}
{% set question_instruction = format_paragraphs(question.instruction) %}
{% set should_wrap_with_fieldset = should_wrap_with_fieldset(question) %}

{%- set question_definition -%}
Expand Down
5 changes: 0 additions & 5 deletions test_schemas/cy/test_language.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@
"type": "Question",
"id": "name-block",
"question": {
"description": "",
"id": "name-question",
"title": "Rhowch enw",
"type": "General",
"answers": [
{
"id": "first-name",
"description": "",
"label": "Enw cyntaf",
"mandatory": true,
"type": "TextField"
},
{
"id": "last-name",
"description": "",
"label": "Enw olaf",
"mandatory": false,
"type": "TextField"
Expand All @@ -55,7 +52,6 @@
"type": "Question",
"id": "dob-block",
"question": {
"description": "",
"id": "dob-question",
"title": {
"text": "Beth yw dyddiad geni {person_name_possessive}?",
Expand Down Expand Up @@ -115,7 +111,6 @@
}
}
],
"description": "",
"id": "number-of-people-question",
"title": "Faint o bobl sy\u2019n byw ar eich cartref?",
"type": "General"
Expand Down
4 changes: 3 additions & 1 deletion test_schemas/en/test_interstitial_instruction.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"id": "interstitial",
"content": {
"title": "Breakfast interstitial",
"instruction": "Just pause for a second",
"instruction": [
"Just pause for a second"
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also have a question instruction in a test schema.

"contents": [
{
"description": "Next we want to know about your lunch."
Expand Down
4 changes: 3 additions & 1 deletion test_schemas/en/test_markup.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"type": "TextField"
}
],
"description": "Cum sociis natoque penatibus et <em>magnis dis parturient montes</em>, nascetur ridiculus mus. Curabitur blandit tempus porttitor.",
"description": [
"Cum sociis natoque penatibus et <em>magnis dis parturient montes</em>, nascetur ridiculus mus. Curabitur blandit tempus porttitor."
],
"id": "question",
"title": "This is a title <em>with emphasis</em>",
"type": "General"
Expand Down
36 changes: 19 additions & 17 deletions test_schemas/en/test_placeholder_playback_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,27 @@
],
"id": "confirm-answers-question",
"title": "You selected the following toppings. Is this correct?",
"description": {
"text": "{toppings}",
"placeholders": [
{
"placeholder": "toppings",
"transforms": [
{
"transform": "format_list",
"arguments": {
"list_to_format": {
"source": "answers",
"identifier": "mandatory-checkbox-answer"
"description": [
{
"text": "{toppings}",
"placeholders": [
{
"placeholder": "toppings",
"transforms": [
{
"transform": "format_list",
"arguments": {
"list_to_format": {
"source": "answers",
"identifier": "mandatory-checkbox-answer"
}
}
}
}
]
}
]
}
]
}
]
}
]
},
"routing_rules": [
{
Expand Down
36 changes: 19 additions & 17 deletions test_schemas/en/test_placeholder_transform.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,27 @@
"type": "General",
"id": "total-retail-turnover-confirmation-question",
"title": "Please enter the value of internet sales",
"description": {
"text": "Of the <em>{total_turnover}</em> total retail turnover, what was the value of internet sales?",
"placeholders": [
{
"placeholder": "total_turnover",
"transforms": [
{
"transform": "format_currency",
"arguments": {
"number": {
"source": "answers",
"identifier": "total-retail-turnover-answer"
"description": [
{
"text": "Of the <em>{total_turnover}</em> total retail turnover, what was the value of internet sales?",
"placeholders": [
{
"placeholder": "total_turnover",
"transforms": [
{
"transform": "format_currency",
"arguments": {
"number": {
"source": "answers",
"identifier": "total-retail-turnover-answer"
}
}
}
}
]
}
]
},
]
}
]
}
],
"answers": [
{
"id": "total-retail-turnover-internet-sales-answer",
Expand Down
67 changes: 67 additions & 0 deletions test_schemas/en/test_question_description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"mime_type": "application/json/ons/eq",
"language": "en",
"schema_version": "0.0.1",
"data_version": "0.0.3",
"survey_id": "0",
"title": "Other input fields",
"theme": "default",
"description": "A questionnaire to demo checkbox field Other input.",
"messages": {
"NUMBER_TOO_LARGE": "Number is too large",
"NUMBER_TOO_SMALL": "Number cannot be less than zero",
"INVALID_NUMBER": "Please enter an integer"
},
"metadata": [
{
"name": "user_id",
"type": "string"
},
{
"name": "period_id",
"type": "string"
},
{
"name": "ru_name",
"type": "string"
}
],
"sections": [
{
"id": "default-section",
"groups": [
{
"blocks": [
{
"type": "Question",
"id": "name-block",
"question": {
"description": ["Answer the question", "Go on"],
"answers": [
{
"id": "name-answer",
"label": "What is your name?",
"max_length": 20,
"mandatory": false,
"q_code": "0",
"type": "TextField"
}
],
"id": "name-question",
"title": "Title",
"type": "General"
},
"routing_rules": []
},
{
"type": "Summary",
"id": "summary"
}
],
"id": "checkboxes",
"title": "Title"
}
]
}
]
}
6 changes: 3 additions & 3 deletions test_schemas/en/test_question_guidance.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"question": {
"id": "question-test-guidance-title",
"title": "Question: Test guidance title",
"description": "Testing combinations of the title within guidance",
"description": ["Testing combinations of the title within guidance"],
"guidance": {
"contents": [
{
Expand Down Expand Up @@ -73,7 +73,7 @@
"question": {
"id": "question-test-guidance-description",
"title": "Question: Test guidance descriptions",
"description": "Tests the descriptions within guidance",
"description": ["Tests the descriptions within guidance"],
"guidance": {
"contents": [
{
Expand Down Expand Up @@ -241,7 +241,7 @@
"question": {
"id": "question-test-guidance-all",
"title": "Question: Test guidance all",
"description": "Testing all features of the guidance block enabled together",
"description": ["Testing all features of the guidance block enabled together"],
"guidance": {
"contents": [
{
Expand Down
6 changes: 3 additions & 3 deletions test_schemas/en/test_section_enabled_checkbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
],
"mandatory": false,
"description": "This is section 1.",
"description": ["This is section 1."],
"id": "section-1-question",
"title": "Which sections do you want to enable?",
"type": "MutuallyExclusive"
Expand Down Expand Up @@ -103,7 +103,7 @@
"type": "Number"
}
],
"description": "This is section 2.",
"description": ["This is section 2."],
"id": "section-2-question",
"title": "Which section is this?",
"type": "General"
Expand Down Expand Up @@ -144,7 +144,7 @@
"type": "Number"
}
],
"description": "This is section 3.",
"description": ["This is section 3."],
"id": "section-3-question",
"title": "Which section is this?",
"type": "General"
Expand Down
6 changes: 3 additions & 3 deletions test_schemas/en/test_section_enabled_hub.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
}
],
"mandatory": false,
"description": "This is section 1.",
"description": ["This is section 1."],
"id": "section-1-question",
"title": "Which sections do you want to enable?",
"type": "MutuallyExclusive"
Expand Down Expand Up @@ -107,7 +107,7 @@
"type": "Number"
}
],
"description": "This is section 2.",
"description": ["This is section 2."],
"id": "section-2-question",
"title": "Which section is this?",
"type": "General"
Expand Down Expand Up @@ -148,7 +148,7 @@
"type": "Number"
}
],
"description": "This is section 3.",
"description": ["This is section 3."],
"id": "section-3-question",
"title": "Which section is this?",
"type": "General"
Expand Down
4 changes: 2 additions & 2 deletions test_schemas/en/test_section_enabled_radio.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"type": "Radio"
}
],
"description": "This is section 1.",
"description": ["This is section 1."],
"id": "section-1-question",
"title": "Do you want to enable section 2?",
"type": "General"
Expand Down Expand Up @@ -91,7 +91,7 @@
"type": "Number"
}
],
"description": "This is section 2.",
"description": ["This is section 2."],
"id": "section-2-question",
"title": "Which section is this?",
"type": "General"
Expand Down
Loading