keystone_ui-pages 0.7.0 → 0.8.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: 52e6e9b60483ae6bcec206e22e688d5b246fb3c30bac941df3658c26c8c386db
4
- data.tar.gz: ae992048e518aae337f6df23ec7a9c4ffd04f7d76e98f0a8c1a389636d99f78d
3
+ metadata.gz: ebfd45f732eefa22bd08b4a5abd3c13ff88a2fa65c55a5309c89c8b21468c69c
4
+ data.tar.gz: bb309abcbff6e6d5a12aa1096db65c1a3d298ca1db781ed4c3110a5b4e6334a3
5
5
  SHA512:
6
- metadata.gz: 7f7dcf0832adca48663675600fa5a2d05aa5f6a6b1e4e4d8c133cf4f9c9cf7bd951fb9244e4fc1824819711733bbd1dfdc03962f239cc60479407ae9ca2754c1
7
- data.tar.gz: bb06bbe0e3e0c2cc7a9876343ab7458ccec329019218c9669f266d06eb2438bff3d8b8ecc95199ff1961775718c8b4178ad5aa47c64966d19bb9843f067eaafc
6
+ metadata.gz: 845983515d8a34e9d1c4ef3faff043e2ec832461b4fbf9be78b246d9fc9aba12c9823b69f3b573879df2755dd30e7041a7b1865939cab16d53ee1dad64f6a94e
7
+ data.tar.gz: dc35e48a37f83ed5b6e61d0d41b22e92139017c8b0fa9cb1cabb458e33bb61a69b38d625800a6f7f7113fe5f3ae80689691f5c2b4a2eafbef3f2db8753b3c4cf
@@ -16,6 +16,7 @@ module KeystoneUi
16
16
 
17
17
  def new
18
18
  @place = chosen_place
19
+ @default_name = Page.new(place: @place, owner: page_owner).default_name
19
20
  end
20
21
 
21
22
  def create
@@ -89,7 +89,7 @@ module KeystoneUi
89
89
  end
90
90
 
91
91
  def default_name
92
- word = KeystoneUi::Pages.default_names.fetch(place, "Page")
92
+ word = KeystoneUi::Pages.place_settings.dig(place, :default_name) || "Page"
93
93
  used = Page.where(owner: owner, place: place).pluck(:name).filter_map { |taken| taken[/\A#{Regexp.escape(word)} (\d+)\z/, 1]&.to_i }
94
94
  "#{word} #{(used.max || 0) + 1}"
95
95
  end
@@ -9,7 +9,7 @@
9
9
  <label class="ks-label mb-1">Name</label>
10
10
  <%= ui_input(name: "page[name]", value: @page.name) %>
11
11
 
12
- <label class="ks-label mb-1">Address</label>
12
+ <label class="ks-label mb-1">URL slug</label>
13
13
  <%= ui_input(name: "page[slug]", value: @page.slug) %>
14
14
 
15
15
  <% if KeystoneUi::Pages.places.any? %>
@@ -5,16 +5,16 @@
5
5
  <%= hidden_field_tag "page[place]", @place if @place %>
6
6
 
7
7
  <label class="ks-label mb-1">Name</label>
8
- <%= ui_input(name: "page[name]", placeholder: "e.g. Pricing") %>
8
+ <%= ui_input(name: "page[name]", placeholder: @default_name) %>
9
9
 
10
- <% unless @place %>
11
- <label class="ks-label mb-1">Address</label>
10
+ <% if KeystoneUi::Pages.slugged?(@place) %>
11
+ <label class="ks-label mb-1">URL slug</label>
12
12
  <%= ui_input(name: "page[slug]", placeholder: "e.g. pricing") %>
13
+ <% end %>
13
14
 
14
- <% if KeystoneUi::Pages.places.any? %>
15
- <label class="ks-label mb-1">Place</label>
16
- <%= ui_select(name: "page[place]", options: KeystoneUi::Pages.places.invert.to_a) %>
17
- <% end %>
15
+ <% if !@place && KeystoneUi::Pages.places.any? %>
16
+ <label class="ks-label mb-1">Place</label>
17
+ <%= ui_select(name: "page[place]", options: KeystoneUi::Pages.places.invert.to_a) %>
18
18
  <% end %>
19
19
 
20
20
  <%= ui_button(label: "Create", type: :submit) %>
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KeystoneUi
4
4
  module Pages
5
- VERSION = "0.7.0"
5
+ VERSION = "0.8.0"
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ require "keystone_ui/pages/engine"
9
9
  module KeystoneUi
10
10
  module Pages
11
11
  class << self
12
- attr_writer :base_controller, :layout, :editor_layout, :pdf_stylesheet, :places, :access_exceptions, :default_names
12
+ attr_writer :base_controller, :layout, :editor_layout, :pdf_stylesheet, :access_exceptions
13
13
  attr_accessor :edit_check_method, :view_check_method, :values_method, :owner_method, :refusal_method, :chrome_path
14
14
 
15
15
  def base_controller
@@ -29,15 +29,28 @@ module KeystoneUi
29
29
  end
30
30
 
31
31
  def places
32
- @places || {}
32
+ (@places || {}).merge(place_settings.transform_values { |settings| settings[:label] })
33
33
  end
34
34
 
35
- def access_exceptions
36
- @access_exceptions || {}
35
+ def places=(labels)
36
+ @places = labels
37
+ @place_settings = {}
38
+ end
39
+
40
+ def register_place(key, label:, default_name: "Page", slug: true)
41
+ place_settings[key.to_s] = { label: label, default_name: default_name, slug: slug }
42
+ end
43
+
44
+ def place_settings
45
+ @place_settings ||= {}
46
+ end
47
+
48
+ def slugged?(place)
49
+ place_settings.dig(place.to_s, :slug) != false
37
50
  end
38
51
 
39
- def default_names
40
- @default_names || {}
52
+ def access_exceptions
53
+ @access_exceptions || {}
41
54
  end
42
55
  end
43
56
 
@@ -51,11 +51,15 @@ inherit from the base controller, so define it there.
51
51
  When it is not empty, the New page form offers them, a page with a place not
52
52
  in it is refused, and the page list shows each page's place. The view check
53
53
  reads it as `page.place`. Unset, pages have no place.
54
- - `KeystoneUi::Pages.default_names = { "client_report" => "Report template" }`
55
- — the word a page created with no name starts with, per place. The page is
56
- named with the word and the next number among that owner's pages in that
57
- place, so "Report template 1", then "Report template 2". A place with no word,
58
- and a page with no place, use "Page".
54
+ - `KeystoneUi::Pages.register_place("client_report", label: "Client report", default_name: "Report template", slug: false)`
55
+ — adds one place with its own settings, so each part of a host app registers
56
+ the place it uses and two registrations never replace each other. `label:` is
57
+ what editors see. `default_name:` is the word a page created with no name
58
+ starts with, followed by the next number among that owner's pages in that
59
+ place, so "Report template 1", then "Report template 2"; it defaults to
60
+ "Page". `slug:` says whether the place's pages have a URL slug; it defaults to
61
+ true. Registered places are offered alongside any set with `places =`, and
62
+ `places = nil` clears both.
59
63
  - `KeystoneUi::Pages.access_exceptions = { "public_preview" => "Public preview" }`
60
64
  — a hash of the exceptions an editor can set on a page, each stored value to
61
65
  its label. When it is not empty, the builder's top bar has an Access exception
@@ -324,11 +328,12 @@ The catalog offers these Keystone UI components by default: `button`,
324
328
  restoring go to that place's list, and so does the builder's Back link unless
325
329
  the host passed its own `return_to`.
326
330
  - **The New page form** at `/pages/manage/pages/new` saves a blank name from
327
- `default_names` and a blank slug as eight random hex characters. A host
328
- linking to it with `new_manage_page_path(place: "client_report")` creates the
329
- page in that place, and the form then asks for a name only. A place the host
330
- does not name in the link is ignored, and one posted to create is refused
331
- with the form shown again.
331
+ the place's `default_name` and a blank slug as eight random hex characters,
332
+ and shows that name as the Name field's placeholder. A host linking to it
333
+ with `new_manage_page_path(place: "client_report")` creates the page in that
334
+ place and offers no place choice. The URL slug field shows unless the place
335
+ was registered with `slug: false`. A place the host does not name in the link
336
+ is ignored, and one posted to create is refused with the form shown again.
332
337
  - **A page's settings** at `/pages/manage/pages/:id/edit` change its name, slug
333
338
  and place after it is created. A slug another page of the same owner uses, or
334
339
  a place the host does not name, is refused with a message and changes nothing.
@@ -11,7 +11,7 @@ develop:
11
11
  - KeystoneUi::Pages.view_check_method
12
12
  - KeystoneUi::Pages.places
13
13
  - KeystoneUi::Pages.access_exceptions
14
- - KeystoneUi::Pages.default_names
14
+ - KeystoneUi::Pages.register_place
15
15
  - KeystoneUi::Pages.values_method
16
16
  - KeystoneUi::Pages.edit_check_method
17
17
  - KeystoneUi::Pages.refusal_method
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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider