metadata_presenter 0.3.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cff1faeeda0dc9ad30f761911443f2f61adade496ec5c1083dbbe5f30a4d98b3
4
- data.tar.gz: a52199fbdfea2f4ee641dd62d792f7bfc2ab76955c40eb8edd0109171120a22f
3
+ metadata.gz: 951d82f5f5c4cb5ac86290e44bab1301c7e3c0d3d803dd323024339108d1af02
4
+ data.tar.gz: 669f233609d32a82bffb442ce9f666d5af1de8f831da3e5e38f8ff85a2da9709
5
5
  SHA512:
6
- metadata.gz: cd44c337711cb58997b98ff2ef941f573093d135ba79342181226ac294a5efc134072767ed505199c188d906a5a26a500d93bf937ee359309023595674af290f
7
- data.tar.gz: 19e793b3f02f3fcba3fb45822da09b6dd4c48037512af6616a8711d3d841cf90f7b549605cb822d891bc5124e39a59d5ace2549757227dd8bb9038de1bc56764
6
+ metadata.gz: 76a0540b501f5d5b2ca999da539001ecc793cb21bdab95b2a885753ef84bd74e755a4849b1deb23c28d93947be79ac5f06672a9cbbb7bbe6f8e8016e58d96638
7
+ data.tar.gz: c89a2d3db1f7bcacd7ad40c4cb550349685822c1914164f9fc5f0d800b00d93ae8ee58f6a50397cf096372451fd4b54479f4fe68aee62b57d4ea46bbc5446317
@@ -1,7 +1,39 @@
1
1
  module MetadataPresenter
2
2
  module ApplicationHelper
3
- def to_markdown(text)
3
+ ## Display user answers on the view
4
+ ## When the user doesn't answered yet the component will be blank
5
+ # or with data otherwise, so doing the if in every output is not
6
+ # pratical.
7
+ #
8
+ # The below example search for 'first_name' in the user data instance
9
+ # variable as long your load_user_data in the controller sets the variable.
10
+ #
11
+ # @example
12
+ # <%=a 'first_name' %>
13
+ #
14
+ def a(component_key)
15
+ if @user_data.present?
16
+ @user_data[component_key]
17
+ end
18
+ end
19
+ alias answer a
20
+
21
+ ## Display user answers on the view formatted.
22
+ ##
23
+ def formatted_answer(component_key)
24
+ user_answer = answer(component_key)
25
+
26
+ simple_format(user_answer) if user_answer.present?
27
+ end
28
+
29
+ # Renders markdown given a text.
30
+ #
31
+ # @example
32
+ # <%=m '# Some markdown' %>
33
+ #
34
+ def m(text)
4
35
  (Kramdown::Document.new(text).to_html).html_safe
5
36
  end
37
+ alias to_markdown m
6
38
  end
7
39
  end
@@ -8,6 +8,10 @@ class MetadataPresenter::Metadata
8
8
  @metadata = OpenStruct.new(metadata)
9
9
  end
10
10
 
11
+ def to_json
12
+ self.to_h.to_json
13
+ end
14
+
11
15
  def id
12
16
  metadata._id
13
17
  end
@@ -7,8 +7,12 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
7
7
  pages.first
8
8
  end
9
9
 
10
+ def service_slug
11
+ service_name.parameterize
12
+ end
13
+
10
14
  def find_page_by_url(url)
11
- pages.find { |page| page.url == url }
15
+ pages.find { |page| strip_slash(page.url) == strip_slash(url) }
12
16
  end
13
17
 
14
18
  def find_page_by_uuid(uuid)
@@ -29,4 +33,12 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
29
33
  page.type == 'page.confirmation'
30
34
  end
31
35
  end
