katalyst-content 2.5.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f1e48e5c4ca1dd80c1f2cf5b55d10ced110836871d8b6e6565f2a6374ebcd9d
4
- data.tar.gz: 857859a63e6bcd2fabefdbbe26f7980b9e5f528aa283a1ac2bf5d8df1de9f257
3
+ metadata.gz: 57fa137dad1c3a60f7f6689ef806fac3ae17a0dbb4fc21d2e1b4392e1bf47d7f
4
+ data.tar.gz: 5e528a67bcc761b93a639671132cd554b33b25632840aada6453af58b5866ff6
5
5
  SHA512:
6
- metadata.gz: 221c2e9c19c45d041022ad6ba4120553463f9c084eed5e323ceaedaf5dfceef792f7c7c2edce9bc67bf44ea5128b75908ed8366e8585e12de3226b04b0e374fb
7
- data.tar.gz: bec1eedffc4d2f6c814d83dfc01c8e627cd1ec669d119eef291ff51d946f384c8c548126266a21d7b5d738e8bb024d76e203f6d151b7989c6ccbb70bba9ab5cd
6
+ metadata.gz: '0785c75b21825b29dae88e7cec9ec3fe409e683a5a28ff08a9a27ada05129045409df9a0e07e52f23b6361d717b1562254a88151c03c23c4eab1c7caa3d659fe'
7
+ data.tar.gz: 95c86f1111d721bff45326298f256289032d0f4fae91d4d0302c3261c28c61cc5bf240241959e9dd05247b417c96581c14c08fea14598eadf5d6e79e39a60a21
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Katalyst
4
+ module Content
5
+ module HasStyle
6
+ extend ActiveSupport::Concern
7
+
8
+ # Style attribute allows items to define their own attributes for use in
9
+ # content styles. These attribute will be automatically mapped to json
10
+ # data which is stored and deserialized without needing to add columns.
11
+ class_methods do
12
+ def style_attributes(&)
13
+ style_class = Class.new(Katalyst::Content::HasStyle::StyleBase, &)
14
+ const_set(:Style, style_class)
15
+ attribute(:style, Katalyst::Content::Types::StyleType.new(style_class), default: -> { style_class.new })
16
+
17
+ style_class.attribute_names.each do |name|
18
+ define_method(name) { style.public_send(name) }
19
+ define_method(:"#{name}=") { |value| style.public_send(:"#{name}=", value) }
20
+ end
21
+
22
+ validate do
23
+ style.validate(validation_context)
24
+ style.errors.each do |error|
25
+ errors.add(error.attribute, error.type)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ class StyleBase
32
+ include ActiveModel::Model
33
+ include ActiveModel::Attributes
34
+ end
35
+ end
36
+ end
37
+ end
@@ -3,6 +3,13 @@
3
3
  module Katalyst
4
4
  module Content
5
5
  class Aside < Layout
6
+ style_attributes do
7
+ attribute :reverse, :boolean, default: false
8
+ end
9
+
10
+ def self.permitted_params
11
+ super + %i[reverse]
12
+ end
6
13
  end
7
14
  end
8
15
  end
@@ -4,11 +4,13 @@ module Katalyst
4
4
  module Content
5
5
  # STI base class for content items
6
6
  class Item < ApplicationRecord
7
+ include HasStyle
8
+
7
9
  def self.config
8
10
  Katalyst::Content.config
9
11
  end
10
12
 
11
- enum heading_style: config.heading_styles, _prefix: :heading
13
+ enum :heading_style, config.heading_styles, prefix: :heading
12
14
 
13
15
  belongs_to :container, polymorphic: true
14
16
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Katalyst
4
+ module Content
5
+ module Types
6
+ # Data serialization/deserialization for Katalyst::Content::Item style data
7
+ class StyleType < ActiveRecord::Type::Json
8
+ def initialize(type)
9
+ super()
10
+
11
+ @type = type
12
+ end
13
+
14
+ def serialize(value)
15
+ super(value.attributes)
16
+ end
17
+
18
+ def deserialize(value)
19
+ case value
20
+ when String
21
+ decoded = super
22
+ @type.new(**decoded) unless decoded.nil?
23
+ when Hash
24
+ @type.new(**value)
25
+ when HasStyle::StyleBase
26
+ value
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -22,6 +22,11 @@
22
22
  <%= form.check_box :visible %>
23
23
  </div>
24
24
 
25
+ <div class="field">
26
+ <%= form.label :reverse %>
27
+ <%= form.check_box :reverse %>
28
+ </div>
29
+
25
30
  <%= form.submit "Done" %>
26
31
  <%= link_to "Discard", :back %>
27
32
  <% end %>
@@ -4,7 +4,7 @@
4
4
  <% if aside.children.any? %>
5
5
  <% items = aside.children.select(&:visible?) %>
6
6
  <% last = items.pop %>
7
- <div role="aside-container">
7
+ <div role="aside-container" <%= "class=reverse" if aside.reverse %>>
8
8
  <div>
9
9
  <%= render_content_items items %>
10
10
  </div>
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddStyleToContentItems < ActiveRecord::Migration[7.1]
4
+ def change
5
+ add_column :katalyst_content_items, :style, :json, null: false, default: {}
6
+ end
7
+ end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '7.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.2'
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: active_storage_validations
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +148,7 @@ files:
128
148
  - app/javascript/content/editor/trix_controller.js
129
149
  - app/models/concerns/katalyst/content/container.rb
130
150
  - app/models/concerns/katalyst/content/garbage_collection.rb
151
+ - app/models/concerns/katalyst/content/has_style.rb
131
152
  - app/models/concerns/katalyst/content/has_tree.rb
132
153
  - app/models/concerns/katalyst/content/version.rb
133
154
  - app/models/katalyst/content/aside.rb
@@ -142,6 +163,7 @@ files:
142
163
  - app/models/katalyst/content/table.rb
143
164
  - app/models/katalyst/content/tables/importer.rb
144
165
  - app/models/katalyst/content/types/nodes_type.rb
166
+ - app/models/katalyst/content/types/style_type.rb
145
167
  - app/views/active_storage/blobs/_blob.html.erb
146
168
  - app/views/katalyst/content/asides/_aside.html+form.erb
147
169
  - app/views/katalyst/content/asides/_aside.html.erb
@@ -172,6 +194,7 @@ files:
172
194
  - db/migrate/20220913003839_create_katalyst_content_items.rb
173
195
  - db/migrate/20220926061535_add_fields_for_figure_to_katalyst_content_items.rb
174
196
  - db/migrate/20230515151440_change_katalyst_content_items_show_heading_column.rb
197
+ - db/migrate/20240826042004_add_style_to_content_items.rb
175
198
  - lib/katalyst/content.rb
176
199
  - lib/katalyst/content/config.rb
177
200
  - lib/katalyst/content/engine.rb