metadata_presenter 0.18.1 → 0.19.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/metadata_presenter/application_helper.rb +4 -0
  3. data/app/helpers/metadata_presenter/default_text.rb +7 -0
  4. data/app/models/metadata_presenter/component.rb +1 -5
  5. data/app/models/metadata_presenter/item.rb +13 -0
  6. data/app/models/metadata_presenter/metadata.rb +8 -2
  7. data/app/models/metadata_presenter/page.rb +1 -1
  8. data/app/models/metadata_presenter/service.rb +3 -1
  9. data/app/views/metadata_presenter/attribute/_body.html.erb +8 -0
  10. data/app/views/metadata_presenter/attribute/_lede.html.erb +8 -0
  11. data/app/views/metadata_presenter/attribute/_section_heading.html.erb +8 -0
  12. data/app/views/metadata_presenter/component/_checkboxes.html.erb +4 -1
  13. data/app/views/metadata_presenter/component/_content.html.erb +1 -0
  14. data/app/views/metadata_presenter/component/_date.html.erb +4 -1
  15. data/app/views/metadata_presenter/component/_number.html.erb +4 -1
  16. data/app/views/metadata_presenter/component/_radios.html.erb +4 -1
  17. data/app/views/metadata_presenter/component/_text.html.erb +4 -1
  18. data/app/views/metadata_presenter/component/_textarea.html.erb +4 -1
  19. data/app/views/metadata_presenter/page/checkanswers.html.erb +4 -21
  20. data/app/views/metadata_presenter/page/confirmation.html.erb +5 -17
  21. data/app/views/metadata_presenter/page/content.html.erb +5 -22
  22. data/app/views/metadata_presenter/page/form.html.erb +1 -1
  23. data/app/views/metadata_presenter/page/multiplequestions.html.erb +2 -7
  24. data/app/views/metadata_presenter/page/start.html.erb +5 -22
  25. data/config/initializers/default_text.rb +5 -0
  26. data/default_metadata/component/checkboxes.json +3 -3
  27. data/default_metadata/component/date.json +1 -1
  28. data/default_metadata/component/number.json +1 -1
  29. data/default_metadata/component/radios.json +3 -3
  30. data/default_metadata/component/text.json +1 -1
  31. data/default_metadata/component/textarea.json +1 -1
  32. data/default_metadata/page/content.json +2 -2
  33. data/default_metadata/page/multiplequestions.json +1 -1
  34. data/default_metadata/page/singlequestion.json +1 -1
  35. data/lib/metadata_presenter/version.rb +1 -1
  36. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39243c82109a4213ccb32b9181e7f7f678053b8d040c9d324af854ba56cbdf64
4
- data.tar.gz: cdd2916ab5aa68fac64832a5a8056006c224a30564f83056742527edf3ce99f5
3
+ metadata.gz: 927d4a58d76571c185ffc90cae54f4924c1d2f7e67b1b82be7e4dbe07aa3b814
4
+ data.tar.gz: ee66e0dc45fb8691146a7b4871c35adcec5c6e1a61e23adf96623889c9cb84d4
5
5
  SHA512:
6
- metadata.gz: df8cf17ae39577882fc9ae3a71558fba5fc109369e8523de234d636040df2414fea491c719d3ba68089243a32f61e8fe6c21ebdebb293670927793bd31895907
7
- data.tar.gz: c61978f1ab47fadd20681cbf2095293b398cc6ad3e27d514ba2414a76ba2023f3f1b03bb4b6ff277635ead18941228a6401f32c76d41db29fc99ab281bbe164d
6
+ metadata.gz: 8d80a2047457f6923e4ec424d27617e48bb5b282436dacda25131f15c75727210c6f88cc210abffd9c428a9c487b550fb283695be870c9aa3f90d090eda6a819
7
+ data.tar.gz: 21c6276b40984fafc6c861140cad12c2ed4359ea0fb1195cd64f420be2719d7ea5d239fc3db180aaacee6bc9e515cd9c7c45520d21e3b8bda3c37b0ae61ffbf2
@@ -21,5 +21,9 @@ module MetadataPresenter
21
21
  (Kramdown::Document.new(text).to_html).html_safe
22
22
  end
23
23
  alias to_markdown m
24
+
25
+ def default_text(property)
26
+ MetadataPresenter::DefaultText[property]
27
+ end
24
28
  end
25
29
  end
@@ -0,0 +1,7 @@
1
+ module MetadataPresenter
2
+ class DefaultText
3
+ def self.[](property)
4
+ Rails.application.config.default_text[property.to_s]
5
+ end
6
+ end
7
+ end
@@ -9,11 +9,7 @@ class MetadataPresenter::Component < MetadataPresenter::Metadata
9
9
 
10
10
  def items
11
11
  metadata.items.map do |item|
12
- OpenStruct.new(
13
- id: item['label'],
14
- name: item['label'],
15
- description: item['hint']
16
- )
12
+ MetadataPresenter::Item.new(item, editor: editor?)
17
13
  end
18
14
  end
19
15
  end
@@ -0,0 +1,13 @@
1
+ class MetadataPresenter::Item < MetadataPresenter::Metadata
2
+ def id
3
+ label
4
+ end
5
+
6
+ def name
7
+ label
8
+ end
9
+
10
+ def description
11
+ hint
12
+ end
13
+ end
@@ -4,8 +4,9 @@ class MetadataPresenter::Metadata
4
4
 
5
5
  attr_reader :metadata
6
6
 
7
- def initialize(metadata)
7
+ def initialize(metadata, editor: false)
8
8
  @metadata = OpenStruct.new(metadata)
9
+ @editor = editor
9
10
  end
10
11
 
11
12
  def to_json
@@ -25,6 +26,11 @@ class MetadataPresenter::Metadata
25
26
  end
26
27
 
27
28
  def method_missing(method_name, *args, &block)
28
- metadata.send(method_name, *args, &block)
29
+ value = metadata.send(method_name, *args, &block)
30
+ value.blank? && editor? ? MetadataPresenter::DefaultText[method_name] : value
31
+ end
32
+
33
+ def editor?
34
+ @editor.present?
29
35
  end
30
36
  end
@@ -16,7 +16,7 @@ module MetadataPresenter
16
16
 
17
17
  def components
18
18
  metadata.components&.map do |component|
19
- MetadataPresenter::Component.new(component)
19
+ MetadataPresenter::Component.new(component, editor: editor?)
20
20
  end
21
21
  end
22
22
 
@@ -1,6 +1,8 @@
1
1
  class MetadataPresenter::Service < MetadataPresenter::Metadata
2
2
  def pages
3
- @_pages ||= metadata.pages.map { |page| MetadataPresenter::Page.new(page) }
3
+ @_pages ||= metadata.pages.map do |page|
4
+ MetadataPresenter::Page.new(page, editor: editor?)
5
+ end
4
6
  end
5
7
 
6
8
  def start_page
@@ -0,0 +1,8 @@
1
+ <% if @page.body %>
2
+ <div class="fb-editable"
3
+ data-fb-content-id="page[body]"
4
+ data-fb-content-type="content"
5
+ data-fb-default-text="<%= default_text('body') %>">
6
+ <%= to_markdown(@page.body) %>
7
+ </div>
8
+ <%- end %>
@@ -0,0 +1,8 @@
1
+ <% if @page.lede %>
2
+ <div class="fb-editable govuk-body-l"
3
+ data-fb-content-id="page[lede]"
4
+ data-fb-content-type="element"
5
+ data-fb-default-text="<%= default_text('lede') %>">
6
+ <%= @page.lede %>
7
+ </div>
8
+ <%- end %>
@@ -0,0 +1,8 @@
1
+ <% if @page.section_heading %>
2
+ <p class="fb-editable govuk-caption-l fb-section_heading"
3
+ data-fb-content-type="element"
4
+ data-fb-content-id="page[section_heading]"
5
+ data-fb-default-text="<%= default_text('section_heading') %>">
6
+ <%= @page.section_heading %>
7
+ </p>
8
+ <%- end %>
@@ -5,6 +5,9 @@
5
5
  :name,
6
6
  :description,
7
7
  legend: { text: input_title },
8
- hint: { text: component.hint },
8
+ hint: {
9
+ data: { "fb-default-text" => default_text('hint') },
10
+ text: component.hint
11
+ },
9
12
  include_hidden: false
10
13
  %>
@@ -0,0 +1 @@
1
+ <%= to_markdown(component.html) %>
@@ -1,5 +1,8 @@
1
1
  <%=
2
2
  f.govuk_date_field component.id.to_sym,
3
- hint: { text: component.hint },
3
+ hint: {
4
+ data: { "fb-default-text" => default_text('hint') },
5
+ text: component.hint
6
+ },
4
7
  legend: { text: input_title }
5
8
  %>
@@ -1,7 +1,10 @@
1
1
  <%=
2
2
  f.govuk_text_field component.id.to_sym,
3
3
  label: { text: input_title },
4
- hint: { text: component.hint },
4
+ hint: {
5
+ data: { "fb-default-text" => default_text('hint') },
6
+ text: component.hint
7
+ },
5
8
  name: "answers[#{component.name}]",
6
9
  width: component.width_class_input.to_i
7
10
  %>
@@ -5,5 +5,8 @@
5
5
  :name,
6
6
  :description,
7
7
  legend: { text: input_title },
8
- hint: { text: component.hint }
8
+ hint: {
9
+ data: { "fb-default-text" => default_text('hint') },
10
+ text: component.hint
11
+ }
9
12
  %>
@@ -1,6 +1,9 @@
1
1
  <%=
2
2
  f.govuk_text_field component.id.to_sym,
3
3
  label: { text: input_title },
4
- hint: { text: component.hint },
4
+ hint: {
5
+ data: { "fb-default-text" => default_text('hint') },
6
+ text: component.hint
7
+ },
5
8
  name: "answers[#{component.name}]"
6
9
  %>
@@ -1,7 +1,10 @@
1
1
  <%=
2
2
  f.govuk_text_area component.id.to_sym,
3
3
  label: { text: input_title },
4
- hint: { text: component.hint },
4
+ hint: {
5
+ data: { "fb-default-text" => default_text('hint') },
6
+ text: component.hint
7
+ },
5
8
  name: "answers[#{component.name}]",
6
9
  max_chars: component.maxchars,
7
10
  max_words: component.maxwords,
@@ -1,12 +1,7 @@
1
1
  <div class="govuk-grid-row">
2
2
  <div class="govuk-grid-column-two-thirds">
3
- <% if @page.section_heading.present? %>
4
- <p class="fb-section-heading fb-editable govuk-caption-l"
5
- data-fb-content-type="element"
6
- data-fb-content-id="page[section_heading]">
7
- <%= @page.section_heading %>
8
- </p>
9
- <% end %>
3
+
4
+ <%= render partial: 'metadata_presenter/attribute/section_heading' %>
10
5
 
11
6
  <% if @page.heading.present? %>
12
7
  <h1 class="fb-editable govuk-heading-xl"
@@ -16,21 +11,9 @@
16
11
  </h1>
17
12
  <% end %>
18
13
 
19
- <% if @page.lede.present? %>
20
- <p class="fb-editable govuk-body-l"
21
- data-fb-content-type="element"
22
- data-fb-content-id="page[lede]">
23
- <%= @page.lede %>
24
- </p>
25
- <% end %>
14
+ <%= render 'metadata_presenter/attribute/lede' %>
26
15
 
27
- <% if @page.body.present? %>
28
- <div class="fb-body fb-editable govuk-prose-scope"
29
- data-fb-content-type="content"
30
- data-fb-content-id="page[body]">
31
- <%= @page.body %>
32
- </div>
33
- <% end %>
16
+ <%= render 'metadata_presenter/attribute/body' %>
34
17
 
35
18
  <%= form_for @page, url: reserved_submissions_path do |f| %>
36
19
  <div data-block-id="page.checkanswers.answers" data-block-type="answers">
@@ -5,23 +5,11 @@
5
5
  <%= @page.heading %>
6
6
  </h1>
7
7
 
8
- <% if @page.lede %>
9
- <p class="fb-editable govuk-panel__body"
10
- data-fb-content-type="element"
11
- data-fb-content-id="page[lede]">
12
- <%= @page.lede %>
13
- </p>
14
- <% end %>
8
+ <%= render 'metadata_presenter/attribute/lede' %>
15
9
  </div>
16
10
 
17
- <% if @page.body %>
18
- <div class="govuk-grid-row">
19
- <div class="govuk-grid-column-two-thirds">
20
- <div class="fb-editable fb-body govuk-prose-scope"
21
- data-fb-content-type="content"
22
- data-fb-content-id="page[body]">
23
- <%= @page.body %>
24
- </div>
25
- </div>
11
+ <div class="govuk-grid-row">
12
+ <div class="govuk-grid-column-two-thirds">
13
+ <%= render 'metadata_presenter/attribute/body' %>
26
14
  </div>
27
- <% end %>
15
+ </div>
@@ -1,37 +1,20 @@
1
1
  <div class="fb-main-grid-wrapper" data-fb-pagetype="<%= @page.type %>">
2
2
  <div class="govuk-grid-row">
3
3
  <div class="govuk-grid-column-two-thirds">
4
- <% if @page.section_heading -%>
5
- <p class="fb-editable govuk-caption-l fb-section_heading"
6
- data-fb-content-type="element"
7
- data-fb-content-id="page[section_heading]">
8
- <%= @page.section_heading.html_safe %>
9
- </p>
10
- <%- end %>
4
+
5
+ <%= render 'metadata_presenter/attribute/section_heading' %>
11
6
 
12
7
  <% if @page.heading %>
13
8
  <h1 class="fb-editable govuk-heading-xl"
14
9
  data-fb-content-id="page[heading]"
15
10
  data-fb-content-type="element">
16
- <%= @page.heading.html_safe %>
11
+ <%= @page.heading %>
17
12
  </h1>
18
13
  <% end %>
19
14
 
20
- <% if @page.lede %>
21
- <div class="fb-editable"
22
- data-fb-content-id="page[lede]"
23
- data-fb-content-type="content">
24
- <%= @page.lede.html_safe %>
25
- </div>
26
- <%- end %>
15
+ <%= render 'metadata_presenter/attribute/lede' %>
27
16
 
28
- <% if @page.body %>
29
- <div class="fb-editable"
30
- data-fb-content-id="page[body]"
31
- data-fb-content-type="content">
32
- <%= to_markdown(@page.body) %>
33
- </div>
34
- <%- end %>
17
+ <%= render 'metadata_presenter/attribute/body' %>
35
18
 
36
19
  <%= form_for @page_answers, as: :answers, url: @page.url, method: :post do |f| %>
37
20
  <%= f.govuk_error_summary %>
@@ -2,7 +2,7 @@
2
2
  <div class="govuk-grid-row">
3
3
  <div class="govuk-grid-column-two-thirds">
4
4
  <% if @page.body %>
5
- <p class="govuk-body-l" data-block-id="<%= @page.id %>" data-block-property="lede">
5
+ <p class="govuk-body-l" data-block-id="<%= @page.id %>" data-block-property="body">
6
6
  <%= to_markdown(@page.body) %>
7
7
  </p>
8
8
  <%- end %>
@@ -1,13 +1,8 @@
1
1
  <div class="fb-main-grid-wrapper" data-block-id="<%= @page.id %>" data-block-type="page" data-block-pagetype="<%= @page.type %>">
2
2
  <div class="govuk-grid-row">
3
3
  <div class="govuk-grid-column-two-thirds">
4
- <% if @page.section_heading %>
5
- <p class="fb-editable govuk-caption-l fb-section_heading"
6
- data-fb-content-type="element"
7
- data-fb-content-id="page[section_heading]">
8
- <%= @page.section_heading.html_safe %>
9
- </p>
10
- <%- end %>
4
+
5
+ <%= render 'metadata_presenter/attribute/section_heading' %>
11
6
 
12
7
  <h1 class="govuk-heading-xl"><%= @page.heading %></h1>
13
8
 
@@ -1,37 +1,20 @@
1
1
  <div class="fb-main-grid-wrapper" data-fb-pagetype="<%= @page.type %>">
2
2
  <div class="govuk-grid-row">
3
3
  <div class="govuk-grid-column-two-thirds">
4
- <% if @page.section_heading -%>
5
- <p class="fb-editable govuk-caption-l fb-section_heading"
6
- data-fb-content-type="element"
7
- data-fb-content-id="page[section_heading]">
8
- <%= @page.section_heading.html_safe %>
9
- </p>
10
- <%- end %>
4
+
5
+ <%= render 'metadata_presenter/attribute/section_heading' %>
11
6
 
12
7
  <% if @page.heading %>
13
8
  <h1 class="fb-editable govuk-heading-xl"
14
9
  data-fb-content-id="page[heading]"
15
10
  data-fb-content-type="element">
16
- <%= @page.heading.html_safe %>
11
+ <%= @page.heading %>
17
12
  </h1>
18
13
  <% end %>
19
14
 
20
- <% if @page.lede %>
21
- <div class="fb-editable"
22
- data-fb-content-id="page[lede]"
23
- data-fb-content-type="content">
24
- <%= @page.lede.html_safe %>
25
- </div>
26
- <%- end %>
15
+ <%= render 'metadata_presenter/attribute/lede' %>
27
16
 
28
- <% if @page.body %>
29
- <div class="fb-editable"
30
- data-fb-content-id="page[body]"
31
- data-fb-content-type="content">
32
- <%= to_markdown(@page.body) %>
33
- </div>
34
- <%- end %>
17
+ <%= render 'metadata_presenter/attribute/body' %>
35
18
 
36
19
  <%= form_tag(root_path, method: :post) do %>
37
20
  <button <%= 'disabled' if editable? %> class='govuk-button govuk-button--start govuk-!-margin-top-2'>
@@ -0,0 +1,5 @@
1
+ Rails.application.config.default_text = JSON.parse(
2
+ File.read(
3
+ MetadataPresenter::Engine.root.join('default_text', 'content.json')
4
+ )
5
+ )
@@ -2,20 +2,20 @@
2
2
  "_id": "component.checkboxes",
3
3
  "_type": "checkboxes",
4
4
  "errors": {},
5
- "hint": "[Optional hint text]",
5
+ "hint": "",
6
6
  "items": [
7
7
  {
8
8
  "_id": "component_checkbox_1",
9
9
  "_type": "checkbox",
10
10
  "label": "Option",
11
- "hint": "[Optional hint text]",
11
+ "hint": "",
12
12
  "value": "value-1"
13
13
  },
14
14
  {
15
15
  "_id": "component_checkbox_2",
16
16
  "_type": "checkbox",
17
17
  "label": "Option",
18
- "hint": "[Optional hint text]",
18
+ "hint": "",
19
19
  "value": "value-2"
20
20
  }
21
21
  ],
@@ -2,7 +2,7 @@
2
2
  "_id": "component.date",
3
3
  "_type": "date",
4
4
  "errors": {},
5
- "hint": "[Optional hint text]",
5
+ "hint": "",
6
6
  "legend": "Question",
7
7
  "name": "component-name",
8
8
  "date_type": "day-month-year",
@@ -2,7 +2,7 @@
2
2
  "_id": "component.number",
3
3
  "_type": "number",
4
4
  "errors": {},
5
- "hint": "[Optional hint text]",
5
+ "hint": "",
6
6
  "label": "Question",
7
7
  "name": "component-name",
8
8
  "width_class_input": "10",
@@ -2,20 +2,20 @@
2
2
  "_id": "component.radios",
3
3
  "_type": "radios",
4
4
  "errors": {},
5
- "hint": "[Optional hint text]",
5
+ "hint": "",
6
6
  "items": [
7
7
  {
8
8
  "_id": "component_radio_1",
9
9
  "_type": "radio",
10
10
  "label": "Option",
11
- "hint": "[Optional hint text]",
11
+ "hint": "",
12
12
  "value": "value-1"
13
13
  },
14
14
  {
15
15
  "_id": "component_radio_2",
16
16
  "_type": "radio",
17
17
  "label": "Option",
18
- "hint": "[Optional hint text]",
18
+ "hint": "",
19
19
  "value": "value-2"
20
20
  }
21
21
  ],
@@ -3,7 +3,7 @@
3
3
  "_type": "text",
4
4
  "errors": {},
5
5
  "label": "Question",
6
- "hint": "[Optional hint text]",
6
+ "hint": "",
7
7
  "name": "component-name",
8
8
  "validation": {
9
9
  "required": true
@@ -2,7 +2,7 @@
2
2
  "_id": "component.textarea",
3
3
  "_type": "textarea",
4
4
  "errors": {},
5
- "hint": "[Optional hint text]",
5
+ "hint": "",
6
6
  "label": "Question",
7
7
  "name": "component-name",
8
8
  "rows": 5,
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "_id": "page.content",
3
3
  "_type": "page.content",
4
- "section_heading": "[Optional section heading]",
4
+ "section_heading": "",
5
5
  "heading": "Title",
6
- "lede": "[Optional lead paragraph]",
6
+ "lede": "",
7
7
  "body": "[Optional content]",
8
8
  "components": [],
9
9
  "url": ""
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "_id": "page.multiplequestions",
3
3
  "_type": "page.multiplequestions",
4
- "section_heading": "[Optional section heading]",
4
+ "section_heading": "",
5
5
  "heading": "Title",
6
6
  "components": [],
7
7
  "url": ""
@@ -2,7 +2,7 @@
2
2
  "_id": "page.singlequestion",
3
3
  "_type": "page.singlequestion",
4
4
  "heading": "Question",
5
- "lede": "This is the lede",
5
+ "lede": "",
6
6
  "body": "Body section",
7
7
  "components": [],
8
8
  "url": ""
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '0.18.1'
2
+ VERSION = '0.19.1'
3
3
  end
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.18.1
4
+ version: 0.19.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-03-15 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -231,9 +231,11 @@ files:
231
231
  - app/controllers/metadata_presenter/service_controller.rb
232
232
  - app/controllers/metadata_presenter/submissions_controller.rb
233
233
  - app/helpers/metadata_presenter/application_helper.rb
234
+ - app/helpers/metadata_presenter/default_text.rb
234
235
  - app/jobs/metadata_presenter/application_job.rb
235
236
  - app/models/metadata_presenter/component.rb
236
237
  - app/models/metadata_presenter/date_field.rb
238
+ - app/models/metadata_presenter/item.rb
237
239
  - app/models/metadata_presenter/metadata.rb
238
240
  - app/models/metadata_presenter/next_page.rb
239
241
  - app/models/metadata_presenter/page.rb
@@ -250,7 +252,11 @@ files:
250
252
  - app/validators/metadata_presenter/validate_schema.rb
251
253
  - app/views/errors/404.html
252
254
  - app/views/layouts/metadata_presenter/application.html.erb
255
+ - app/views/metadata_presenter/attribute/_body.html.erb
256
+ - app/views/metadata_presenter/attribute/_lede.html.erb
257
+ - app/views/metadata_presenter/attribute/_section_heading.html.erb
253
258
  - app/views/metadata_presenter/component/_checkboxes.html.erb
259
+ - app/views/metadata_presenter/component/_content.html.erb
254
260
  - app/views/metadata_presenter/component/_date.html.erb
255
261
  - app/views/metadata_presenter/component/_number.html.erb
256
262
  - app/views/metadata_presenter/component/_radios.html.erb
@@ -266,6 +272,7 @@ files:
266
272
  - app/views/metadata_presenter/page/singlequestion.html.erb
267
273
  - app/views/metadata_presenter/page/start.html.erb
268
274
  - config/initializers/default_metadata.rb
275
+ - config/initializers/default_text.rb
269
276
  - config/initializers/schemas.rb
270
277
  - config/routes.rb
271
278
  - default_metadata/component/checkboxes.json