metadata_presenter 0.3.1 → 0.6.1

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: da4d7d444ed39c7f2f0815e1c7a6034893106531275dd4de9f97f655e5b6615f
4
- data.tar.gz: 3e952b54e9652043c6f56d601a82e6bdc414f0c76a932cd17209be26a0914933
3
+ metadata.gz: 895460d73f90e04b682711defdba71d7cce582761efadc78171c31291304220b
4
+ data.tar.gz: 7de5ba6ad3af9c30665bdf676dfc8fdc22cbd468b434c8486e4af5716e0e9224
5
5
  SHA512:
6
- metadata.gz: e0fd8beaea7b9141a1d58b94083b1757efeaee7160df08f347a5a47d1253736c3cdc7912e17fc0da28cd4ce8c0e8ad210c594a2bd4287c39e9ce0f8477977909
7
- data.tar.gz: 1e768d8037be04a9e6f94c20a901cd3e29a9196cdcde94addd206ce468d2cc1ceaf19991daf22f02a2e1f42415f9a355e0e9b666f905a7f947c9d0345fa12ce5
6
+ metadata.gz: df217acae89ba5d92dfbed9a452a5f5d7aaed4d59fe2249664c31198e83db2b457b0aa37056e2ddcd6297700f44dcb050c8253657fbdd3ee3732c659b036aa1c
7
+ data.tar.gz: d180c076e54ea004b37b9e922e3533391f8f3b937b8e9232662cbb1bb050e25ec6b88e6393b7ca5ff684338906dfb89177121381b33985bf91dd096bde1be85d
@@ -9,7 +9,7 @@ module MetadataPresenter
9
9
  # variable as long your load_user_data in the controller sets the variable.
10
10
  #
11
11
  # @example
12
- # <%= a('first_name') %>
12
+ # <%=a 'first_name' %>
13
13
  #
14
14
  def a(component_key)
15
15
  if @user_data.present?
@@ -18,8 +18,22 @@ module MetadataPresenter
18
18
  end
19
19
  alias answer a
20
20
 
21
- def to_markdown(text)
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)
22
35
  (Kramdown::Document.new(text).to_html).html_safe
23
36
  end
37
+ alias to_markdown m
24
38
  end
25
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
@@ -14,7 +14,6 @@
14
14
 
15
15
  <%= stylesheet_pack_tag 'govuk' %>
16
16
  <%= stylesheet_link_tag 'application', media: 'all' %>
17
- <%= javascript_pack_tag 'application' %>
18
17
  </head>
19
18
 
20
19
  <body class="govuk-template__body">
@@ -28,6 +27,7 @@
28
27
  <%= yield %>
29
28
  </main>
30
29
  </div>
30
+ <%= javascript_pack_tag 'application' %>
31
31
  <%= javascript_pack_tag 'govuk' %>
32
32
  </body>
33
33
  </html>
@@ -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
- <%=a component.name %>
38
+ <%= formatted_answer(component.name) %>
39
39
  </dd>
40
40
  <dd class="govuk-summary-list__actions">
41
41
  <%= link_to(
@@ -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">
data/config/routes.rb CHANGED
@@ -6,5 +6,7 @@ MetadataPresenter::Engine.routes.draw do
6
6
 
7
7
  post '/', to: 'answers#create'
8
8
  match '*path', to: 'answers#create', via: :post
9
- match '*path', to: 'pages#show', via: :all
9
+ match '*path', to: 'pages#show',
10
+ via: :all,
11
+ constraints: lambda {|req| req.path !~ /\.(png|jpg|js|css|ico)$/ }
10
12
  end
@@ -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.1'
2
+ VERSION = '0.6.1'
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.1
4
+ version: 0.6.1
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-28 00:00:00.000000000 Z
11
+ date: 2021-02-09 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: