keystone_ui-pages 0.4.1 → 0.6.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: 20dcd88a9a3339db1695fdf1d3c7597e60c3706f7686a3ca1bf9efeb130e0529
4
- data.tar.gz: ac4ebbcec505d877acaaaeef407246ef202f1e09884b9d6e7479d09a49faf977
3
+ metadata.gz: 77da11cab12ab896f890ea203bdf2f4b346603a1a0de8163359adf0fb1f8a608
4
+ data.tar.gz: abed3bcb29768934b84651c448105a9a75d6480c5000149b3473d3ce7250eb6e
5
5
  SHA512:
6
- metadata.gz: 1b7d8e2f3f4be7fbda39dac9e52b9b36824c1b8c5f2906e6502023fe10f6cab2ce5d6da1b355e08ca9abc8b144eb0b6cac580ac5d5c19cc699b3e6f6dd9ff0b0
7
- data.tar.gz: d50999cf89f1fb712ebeb7c1891dcf00edce95dfab8422115625198568444e3c7e2060a55a474594ec880e5913e6754ced5ea231b7592e5ab27f1340967d42d6
6
+ metadata.gz: 9bc3c8e60570178ccc5c4ef7029a6fe9cad8039187cb5649039cd85b3162d2a349814987825326834f0d4a8d1791dfbb0f5a2abab60b2e578e470d804f6003b0
7
+ data.tar.gz: 68dea7bf498637cf98b1233afb11f509ff45be2e030a6d3ab4ce150dd2f7b289cca9e80a3ef9b23900aa4d3f85e7f8a82b1cd1b1f7fb1d2658a3ecaf0fb6752f
@@ -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")
@@ -3,8 +3,8 @@
3
3
  module KeystoneUi
4
4
  module Pages
5
5
  class PdfJob < ActiveJob::Base
6
- def perform(page, values)
7
- KeystoneUi::Pages.pdf(page, values: values)
6
+ def perform(page, values, version = nil)
7
+ KeystoneUi::Pages.pdf(page, values: values, version: version)
8
8
  end
9
9
  end
10
10
  end
@@ -9,8 +9,8 @@ module KeystoneUi
9
9
  module Pdfs
10
10
  module_function
11
11
 
12
- def for(page, values: {})
13
- version = page.versions.live.first
12
+ def for(page, values: {}, version: nil)
13
+ version = version ? page.versions.find_by(number: version) : page.versions.live.first
14
14
  digest = Operations.digest(values.to_h.stringify_keys)
15
15
  Pdf.find_by(version: version, values_digest: digest) || Pdf.create!(version: version, values_digest: digest,
16
16
  file: { io: StringIO.new(Printer.pdf(PdfDocument.html(version, values: values))), filename: "#{page.slug}.pdf", content_type: "application/pdf" })
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KeystoneUi
4
4
  module Pages
5
- VERSION = "0.4.1"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -37,13 +37,13 @@ module KeystoneUi
37
37
  end
38
38
  end
39
39
 
40
- def self.pdf(page, values: {})
40
+ def self.pdf(page, values: {}, version: nil)
41
41
  require "keystone_ui/pages/pdfs"
42
- Pdfs.for(page, values: values)
42
+ Pdfs.for(page, values: values, version: version)
43
43
  end
44
44
 
45
- def self.prepare_pdf(page, values: {})
46
- PdfJob.perform_later(page, values.to_h.stringify_keys)
45
+ def self.prepare_pdf(page, values: {}, version: nil)
46
+ PdfJob.perform_later(page, values.to_h.stringify_keys, version)
47
47
  end
48
48
 
49
49
  def self.catalog
@@ -111,19 +111,26 @@ 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.
118
- - `KeystoneUi::Pages.pdf(page, values: {})` — returns a
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.
123
+ - `KeystoneUi::Pages.pdf(page, values: {}, version: nil)` — 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,
121
- link or email. The same live version and values return the record already
126
+ link or email. The same version and values return the record already
122
127
  kept, and a newly published version or different values print a new one.
123
- When nothing is kept it prints in the current request.
124
- - `KeystoneUi::Pages.prepare_pdf(page, values: {})` — queues
128
+ When nothing is kept it prints in the current request. `version:` takes a
129
+ published version's number and prints that version instead, live or
130
+ superseded, the same way `keystone_ui_page` draws it.
131
+ - `KeystoneUi::Pages.prepare_pdf(page, values: {}, version: nil)` — queues
125
132
  `KeystoneUi::Pages::PdfJob`, which calls `KeystoneUi::Pages.pdf` with the same
126
- page and values, so the file is kept before anyone asks for it.
133
+ page, values and version, so the file is kept before anyone asks for it.
127
134
 
128
135
  ### The builder and the editor's screens
129
136
 
@@ -271,7 +278,8 @@ The catalog offers these Keystone UI components by default: `button`,
271
278
  layout and print rules together.
272
279
  - **Only the live version leaves the builder.** The draft is what editors
273
280
  change. Visitors, `keystone_ui_page` and PDFs show the live version, so an
274
- unpublished change shows nowhere else.
281
+ unpublished change shows nowhere else. `keystone_ui_page` and PDFs with
282
+ `version:` show an earlier published version, never the draft.
275
283
  - **Value names are strings.** `Values.names`, the provider's hash and the
276
284
  `values:` passed to the helper and to PDFs all use the same names. The gem
277
285
  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.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider