katalyst-content 3.1.0 → 3.1.2

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: d1be194d961a873a0cdb20f871b5ff57f57ff1b5b503dfc8716b1004b6b6a4e6
4
- data.tar.gz: b3f45e0d9e23450e39055da1cd5b15b3b93865fa7b37b6cc632ff900041e0d60
3
+ metadata.gz: 5e38cbf36ab348007822df1209895dd018187732543a5e30a415b45c6c76eea2
4
+ data.tar.gz: 1594f99bc385122dec95d1193579de7f7405981233fdff7d304f8628295883fc
5
5
  SHA512:
6
- metadata.gz: 647b389cbc0c4b8c27227c377a910c04906cb46e34be09d12914f368d2699a0d778b73b7a2e5d493dd45c4f6de9303a366f45f4246984db6b3764294ab2f794b
7
- data.tar.gz: af45914d0047b3b13d4ea19051fb2914cfa4aebf81809af22d14ef022332dd51683d49f10fc5685e9e32e8225bd3712d2c0b51c85df7c033cf1d5457458e4e55
6
+ metadata.gz: 5881d775194f04bb5ac2b53b7585281661c5633306cbf91dbae7c08853ee1e5eba22c92366c65152836543c3c01bbd0952610c77330a2630d0f9cd4c776a9842
7
+ data.tar.gz: 425ca40e2cd4b354e792e09a25dc6ec3cd0a99a4725ee5ce862f7ff9886d4d07fe161882be1a5c209dc5137cd09ef1b2412769a9883c7482a93f83e16fb8866b
data/README.md CHANGED
@@ -78,6 +78,35 @@ class CreatePageVersions < ActiveRecord::Migration[7.0]
78
78
  end
79
79
  ```
80
80
 
81
+ If you don't have a pages model yet, add it before the page_versions change:
82
+ ```ruby
83
+ class CreatePages < ActiveRecord::Migration[7.0]
84
+ def change
85
+ create_table :pages do |t|
86
+ t.string :title
87
+ t.string :slug
88
+ t.boolean :show_title, default: true, null: false
89
+
90
+ t.timestamps
91
+ end
92
+ add_index :pages, :slug, unique: true
93
+
94
+ create_table :page_versions do |t|
95
+ t.references :parent, foreign_key: { to_table: :pages }, null: false
96
+ t.json :nodes
97
+
98
+ t.timestamps
99
+ end
100
+
101
+ change_table :pages do |t|
102
+ t.references :published_version, foreign_key: { to_table: :page_versions }
103
+ t.references :draft_version, foreign_key: { to_table: :page_versions }
104
+ end
105
+ end
106
+ end
107
+ ```
108
+
109
+
81
110
  Next, include the `Katalyst::Content` concerns into your model, and add a nested
82
111
  model for storing content version information:
83
112
 
@@ -34,22 +34,18 @@
34
34
  }
35
35
 
36
36
  .content-item [data-content-theme] {
37
+ background: var(--background, unset);
38
+ color: var(--text-color);
37
39
  padding-inline: var(--content-inline-gutter);
38
40
  }
39
41
 
40
42
  [data-content-theme="light"] {
41
- background: var(--background, var(--background-color));
42
- color: var(--text-color);
43
-
44
43
  --text-color: var(--color-dark, black);
45
44
  --background: var(--color-light, black);
46
45
  --link-color: var(--color-dark, black);
47
46
  }
48
47
 
49
48
  [data-content-theme="dark"] {
50
- background: var(--background, var(--background-color));
51
- color: var(--text-color);
52
-
53
49
  --text-color: var(--color-light, white);
54
50
  --background: var(--color-dark, black);
55
51
  --link-color: var(--color-light, white);
@@ -14,7 +14,7 @@ module Katalyst
14
14
  super(**)
15
15
 
16
16
  @container = container
17
- @item = item
17
+ @item = item
18
18
  end
19
19
 
20
20
  def call; end
@@ -50,7 +50,7 @@ module Katalyst
50
50
 
51
51
  def item_params_type
52
52
  requested_type = params.require(:item).fetch(:type, "")
53
- if (type = Katalyst::Content.config.items.find { |t| t == requested_type })
53
+ if (type = Katalyst::Content.config.items.find { |t| t == requested_type })
54
54
  type.safe_constantize
55
55
  else
56
56
  Item
@@ -70,9 +70,9 @@ module Katalyst
70
70
  end
71
71
 
72
72
  def set_item
73
- @item = Item.find(params[:id])
73
+ @item = Item.find(params.expect(:id))
74
74
  @container = @item.container
75
- @editor = Katalyst::Content::EditorComponent.new(container:, item:)
75
+ @editor = Katalyst::Content::EditorComponent.new(container:, item:)
76
76
  end
77
77
 
78
78
  def set_editor_variant
@@ -9,7 +9,7 @@ module Katalyst
9
9
  if item.valid?
10
10
  render :update, locals: { item_editor: }
11
11
  else
12
- render :update, locals: { item_editor: }, status: :unprocessable_entity
12
+ render :update, locals: { item_editor: }, status: :unprocessable_content
13
13
  end
14
14
  end
15
15
  alias_method :create, :update
@@ -53,7 +53,7 @@ module Katalyst
53
53
 
54
54
  return unless @node
55
55
 
56
- @heading_rows = @table.heading_rows.clamp(0..css("tr").length)
56
+ @heading_rows = @table.heading_rows.clamp(0..css("tr").length)
57
57
  @heading_columns = @table.heading_columns.clamp(0..)
58
58
  end
59
59
 
@@ -94,7 +94,7 @@ module Katalyst
94
94
  # e.g. colspan=2 rowspan=3 would occupy 6 cells
95
95
  row_range(cell, y).each do |ty|
96
96
  col_range(cell, x).each do |tx|
97
- matrix[ty] ||= []
97
+ matrix[ty] ||= []
98
98
  matrix[ty][tx] = cell.text
99
99
  end
100
100
  end
@@ -49,11 +49,8 @@ module Katalyst
49
49
  dependent: :destroy,
50
50
  validate: true
51
51
 
52
- # Rails 7.2 dropped support for ActiveModel enums. This is a temporary workaround.
53
- # Intended behaviour:
54
- # attribute :state, :string
55
- # enum :state, %i[published draft unpublished].index_with(&:to_s)
56
52
  attribute :state, :string
53
+ enum :state, %i[published draft unpublished].index_with(&:to_s)
57
54
 
58
55
  # Returns true if there is a published version. Note that this includes drafts.
59
56
  def published?
@@ -154,7 +151,7 @@ module Katalyst
154
151
  private
155
152
 
156
153
  def unset_versions
157
- self.draft_version_id = nil
154
+ self.draft_version_id = nil
158
155
  self.published_version_id = nil
159
156
  save!(validate: false)
160
157
  end
@@ -57,7 +57,7 @@ module Katalyst
57
57
 
58
58
  # Add node to the top of builder stacks
59
59
  def push(node)
60
- self.depth += 1
60
+ self.depth += 1
61
61
  self.current = node
62
62
  self.children = node.children = []
63
63
  node
@@ -65,7 +65,7 @@ module Katalyst
65
65
 
66
66
  # Remove current from builder stack
67
67
  def pop
68
- previous = current
68
+ previous = current
69
69
  self.depth -= 1
70
70
  if depth.zero?
71
71
  self.current = nil
@@ -36,7 +36,7 @@ module Katalyst
36
36
  end
37
37
 
38
38
  def text
39
- items.filter_map(&:to_plain_text).join("\n")
39
+ tree.filter_map(&:to_plain_text).join("\n")
40
40
  end
41
41
  end
42
42
  end
@@ -3,6 +3,11 @@
3
3
  module Katalyst
4
4
  module Content
5
5
  class Layout < Item
6
+ def to_plain_text
7
+ return unless visible?
8
+
9
+ [super, *children.filter_map(&:to_plain_text)].join("\n").presence
10
+ end
6
11
  end
7
12
  end
8
13
  end
@@ -77,7 +77,7 @@ module Katalyst
77
77
 
78
78
  def header_row_caption?
79
79
  !at_css("caption") &&
80
- (tr = at_css("thead > tr:first-child"))&.elements&.one? &&
80
+ (tr = at_css("thead > tr:first-child"))&.elements&.one? &&
81
81
  (colspan = tr.elements.first.attributes["colspan"]&.value) &&
82
82
  colspan.to_i > 1
83
83
  end
@@ -130,10 +130,10 @@ module Katalyst
130
130
 
131
131
  # Promotes the first row to a caption if it only has one cell.
132
132
  def promote_header_row_caption!
133
- tr = at_css("thead > tr:first-child")
134
- cell = tr.elements.first
133
+ tr = at_css("thead > tr:first-child")
134
+ cell = tr.elements.first
135
135
  tr.remove
136
- thead = at_css("thead")
136
+ thead = at_css("thead")
137
137
  thead.before("<caption></caption>")
138
138
  thead.remove if thead.elements.empty?
139
139
  at_css("caption").inner_html = cell.inner_html.strip
@@ -141,7 +141,7 @@ module Katalyst
141
141
 
142
142
  # Set heading from caption and remove the caption from the table.
143
143
  def set_heading!
144
- caption = at_css("caption")
144
+ caption = at_css("caption")
145
145
  table.heading = caption.text.strip
146
146
  table.heading_style = "default"
147
147
  caption.remove
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  requirements: []
231
- rubygems_version: 3.6.9
231
+ rubygems_version: 4.0.10
232
232
  specification_version: 4
233
233
  summary: Rich content page builder and editor
234
234
  test_files: []