katalyst-tables 3.4.4 → 3.4.6

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: 4dc2698abbad7fb7b3f49ead09af73c697bdef0f31371c6b2c0c69478ab0df5f
4
- data.tar.gz: dea2e28dfed3ce6c39ccf61f607755915fa86e138f3ac59f55e926049c5ec34d
3
+ metadata.gz: f333ba93cb729a1f41be52b7e5c63dc94e96f4bef109b0c3dfc45b341ba50455
4
+ data.tar.gz: a7269053206d9f707a4e8d9ab27f26c86f6ee09c1b72701a2bdcae74cf2ba4cd
5
5
  SHA512:
6
- metadata.gz: 6ab5ffed559436e0ed73671445d653ab603e48be03f2099ae39e8b6e4bcbe2d2b503752dd2fa722b9673dbdc9a2309e52c45841dabbf6443f83a0e5dd9c57671
7
- data.tar.gz: 832a7746ba587a059810117e215c5dd2011604d92e8f1be63e8842dce1b8d15153f789a41834a0a912dc6410356abda2eaa63d0574ee8c4fb372c9456146c3a2
6
+ metadata.gz: 4a43742d78a0b82297ad3e09eddfae8de56b3a2a4ecb41ed44eec2b6d73ada2f29b0cec888781e0f16c35a91a71614303ab05711c243692e9b413de9a2298931
7
+ data.tar.gz: de6edd608168b5e78c4fbf9708565af15c7a80c3bc155b2191d2ab9c257ce5312ea0ebd61a101e08b5662b07e120190f6a46af73f7db94c6ac092b670af88d99
@@ -9,7 +9,11 @@
9
9
  small {
10
10
  background: var(--tag-color);
11
11
  border-radius: 0.25rem;
12
- padding: 0.25rem 0.5rem;
12
+ padding: 0.25rem;
13
13
  font-size: small;
14
14
  }
15
15
  }
16
+
17
+ table td.type-enum {
18
+ text-overflow: unset;
19
+ }
@@ -26,15 +26,30 @@ module Katalyst
26
26
  keys = keys.select { |key| key.include?(attribute.value_before_type_cast.last) }
27
27
  end
28
28
 
29
- keys.map { |key| example(key, describe_key(model, attribute.name, key)) }
29
+ keys.map { |key| example(key, describe_key(model, attribute, key)) }
30
30
  end
31
31
 
32
32
  private
33
33
 
34
- def describe_key(model, name, key)
35
- label = model.human_attribute_name(name).downcase
36
- value = model.human_attribute_name("#{name}.#{key}").downcase
37
- "#{model.model_name.human} #{label} is #{value}"
34
+ def cast_value(value)
35
+ value.to_s
36
+ end
37
+
38
+ def describe_key(model, attribute, key)
39
+ label = model.human_attribute_name(attribute.name).downcase
40
+ value = model.human_attribute_name("#{attribute.name}.#{key}").downcase
41
+
42
+ description = "#{model.model_name.human} #{label} is #{value}"
43
+ description += " (default)" if default?(attribute, key)
44
+ description
45
+ end
46
+
47
+ def default?(attribute, value)
48
+ if multiple?
49
+ attribute.original_value&.intersection(cast(value))&.any?
50
+ else
51
+ attribute.default_value.eql?(cast(value))
52
+ end
38
53
  end
39
54
  end
40
55
  end
@@ -48,7 +48,10 @@ module Katalyst
48
48
  def examples_for(scope, attribute, limit: 10, order: :asc)
49
49
  scope, model, column = model_and_column_for(scope, attribute)
50
50
 
51
- return unless model.attribute_types.has_key?(column)
51
+ unless model.attribute_types.has_key?(column)
52
+ raise(ArgumentError, "Unknown column '#{column}' for #{model}. " \
53
+ "Consider defining '#{attribute.name.parameterize.underscore}_examples'")
54
+ end
52
55
 
53
56
  column = model.arel_table[column]
54
57
 
@@ -2,23 +2,6 @@
2
2
 
3
3
  require "active_model/type"
4
4
 
5
- require "katalyst/tables/collection/type/helpers/delegate"
6
- require "katalyst/tables/collection/type/helpers/extensions"
7
- require "katalyst/tables/collection/type/helpers/multiple"
8
- require "katalyst/tables/collection/type/helpers/range"
9
-
10
- require "katalyst/tables/collection/type/example"
11
- require "katalyst/tables/collection/type/value"
12
-
13
- require "katalyst/tables/collection/type/boolean"
14
- require "katalyst/tables/collection/type/date"
15
- require "katalyst/tables/collection/type/enum"
16
- require "katalyst/tables/collection/type/float"
17
- require "katalyst/tables/collection/type/integer"
18
- require "katalyst/tables/collection/type/query"
19
- require "katalyst/tables/collection/type/search"
20
- require "katalyst/tables/collection/type/string"
21
-
22
5
  module Katalyst
23
6
  module Tables
24
7
  module Collection
@@ -41,15 +24,6 @@ module Katalyst
41
24
  @default_value ||= Value.new
42
25
  end
43
26
  end
44
-
45
- register(:boolean, Type::Boolean)
46
- register(:date, Type::Date)
47
- register(:enum, Type::Enum)
48
- register(:float, Type::Float)
49
- register(:integer, Type::Integer)
50
- register(:string, Type::String)
51
- register(:query, Type::Query)
52
- register(:search, Type::Search)
53
27
  end
54
28
  end
55
29
  end
@@ -18,6 +18,19 @@ module Katalyst
18
18
 
19
19
  config_accessor(:date_format) { :default }
20
20
  config_accessor(:datetime_format) { :default }
21
+
22
+ config_accessor(:collection_types) do
23
+ {
24
+ boolean: "Katalyst::Tables::Collection::Type::Boolean",
25
+ date: "Katalyst::Tables::Collection::Type::Date",
26
+ enum: "Katalyst::Tables::Collection::Type::Enum",
27
+ float: "Katalyst::Tables::Collection::Type::Float",
28
+ integer: "Katalyst::Tables::Collection::Type::Integer",
29
+ string: "Katalyst::Tables::Collection::Type::String",
30
+ query: "Katalyst::Tables::Collection::Type::Query",
31
+ search: "Katalyst::Tables::Collection::Type::Search",
32
+ }
33
+ end
21
34
  end
22
35
  end
23
36
  end
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails"
3
+ require "katalyst/html_attributes"
4
+ require "rails/engine"
5
+ require "view_component"
4
6
 
5
7
  module Katalyst
6
8
  module Tables
7
9
  class Engine < ::Rails::Engine # :nodoc:
8
10
  isolate_namespace Katalyst::Tables
11
+ config.eager_load_namespaces << Katalyst::Tables
12
+ config.paths.add("lib", autoload: true)
9
13
 
10
14
  initializer "katalyst-tables.asset" do
11
15
  config.after_initialize do |app|
@@ -21,6 +25,14 @@ module Katalyst
21
25
  app.config.importmap.cache_sweepers << root.join("app/assets/builds")
22
26
  end
23
27
  end
28
+
29
+ initializer "katalyst-tables.collection-types" do |app|
30
+ app.reloader.to_prepare do
31
+ Tables.config.collection_types.each do |key, type|
32
+ Collection::Type.register(key, type.constantize)
33
+ end
34
+ end
35
+ end
24
36
  end
25
37
  end
26
38
  end
@@ -1,18 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
- require "active_support/rails"
5
- require "view_component"
6
- require "katalyst/html_attributes"
7
-
8
- require_relative "tables/config"
9
- require_relative "tables/engine"
10
4
 
11
5
  module Katalyst
12
6
  module Tables
13
7
  extend ActiveSupport::Autoload
14
8
 
15
- autoload :Collection
9
+ autoload :Config
16
10
 
17
11
  class Error < StandardError; end
18
12
 
@@ -25,3 +19,5 @@ module Katalyst
25
19
  end
26
20
  end
27
21
  end
22
+
23
+ require "katalyst/tables/engine"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.4
4
+ version: 3.4.6
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-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katalyst-html-attributes