36
+
37
+ private
38
+
39
+ def strip_slash(url)
40
+ return url if url == '/'
41
+
42
+ url.gsub(/^\//, '')
43
+ end
32
44
  end
@@ -3,5 +3,5 @@
3
3
  label: { text: component.label },
4
4
  hint: { text: component.hint },
5
5
  name: "answers[#{component.name}]",
6
- value: @user_data ? @user_data[component.name] : nil
6
+ value: answer(component.name)
7
7
  %>
@@ -0,0 +1,11 @@
1
+ <%=
2
+ f.govuk_text_area component.id.to_sym,
3
+ label: { text: component.label },
4
+ hint: { text: component.hint },
5
+ name: "answers[#{component.name}]",
6
+ value: answer(component.name),
7
+ max_chars: component.maxchars,
8
+ max_words: component.maxwords,
9
+ threshold: component.threshold,
10
+ rows: component.rows
11
+ %>
@@ -35,7 +35,7 @@
35
35
  </dt>
36
36
 
37
37
  <dd class="govuk-summary-list__value">
38
- <%= @user_data[component.name] %>
38
+ <%= formatted_answer(component.name) %>
39
39
  </dd>
40
40
  <dd class="govuk-summary-list__actions">
41
41
  <%= link_to(
@@ -66,7 +66,7 @@
66
66
  </div>
67
67
  <% end %>
68
68
 
69
- <button data-prevent-double-click="true" class="fb-block fb-block-actions govuk-button" data-module="govuk-button" data-block-id="actions" data-block-type="actions">
69
+ <button <%= 'disabled' if editable? %> data-prevent-double-click="true" class="fb-block fb-block-actions govuk-button" data-module="govuk-button" data-block-id="actions" data-block-type="actions">
70
70
  Accept and send application
71
71
  </button>
72
72
  <% end %>
@@ -25,7 +25,7 @@
25
25
  </p>
26
26
  <%- end %>
27
27
 
28
- <%= form_tag(@page.url, method: :post) do %>
28
+ <%= form_tag(root_path, method: :post) do %>
29
29
  <button <%= 'disabled' if editable? %> class='govuk-button govuk-button--start govuk-!-margin-top-2'>
30
30
  Start
31
31
  <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
@@ -4,5 +4,8 @@
4
4
  "errors": {},
5
5
  "hint": "Component hint",
6
6
  "label": "Component label",
7
- "name": "component-name"
7
+ "name": "component-name",
8
+ "validation": {
9
+ "required": true
10
+ }
8
11
  }
@@ -0,0 +1,12 @@
1
+ {
2
+ "_id": "component.textarea",
3
+ "_type": "textarea",
4
+ "errors": {},
5
+ "hint": "Component hint",
6
+ "label": "Component label",
7
+ "name": "component-name",
8
+ "rows": 5,
9
+ "validation": {
10
+ "required": true
11
+ }
12
+ }
@@ -124,6 +124,25 @@
124
124
  "heading": "Parent name",
125
125
  "url": "/parent-name"
126
126
  },
127
+ {
128
+ "_uuid": "7b748584-100e-4d81-a54a-5049190136cc",
129
+ "_id": "page.family_hobbies",
130
+ "_type": "page.singlequestion",
131
+ "components": [
132
+ {
133
+ "_id": "page.family-hobbies--text.auto_name__3",
134
+ "_type": "textarea",
135
+ "label": "Your family hobbies",
136
+ "name": "family_hobbies",
137
+ "rows": 5,
138
+ "validation": {
139
+ "required": true
140
+ }
141
+ }
142
+ ],
143
+ "heading": "Family Hobbies",
144
+ "url": "/family-hobbies"
145
+ },
127
146
  {
128
147
  "_uuid": "e819d0c2-7062-4997-89cf-44d26d098404",
129
148
  "_id": "page._check-answers",
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '0.3.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -0,0 +1,55 @@
1
+ {
2
+ "_id": "component.textarea",
3
+ "_name": "textarea",
4
+ "title": "Textarea",
5
+ "description": "Let users enter text that can be longer than a single line",
6
+ "type": "object",
7
+ "properties": {
8
+ "_type": {
9
+ "const": "textarea"
10
+ },
11
+ "maxwords": {
12
+ "type": "number",
13
+ "title": "Maximum words",
14
+ "description": "Set a word limit",
15
+ "category": [
16
+ "userinput"
17
+ ]
18
+ },
19
+ "maxchars": {
20
+ "type": "number",
21
+ "title": "Maximum characters",
22
+ "description": "Set a character limit",
23
+ "category": [
24
+ "userinput"
25
+ ]
26
+ },
27
+ "threshold": {
28
+ "type": "number",
29
+ "title": "Threshold percentage",
30
+ "description": "Display the message about maximum length or words after a user has entered a certain amount",
31
+ "category": [
32
+ "userinput"
33
+ ]
34
+ },
35
+ "rows": {
36
+ "type": "number",
37
+ "title": "Number of rows in the textarea",
38
+ "description": "Set the number of rows",
39
+ "category": [
40
+ "userinput"
41
+ ]
42
+ }
43
+ },
44
+ "allOf": [
45
+ {
46
+ "$ref": "definition.field"
47
+ },
48
+ {
49
+ "$ref": "validations#/definitions/string_bundle"
50
+ },
51
+ {
52
+ "$ref": "definition.width_class.input"
53
+ }
54
+ ]
55
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Online
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-25 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -246,6 +246,7 @@ files:
246
246
  - app/views/errors/404.html
247
247
  - app/views/layouts/metadata_presenter/application.html.erb
248
248
  - app/views/metadata_presenter/component/_text.html.erb
249
+ - app/views/metadata_presenter/component/_textarea.html.erb
249
250
  - app/views/metadata_presenter/header/show.html.erb
250
251
  - app/views/metadata_presenter/page/checkanswers.html.erb
251
252
  - app/views/metadata_presenter/page/confirmation.html.erb
@@ -256,6 +257,7 @@ files:
256
257
  - config/initializers/schemas.rb
257
258
  - config/routes.rb
258
259
  - default_metadata/component/text.json
260
+ - default_metadata/component/textarea.json
259
261
  - default_metadata/config/meta.json
260
262
  - default_metadata/config/service.json
261
263
  - default_metadata/page/checkanswers.json
@@ -317,6 +319,7 @@ files:
317
319
  - schemas/service/configuration.json
318
320
  - schemas/service/locale.json
319
321
  - schemas/text/text.json
322
+ - schemas/textarea/textarea.json
320
323
  - schemas/validations/validations.json
321
324
  homepage: https://moj-online.service.justice.gov.uk
322
325
  licenses: