katalyst-koi 4.5.8 → 4.5.9

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: 02aaba817c8e75d9eed8d2dca586a03a28731c89746a94e92b7c8c0e0e6bc024
4
- data.tar.gz: fb4ccd92543436bd7516f4077b3924e4a55be01552e0ed69dab552e87ddce4c2
3
+ metadata.gz: '08771b81c4521daf6ece3e3772876dd33aae6b5f28c9192f20f098b7044a6fec'
4
+ data.tar.gz: 255024e1221fcaac47c145a866d331a8ed135686cad306e7104578602c72ac2f
5
5
  SHA512:
6
- metadata.gz: 350338e7f380b480e18cb126895475cefb02bf890d39fdc6ec7bf1ea0bcf3aba30732f25bf9b33168eb186a7161e09a10a50ade515bea63ee61d0e4f15b58389
7
- data.tar.gz: 962680c5043e50c1e0b38a36ebf2caf712a40ed9c4f49c33614bcacdf3882ba72157649d5bfe793649dc2ab03a919b42037ffb8e4cbce0516e7aba0048488399
6
+ metadata.gz: 4835ecf31eccc9160aa3ba9ed93cdb0d8391f63996046f74bf82a5d25991ba9b9b546ad7c4750e470fcffcf398b74118ecf4525bab059bb560e2374f99cf9722
7
+ data.tar.gz: 9195e5a7a56909414f36ce7bdf2ebd714ca7b9525577f2c8a6bb816ae74712e985098418e1a5897ee64c33f031ac14f4b8c32e54a94af2468d451274d4f77ad8
@@ -7,15 +7,11 @@ module GOVUKDesignSystemFormBuilder
7
7
  class Document < Base
8
8
  include FileElement
9
9
 
10
- MIME_TYPES = %w[
11
- image/png image/gif image/jpeg image/webp
12
- application/pdf audio/*
13
- ].freeze
14
-
15
- def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
10
+ def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, mime_types:,
11
+ **kwargs, &block)
16
12
  super(builder, object_name, attribute_name, &block)
17
13
 
18
- @mime_types = kwargs.fetch(:mime_types, MIME_TYPES)
14
+ @mime_types = mime_types
19
15
  @label = label
20
16
  @caption = caption
21
17
  @hint = hint
@@ -57,9 +53,17 @@ module GOVUKDesignSystemFormBuilder
57
53
  # @example A upload field with label as a proc
58
54
  # = f.govuk_document_field :data, label: -> { tag.h3('Upload your document') }
59
55
  #
60
- def govuk_document_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
61
- Elements::Document.new(self, object_name, attribute_name, label:, caption:, hint:, form_group:, **kwargs,
62
- &block).html
56
+ def govuk_document_field(attribute_name,
57
+ label: {},
58
+ caption: {},
59
+ hint: {},
60
+ form_group: {},
61
+ mime_types: Koi.config.document_mime_types,
62
+ **kwargs,
63
+ &block)
64
+ Elements::Document.new(
65
+ self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **kwargs, &block
66
+ ).html
63
67
  end
64
68
  end
65
69
  end
@@ -8,12 +8,11 @@ module GOVUKDesignSystemFormBuilder
8
8
  class Image < Base
9
9
  include FileElement
10
10
 
11
- MIME_TYPES = %w[image/png image/gif image/jpeg image/webp].freeze
12
-
13
- def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
11
+ def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, mime_types:,
12
+ **kwargs, &block)
14
13
  super(builder, object_name, attribute_name, &block)
15
14
 
16
- @mime_types = kwargs[:mime_types] || MIME_TYPES
15
+ @mime_types = mime_types
17
16
  @label = label
18
17
  @caption = caption
19
18
  @hint = hint
@@ -84,9 +83,17 @@ module GOVUKDesignSystemFormBuilder
84
83
  # @example A image upload field with label as a proc
85
84
  # = f.govuk_image_field :image, label: -> { tag.h3('Upload your image') }
86
85
  #
87
- def govuk_image_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
88
- Elements::Image.new(self, object_name, attribute_name,
89
- label:, caption:, hint:, form_group:, **kwargs, &block).html
86
+ def govuk_image_field(attribute_name,
87
+ label: {},
88
+ caption: {},
89
+ hint: {},
90
+ form_group: {},
91
+ mime_types: Koi.config.image_mime_types,
92
+ **kwargs,
93
+ &block)
94
+ Elements::Image.new(
95
+ self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **kwargs, &block
96
+ ).html
90
97
  end
91
98
  end
92
99
  end
data/lib/koi/config.rb CHANGED
@@ -9,8 +9,18 @@ module Koi
9
9
 
10
10
  config_accessor(:resource_name_candidates) { %i[title name] }
11
11
 
12
- config_accessor(:image_size_limit) { 10.megabytes }
13
-
14
12
  config_accessor(:admin_stylesheet) { "koi/admin" }
13
+
14
+ config_accessor(:document_mime_types) do
15
+ %w[image/png image/gif image/jpeg image/webp application/pdf audio/*].freeze
16
+ end
17
+
18
+ config_accessor(:document_size_limit) { 10.megabytes }
19
+
20
+ config_accessor(:image_mime_types) do
21
+ %w[image/png image/gif image/jpeg image/webp].freeze
22
+ end
23
+
24
+ config_accessor(:image_size_limit) { 10.megabytes }
15
25
  end
16
26
  end
@@ -36,28 +36,24 @@ module Koi
36
36
 
37
37
  # @api internal
38
38
  # @see GOVUKDesignSystemFormBuilder::Builder#govuk_document_field
39
- def govuk_document_field(attribute_name, hint: {}, **kwargs, &block)
40
- max_size = hint[:max_size] || Koi.config.image_size_limit
41
- super(attribute_name, hint:, **kwargs) do
42
- if block
43
- concat(yield)
44
- else
45
- concat(t("helpers.hint.default.document", max_size: @template.number_to_human_size(max_size)))
46
- end
39
+ def govuk_document_field(attribute_name, hint: {}, **, &)
40
+ if hint.is_a?(Hash)
41
+ max_size = hint.fetch(:max_size, Koi.config.document_size_limit)
42
+ hint[:text] ||= t("helpers.hint.default.document", max_size: @template.number_to_human_size(max_size))
47
43
  end
44
+
45
+ super(attribute_name, hint:, **, &)
48
46
  end
49
47
 
50
48
  # @api internal
51
49
  # @see GOVUKDesignSystemFormBuilder::Builder#govuk_image_field
52
- def govuk_image_field(attribute_name, hint: {}, **kwargs, &block)
53
- max_size = hint[:max_size] || Koi.config.image_size_limit
54
- super(attribute_name, hint:, **kwargs) do
55
- if block
56
- concat(yield)
57
- else
58
- concat(t("helpers.hint.default.image", max_size: @template.number_to_human_size(max_size)))
59
- end
50
+ def govuk_image_field(attribute_name, hint: {}, **, &)
51
+ if hint.is_a?(Hash)
52
+ max_size = hint.fetch(:max_size, Koi.config.image_size_limit)
53
+ hint[:text] ||= t("helpers.hint.default.document", max_size: @template.number_to_human_size(max_size))
60
54
  end
55
+
56
+ super(attribute_name, hint:, **, &)
61
57
  end
62
58
 
63
59
  # Use content editor trix setup by default.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-koi
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.8
4
+ version: 4.5.9
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-03-27 00:00:00.000000000 Z
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails