katalyst-content 2.5.0 → 2.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: b6a6f54f7d667a7f22b554a812d4eeaccdf177441f9aa472b39f9cf6ecf9391f
4
- data.tar.gz: c9d797a85f1a2fa139c4aa275c55840621b76da138db1f01deb5ada1239d4a08
3
+ metadata.gz: 57fa137dad1c3a60f7f6689ef806fac3ae17a0dbb4fc21d2e1b4392e1bf47d7f
4
+ data.tar.gz: 5e528a67bcc761b93a639671132cd554b33b25632840aada6453af58b5866ff6
5
5
  SHA512:
6
- metadata.gz: 62adedcdf33603f1afe25a51bb3f44a7b956e400a58c7820fc2a09887fafd713034dc9eea56088d124e259753e99e1914cac83dd0fba9a1e70c4a1c6c40d4787
7
- data.tar.gz: 790ec607c8ce81d4bfe522f6a95dce04ed8c9c238161752446a05edaecb5ab62297cf0ea1df9cf060d4bb47fff4b75ac74da41e2e8c407b20bb51c363bae1a13
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
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails"
3
+ require "katalyst/html_attributes"
4
+ require "katalyst/kpop"
5
+ require "rails/engine"
4
6
 
5
7
  module Katalyst
6
8
  module Content
7
9
  class Engine < ::Rails::Engine
8
10
  isolate_namespace Katalyst::Content
11
+ config.eager_load_namespaces << Katalyst::Content
9
12
 
10
13
  initializer "katalyst-content.factories", after: "factory_bot.set_factory_paths" do
11
14
  FactoryBot.definition_file_paths << Engine.root.join("spec/factories") if defined?(FactoryBot)
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
- require "katalyst/html_attributes"
5
- require "katalyst/kpop"
6
-
7
- require "katalyst/content/config"
8
- require "katalyst/content/engine"
9
4
 
10
5
  module Katalyst
11
6
  module Content
7
+ extend ActiveSupport::Autoload
12
8
  extend self
13
9
 
10
+ autoload :Config
11
+
14
12
  def config
15
13
  @config ||= Config.new
16
14
  end
@@ -20,3 +18,5 @@ module Katalyst
20
18
  end
21
19
  end
22
20
  end
21
+
22
+ require "katalyst/content/engine"
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.0
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-05 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