metadata_presenter 0.23.0 → 0.27.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: d1b2ff20300f6b643a7c83f8885c640b375babed55cd30798ca079bbd67b0506
4
- data.tar.gz: ba841ff80433e9ff917a2d006eca7a53f618193640815e7594415a8945003c57
3
+ metadata.gz: 4048587e07e7a5b2b4919a71d0183200b3f88068377b284a307ad917d1a30add
4
+ data.tar.gz: 4fb293d2eb67132d9f68b8da4f142847864d748a8a3e4dd1bb93151b327aab0a
5
5
  SHA512:
6
- metadata.gz: 1298d445703206b693fb9153255362433a4476bca5e982aac89a847c8a902013d066e729bdf645ba48fd0b5f4a780b972a94a14740b3db8ba55879439e6fd33f
7
- data.tar.gz: 12439df97cda7c675df1f53ebb4151ebdfc64509c64ce08b466c9f16ed67b2f02fb06e9777458c5da37bfc27c54ad5f4368372f07c56292a624d2d36f24196ef
6
+ metadata.gz: 4110ca082033d1bbdbe271b70942c37b6bb0424d4202874e3016ab96c85d226bb8da432bdc63079918cd544ada93d869add4b45e2d961bf9c0272fc5ba4969ff
7
+ data.tar.gz: 146b09fa25fc4305b3193b0a932bff1b6846b4d8cf8bf55246b0fc5c01df55b7de41cb701d12f74aab38e365045edb0fd489a78175f7728ef967c363f81084df
@@ -6,15 +6,14 @@ module MetadataPresenter
6
6
  end
7
7
  end
8
8
 
9
- # Renders markdown given a text.
9
+ # Renders html given markdown.
10
10
  #
11
11
  # @example
12
- # <%=m '# Some markdown' %>
12
+ # <%=to_html '# Some markdown' %>
13
13
  #
14
- def m(text)
14
+ def to_html(text)
15
15
  Kramdown::Document.new(text).to_html.html_safe
16
16
  end
17
- alias_method :to_markdown, :m
18
17
 
19
18
  def default_text(property)
20
19
  MetadataPresenter::DefaultText[property]
@@ -1,4 +1,7 @@
1
1
  module MetadataPresenter
2
+ class PageComponentsNotDefinedError < StandardError
3
+ end
4
+
2
5
  class Page < MetadataPresenter::Metadata
3
6
  include ActiveModel::Validations
4
7
 
@@ -27,5 +30,28 @@ module MetadataPresenter
27
30
  def template
28
31
  "metadata_presenter/#{type.gsub('.', '/')}"
29
32
  end
33
+
34
+ def input_components
35
+ page_components(raw_type)[:input_components]
36
+ end
37
+
38
+ def content_components
39
+ page_components(raw_type)[:content_components]
40
+ end
41
+
42
+ private
43
+
44
+ def page_components(page_type)
45
+ values = Rails.application.config.page_components[page_type]
46
+ if values.blank?
47
+ raise PageComponentsNotDefinedError, "No page components defined for #{page_type} in config initialiser"
48
+ end
49
+
50
+ values
51
+ end
52
+
53
+ def raw_type
54
+ type.gsub('page.', '')
55
+ end
30
56
  end
31
57
  end
@@ -3,6 +3,6 @@
3
3
  data-fb-content-id="page[body]"
4
4
  data-fb-content-type="content"
5
5
  data-fb-default-text="<%= default_text('body') %>">
6
- <%= to_markdown(@page.body) %>
6
+ <%= to_html(@page.body) %>
7
7
  </div>
8
8
  <%- end %>
@@ -1 +1 @@
1
- <%= to_markdown(component.html) %>
1
+ <%= to_html(component.content) %>
@@ -12,6 +12,17 @@
12
12
  <% end %>
13
13
 
14
14
  <%= form_for @page, url: reserved_submissions_path do |f| %>
15
+
16
+ <%= render partial: 'metadata_presenter/component/components',
17
+ locals: {
18
+ f: f,
19
+ components: @page.extra_components,
20
+ tag: nil,
21
+ classes: nil,
22
+ input_components: @page.input_components,
23
+ content_components: @page.content_components
24
+ } %>
25
+
15
26
  <div data-block-id="page.checkanswers.answers" data-block-type="answers">
16
27
  <dl class="fb-block fb-block-answers govuk-summary-list">
17
28
  <% pages_presenters.each do |page_answers_presenters| %>
@@ -69,7 +80,9 @@
69
80
  f: f,
70
81
  components: @page.components,
71
82
  tag: nil,
72
- classes: nil
83
+ classes: nil,
84
+ input_components: @page.input_components,
85
+ content_components: @page.content_components
73
86
  } %>
74
87
 
75
88
  <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">
@@ -19,5 +19,7 @@
19
19
  f: nil,
20
20
  components: @page.components,
21
21
  tag: nil,
22
- classes: nil
22
+ classes: nil,
23
+ input_components: @page.input_components,
24
+ content_components: @page.content_components
23
25
  } %>
@@ -23,7 +23,9 @@
23
23
  f: f,
24
24
  components: @page.components,
25
25
  tag: nil,
26
- classes: nil
26
+ classes: nil,
27
+ input_components: @page.input_components,
28
+ content_components: @page.content_components
27
29
  } %>
28
30
 
29
31
  <%= f.govuk_submit(disabled: editable?) %>
@@ -3,7 +3,7 @@
3
3
  <div class="govuk-grid-column-two-thirds">
4
4
  <% if @page.body %>
5
5
  <p class="govuk-body-l" data-block-id="<%= @page.id %>" data-block-property="body">
6
- <%= to_markdown(@page.body) %>
6
+ <%= to_html(@page.body) %>
7
7
  </p>
8
8
  <%- end %>
9
9
  <%= form_tag(reserved_answers_path, method: :post) do %>
@@ -12,7 +12,9 @@
12
12
  f: f,
13
13
  components: @page.components,
14
14
  tag: :h2,
15
- classes: 'govuk-heading-m govuk-!-margin-top-8'
15
+ classes: 'govuk-heading-m govuk-!-margin-top-8',
16
+ input_components: @page.input_components,
17
+ content_components: @page.content_components
16
18
  }
17
19
  %>
18
20
 
@@ -20,7 +20,7 @@
20
20
  <div class="fb-editable"
21
21
  data-fb-content-id="page[before_you_start]"
22
22
  data-fb-content-type="content">
23
- <%= to_markdown(@page.before_you_start) %>
23
+ <%= to_html(@page.before_you_start) %>
24
24
  </div>
25
25
  <%- end %>
26
26
  </div>
@@ -0,0 +1,19 @@
1
+ Rails.application.config.page_components =
2
+ ActiveSupport::HashWithIndifferentAccess.new({
3
+ checkanswers: {
4
+ input_components: %w(),
5
+ content_components: %w(content)
6
+ },
7
+ confirmation: {
8
+ input_components: %w(),
9
+ content_components: %w(content)
10
+ },
11
+ content: {
12
+ input_components: %w(),
13
+ content_components: %w(content)
14
+ },
15
+ multiplequestions: {
16
+ input_components: %w(text textarea number date radios checkboxes),
17
+ content_components: %w(content)
18
+ }
19
+ })
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "_id": "component.content",
3
3
  "_type": "content",
4
- "html": "[Optional content]"
4
+ "content": "[Optional content]"
5
5
  }
@@ -4,5 +4,6 @@
4
4
  "heading": "Check your answers",
5
5
  "send_heading": "Now send your application",
6
6
  "send_body": "By submitting this application you confirm that, to the best of your knowledge, the details you are providing are correct.",
7
- "components": []
7
+ "components": [],
8
+ "extra_components": []
8
9
  }
@@ -2,6 +2,6 @@
2
2
  "section_heading": "[Optional section heading]",
3
3
  "lede": "[Optional lede paragraph]",
4
4
  "body": "[Optional content]",
5
- "html": "[Optional content]",
5
+ "content": "[Optional content]",
6
6
  "hint": "[Optional hint text]"
7
7
  }
@@ -178,14 +178,14 @@
178
178
  "legend": "Do you like Star Wars?",
179
179
  "items": [
180
180
  {
181
- "_id": "do-you-like-star-wars_radio_1",
181
+ "_id": "do-you-like-star-wars_radios_1_item_1",
182
182
  "_type": "radio",
183
183
  "label": "Only on weekends",
184
184
  "hint": "Optional item hint",
185
185
  "value": "only-on-weekends"
186
186
  },
187
187
  {
188
- "_id": "do-you-like-star-wars_radio_2",
188
+ "_id": "do-you-like-star-wars_radios_1_item_2",
189
189
  "_type": "radio",
190
190
  "label": "Hell no!",
191
191
  "hint": "Optional item hint",
@@ -236,21 +236,21 @@
236
236
  "legend": "What would you like on your burger?",
237
237
  "items": [
238
238
  {
239
- "_id": "burgers_checkbox_1",
239
+ "_id": "burgers_checkboxes_1_item_1",
240
240
  "_type": "checkbox",
241
241
  "label": "Beef, cheese, tomato",
242
242
  "hint": "Optional item hint",
243
243
  "value": "beef-cheese-tomato"
244
244
  },
245
245
  {
246
- "_id": "burgers_checkbox_2",
246
+ "_id": "burgers_checkboxes_1_item_2",
247
247
  "_type": "checkbox",
248
248
  "label": "Chicken, cheese, tomato",
249
249
  "hint": "Optional item hint",
250
250
  "value": "chicken-cheese-tomato"
251
251
  },
252
252
  {
253
- "_id": "burgers_checkbox_3",
253
+ "_id": "burgers_checkboxes_1_item_3",
254
254
  "_type": "checkbox",
255
255
  "label": "Mozzarella, cheddar, feta",
256
256
  "hint": "Optional item hint",
@@ -330,7 +330,7 @@
330
330
  {
331
331
  "_id": "how-many-lights_content_1",
332
332
  "_type": "content",
333
- "html": "What lights?"
333
+ "content": "What lights?"
334
334
  }
335
335
  ],
336
336
  "url": "how-many-lights"
@@ -348,9 +348,10 @@
348
348
  {
349
349
  "_id": "check-answers_content_1",
350
350
  "_type": "content",
351
- "html": "Check yourself before you wreck yourself."
351
+ "content": "Check yourself before you wreck yourself."
352
352
  }
353
- ]
353
+ ],
354
+ "extra_components": []
354
355
  },
355
356
  {
356
357
  "_uuid": "b238a22f-c180-48d0-a7d9-8aad2036f1f2",
@@ -364,7 +365,7 @@
364
365
  {
365
366
  "_id": "confirmation_content_1",
366
367
  "_type": "content",
367
- "html": "Some day I will be the most powerful Jedi ever!"
368
+ "content": "Some day I will be the most powerful Jedi ever!"
368
369
  }
369
370
  ]
370
371
  }
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '0.23.0'.freeze
2
+ VERSION = '0.27.0'.freeze
3
3
  end
@@ -11,7 +11,7 @@
11
11
  "_type": {
12
12
  "const": "content"
13
13
  },
14
- "html": {
14
+ "content": {
15
15
  "title": "Content",
16
16
  "description": "Content to display - use [markdown](https://www.gov.uk/guidance/how-to-publish-on-gov-uk/markdown) to format text or add hyperlinks",
17
17
  "type": "string",
@@ -25,6 +25,6 @@
25
25
  }
26
26
  ],
27
27
  "required": [
28
- "html"
28
+ "content"
29
29
  ]
30
30
  }
@@ -43,6 +43,14 @@
43
43
  "items": {
44
44
  "$ref": "component.content"
45
45
  }
46
+ },
47
+ "extra_components": {
48
+ "title": "Extra Components",
49
+ "description": "More form or content elements used on the page",
50
+ "type": "array",
51
+ "items": {
52
+ "$ref": "component.content"
53
+ }
46
54
  }
47
55
  },
48
56
  "required": [
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.23.0
4
+ version: 0.27.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-03-31 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -303,6 +303,7 @@ files:
303
303
  - app/views/metadata_presenter/page/start.html.erb
304
304
  - config/initializers/default_metadata.rb
305
305
  - config/initializers/default_text.rb
306
+ - config/initializers/page_components.rb
306
307
  - config/initializers/schemas.rb
307
308
  - config/routes.rb
308
309
  - default_metadata/component/checkboxes.json