keystone_ui-pages 0.4.0 → 0.5.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: 173519c8861b68b91c52a60547f7a7457f34c04319eb528b795b7266a6dd0bfd
4
- data.tar.gz: a1cf640e7b60ff4d6072be38c644fc8396784d35368499414b17bb21616f88a3
3
+ metadata.gz: 8a26feddb5cd80b4e5a676159463899d2aa3f8956e0a9e3a2a7cfdc2a9645a61
4
+ data.tar.gz: 118357d59feb0e62eeb1aa9c04a327fc59ee13683e7878023990ec0388542939
5
5
  SHA512:
6
- metadata.gz: dc73c41700f1444b0cbaf65ee371dac7a68fe3555f6d73bb5e0f88183c2e244bc638d4de7203c0e10eebc444c02f4e49260ff79cd795227c9c4d3472dfbd13e7
7
- data.tar.gz: 74b742f036c877533c267f2787c008c9895ed426d138fe1d63e3edc9ce4dfdb4cdfa6a412e4d7abbe6659203e1c4b0ac482e0d1b5c136e46adc1980eb726fdad
6
+ metadata.gz: 9aee570200cb37d2bf6be9c90dec6202087b85c4cefe4a448607df0b26f274f162f5c73a85a456659404b4508541d6e6fe53da3c227877bcde74acaaa75baafe
7
+ data.tar.gz: b1413f0fc7236cbfcc7769ba870726b4e79addd6d786705e1eaf5b10e6feb6f602d05a4ad5b68238b0bf67ac2a3aee9a83b24b260fa7a213d41569f3d767bc17
@@ -17,6 +17,7 @@ module KeystoneUi
17
17
 
18
18
  def drawn_version(version, values: {})
19
19
  key = [ "keystone_ui_pages", version.id, Operations.digest(values.to_h.stringify_keys) ]
20
+ @drawn_page_id = version.page_id
20
21
  Rails.cache.fetch(key) { drawn_document(version.document, values: values).to_str }.html_safe
21
22
  end
22
23
 
@@ -79,10 +80,25 @@ module KeystoneUi
79
80
  end
80
81
 
81
82
  def edited_element(element)
83
+ return missing_element(element) unless KeystoneUi::Pages.catalog.find(element["key"])
84
+
82
85
  wrapped_element(element, data: { element_id: element["id"], hidden: hidden?(element) || nil }.compact)
83
86
  end
84
87
 
88
+ def reported_missing(element)
89
+ Rails.error.report(InvalidDocument.new("No element is registered as #{element["key"]}"), handled: true,
90
+ context: { page_id: @drawn_page_id, element_key: element["key"] })
91
+ nil
92
+ end
93
+
94
+ def missing_element(element)
95
+ tag.div("No longer offered: #{element["key"]}", class: "ks-pages-element ks-hint rounded-md border-2 border-dashed border-(--ks-color-border-strong) p-3",
96
+ data: { element_id: element["id"], missing_element: true })
97
+ end
98
+
85
99
  def drawn_element(element)
100
+ return reported_missing(element) unless KeystoneUi::Pages.catalog.find(element["key"])
101
+
86
102
  wrapped_element(element) unless hidden?(element)
87
103
  end
88
104
 
@@ -6,8 +6,8 @@ module KeystoneUi
6
6
  include KeystoneUiHelper
7
7
  include DrawingHelper
8
8
 
9
- def keystone_ui_page(page, values: {})
10
- version = page.live_version
9
+ def keystone_ui_page(page, values: {}, version: nil)
10
+ version = version ? page.versions.find_by(number: version) : page.live_version
11
11
  return if version.nil?
12
12
 
13
13
  tag.div(drawn_version(version, values: values), class: "@container")
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KeystoneUi
4
4
  module Pages
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -111,10 +111,15 @@ inherit from the base controller, so define it there.
111
111
 
112
112
  ### Drawing and printing
113
113
 
114
- - `keystone_ui_page(page, values: {})` — a view helper, available in every host
115
- view, that draws the page's live version with the values given, inside a
116
- `<div class="@container">`. It returns nil when the page has never been
117
- published. `values:` takes value names to values, with string or symbol keys.
114
+ - `keystone_ui_page(page, values: {}, version: nil)` — a view helper, available
115
+ in every host view, that draws the page's live version with the values given,
116
+ inside a `<div class="@container">`. It returns nil when no version is live.
117
+ `values:` takes value names to values, with string or symbol keys.
118
+ `version:` takes a published version's number and draws that version
119
+ instead, whether it is live or superseded and whether the page is
120
+ unpublished or archived. It returns nil when the page has no version with
121
+ that number. A record made from a page keeps the number it was made with
122
+ and passes it here, so it keeps drawing the same way after later publishes.
118
123
  - `KeystoneUi::Pages.pdf(page, values: {})` — returns a
119
124
  `KeystoneUi::Pages::Pdf` record for the page's live version drawn with the
120
125
  values given. Its `file` is an Active Storage attachment, ready to download,
@@ -257,8 +262,11 @@ The catalog offers these Keystone UI components by default: `button`,
257
262
 
258
263
  The method must be reachable in the engine's views and in any host view that
259
264
  calls `keystone_ui_page`. A `helper_method` on the base controller covers
260
- both. Leaving out an element that pages already use makes those pages fail
261
- to draw, so search the pages' documents for its key before leaving it out.
265
+ both. A page that holds an element the catalog no longer offers still
266
+ draws its other elements for visitors, marks the missing one in the editor
267
+ as no longer offered, and reports the page's id and the element's key
268
+ through `Rails.error`, so search the pages' documents for its key before
269
+ leaving it out.
262
270
 
263
271
  ## Conventions
264
272
 
@@ -268,7 +276,8 @@ The catalog offers these Keystone UI components by default: `button`,
268
276
  layout and print rules together.
269
277
  - **Only the live version leaves the builder.** The draft is what editors
270
278
  change. Visitors, `keystone_ui_page` and PDFs show the live version, so an
271
- unpublished change shows nowhere else.
279
+ unpublished change shows nowhere else. `keystone_ui_page` with `version:`
280
+ shows an earlier published version, never the draft.
272
281
  - **Value names are strings.** `Values.names`, the provider's hash and the
273
282
  `values:` passed to the helper and to PDFs all use the same names. The gem
274
283
  turns symbol keys into strings, so either works, but the names must match.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider