metadata_presenter 0.18.4 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) 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 +9 -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 +4 -21
  22. data/app/views/metadata_presenter/page/multiplequestions.html.erb +2 -7
  23. data/app/views/metadata_presenter/page/start.html.erb +4 -21
  24. data/config/initializers/default_text.rb +5 -0
  25. data/default_metadata/component/checkboxes.json +3 -3
  26. data/default_metadata/component/date.json +1 -1
  27. data/default_metadata/component/number.json +1 -1
  28. data/default_metadata/component/radios.json +3 -3
  29. data/default_metadata/component/text.json +1 -1
  30. data/default_metadata/component/textarea.json +1 -1
  31. data/default_metadata/page/content.json +2 -2
  32. data/default_metadata/page/multiplequestions.json +1 -1
  33. data/default_metadata/page/singlequestion.json +1 -1
  34. data/lib/metadata_presenter/version.rb +1 -1
  35. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6eedfdb8be0287c9afecc889ed795de1cbe54803a3f10ee3534c7b94656a724e
4
- data.tar.gz: 6c16e4986b0ddbbb964e2e66d89350359e8cde221b1bf934ac58d81b621a11a3
3
+ metadata.gz: 823bc281b38f93b1e5e8e2adcbed277bc4aca13e36ee803a3e699c10aaacac41
4
+ data.tar.gz: f6ceffa8d3efea9201c00db0dc81240a717e5bcd47cc7f1b943b9b33a529fece
5
5
  SHA512:
6
- metadata.gz: c927b311be5d096e19b5ca2edd50c33afb899f44942cd3a11ea3d396ba504df656165bb808d02c43b10c679e71a86ec24e5718cd98bf86c254393728ccee7691
7
- data.tar.gz: a6a0690aae68acd1799acdbfb97f03b37dcf68feabc847d8ed8ee549bd2ac71c0043b49bacb3e05ce24aa3c1737fbd94c8a239b7dda68b4197f4247c65bedc6c
6
+ metadata.gz: ac34de25f5db0f90894a6d0af674de69136fc332ea512dd4c7b3afe9561c29d15be274d6025a2cbd27f438b2f76a83544cd51194880ede76bb5dc9d3912bcdf7
7
+ data.tar.gz: 3a0ba09f181fcd7549ddef81a3b2f581db6c74d619f7b27c5a3d7810bf26264ed093d9d849486d1de4cfe414b36c65f97491e63224fa486c3b44da0a229fdcdc
@@ -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,9 @@
1
+ class MetadataPresenter::Item < MetadataPresenter::Metadata
2
+ def name
3
+ label
4
+ end
5
+
6
+ def description
7
+ hint
8
+ end
9
+ 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,13 +1,8 @@
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 %>
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"
@@ -17,21 +12,9 @@
17
12
  </h1>
18
13
  <% end %>
19
14
 
20
- <% if @page.lede %>
21
- <div class="fb-editable govuk-body-l"
22
- data-fb-content-id="page[lede]"
23
- data-fb-content-type="element">
24
- <%= @page.lede %>
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 %>
@@ -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 %>
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,13 +1,8 @@
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 %>
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"
@@ -17,21 +12,9 @@
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="element">
24
- <%= @page.lede %>
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 lede 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.4'
2
+ VERSION = '0.19.0'
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.4
4
+ version: 0.19.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-17 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