shimmer 0.0.22 → 0.0.24

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: 36f3761e1bd5856a9fd2078201abda25b544eff5e807566ce85847ba291c47d9
4
- data.tar.gz: c946f2ec830a472aee08d835dbb697711d46c107152723ee8f9bb43a36bc4173
3
+ metadata.gz: c0eaed2568e6fdbdc41b8c47337b1c514f0db410c597c3b5727eb3de9ffa2367
4
+ data.tar.gz: b946998c24efbe8fe0307ef55ea9971233be36623cdbcdbd283306c319132d02
5
5
  SHA512:
6
- metadata.gz: d8bb839595c9e32ab185276bdaac0c8a6f43b4ce1fb1ce0d82d47a1c18c5ae082e29caa68c34d14856db2ebb2001fe4774f5b687599b794706d199767bd46de1
7
- data.tar.gz: 885c2bdb0326b02c3eebd7d4606d79906b52264ef8b6043dc6f4061dffd6c8b5a786af22f9d25378d7aa21988a34d6412409adcd7acb6acce7f478e342323eba
6
+ metadata.gz: 13279649e9331c200c8491974f57fc659aff3b60242f93683fba9a55d0d75583a32c6b9eaab4a4d128207f5be416b55493af629cd87edd02d01cc52c946da4da
7
+ data.tar.gz: 8f200cd8ed792dc4a33d2ab7fc2d0607a00ea9a2a4ad32f278d655a21d1510d7cd614483d15077cb99ab2ca9b124c6ec94b02cf8471740b0b17497f94bc61354
@@ -13,7 +13,7 @@ module Shimmer
13
13
  end
14
14
  end
15
15
 
16
- def input(method, as: guess_type(method), **options)
16
+ def input(method, as: guess_type(method), wrapper_options: {}, description: nil, **options)
17
17
  as ||= guess_type(method)
18
18
  options[:class] ||= "input__input"
19
19
  collection = options.delete :collection
@@ -25,12 +25,12 @@ module Shimmer
25
25
  options[:required] ||= true if options[:required].nil? && required_attributes.include?(method)
26
26
  options[:data] ||= {}
27
27
  options[:data][:controller] = options.delete(:controller) if options[:controller]
28
- wrapper_data = {}
29
28
  extra = []
30
29
  input_class = self.class.input_registry[as]
31
30
  raise "Unknown type #{as}" unless input_class
32
31
  input = input_class.new(builder: self, method: method, options: options, id_method: id_method, collection: collection, name_method: name_method)
33
- wrap method: method, content: input.render, classes: classes + ["input--#{as}"], label: options[:label], data: wrapper_data, extra: extra
32
+ wrapper_options.reverse_merge! input.wrapper_options
33
+ wrap method: method, content: input.render, classes: classes + ["input--#{as}"], label: options[:label], extra: extra, description: description, options: wrapper_options
34
34
  end
35
35
 
36
36
  private
@@ -65,13 +65,14 @@ module Shimmer
65
65
  object.class.types.keys if object.class.respond_to?(method.to_s.pluralize)
66
66
  end
67
67
 
68
- def wrap(method:, content:, classes:, label:, data: nil, extra: nil)
68
+ def wrap(method:, content:, classes:, label:, data: nil, extra: nil, description: nil, options: {})
69
69
  if object&.errors&.[](method)&.any?
70
70
  classes << "input--error"
71
71
  errors = safe_join(object.errors[method].map { |e| content_tag :div, e, class: "input__error" })
72
72
  end
73
73
  label = label == false ? nil : self.label(method, label, class: "input__label")
74
- content_tag(:div, safe_join([label, content, errors, extra].compact), class: ["input"] + classes, data: data)
74
+ description = description.presence ? content_tag(:div, description, class: "input__description") : nil
75
+ content_tag(:div, safe_join([label, content, description, errors, extra].compact), class: ["input"] + classes, **options)
75
76
  end
76
77
 
77
78
  def helper
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shimmer
4
+ module Form
5
+ class CheckboxField < Field
6
+ self.type = :checkbox
7
+
8
+ def render
9
+ builder.check_box method, options
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shimmer
4
+ module Form
5
+ class DatetimeField < Field
6
+ self.type = :datetime
7
+
8
+ def render
9
+ builder.datetime_field method, options
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,6 +13,10 @@ module Shimmer
13
13
  end
14
14
  end
15
15
 
16
+ def wrapper_options
17
+ {}
18
+ end
19
+
16
20
  def initialize(builder:, method:, collection:, id_method:, name_method:, options: {})
17
21
  @builder = builder
18
22
  @method = method
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shimmer
4
+ module Form
5
+ class ImageField < Field
6
+ self.type = :image
7
+
8
+ def render
9
+ builder.file_field method, options.reverse_merge(accept: "image/*")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -27,19 +27,27 @@ module Shimmer
27
27
  end
28
28
 
29
29
  def image_file_path(source, width: nil, height: nil)
30
- image_file_proxy(source, width: width, height: height)&.path
30
+ image_file_proxy(source, width: width, height: height, return_type: :path)
31
31
  end
32
32
 
33
33
  def image_file_url(source, width: nil, height: nil)
34
- image_file_proxy(source, width: width, height: height)&.url
34
+ image_file_proxy(source, width: width, height: height, return_type: :url)
35
35
  end
36
36
 
37
- def image_file_proxy(source, width: nil, height: nil)
37
+ def image_file_proxy(source, width: nil, height: nil, return_type: nil)
38
38
  return if source.blank?
39
39
  return source if source.is_a?(String)
40
40
 
41
41
  blob = source.try(:blob) || source
42
- Shimmer::FileProxy.new(blob_id: blob.id, width: width, height: height)
42
+ proxy = Shimmer::FileProxy.new(blob_id: blob.id, width: width, height: height)
43
+ case return_type
44
+ when nil
45
+ proxy
46
+ when :path
47
+ proxy.path
48
+ when :url
49
+ proxy.url
50
+ end
43
51
  end
44
52
  end
45
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shimmer
4
- VERSION = "0.0.22"
4
+ VERSION = "0.0.24"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Ravens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-11 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -147,10 +147,13 @@ files:
147
147
  - lib/shimmer/controllers/sitemaps_controller.rb
148
148
  - lib/shimmer/form.rb
149
149
  - lib/shimmer/form/builder.rb
150
+ - lib/shimmer/form/checkbox_field.rb
150
151
  - lib/shimmer/form/checkboxes_field.rb
151
152
  - lib/shimmer/form/date_field.rb
153
+ - lib/shimmer/form/datetime_field.rb
152
154
  - lib/shimmer/form/email_field.rb
153
155
  - lib/shimmer/form/field.rb
156
+ - lib/shimmer/form/image_field.rb
154
157
  - lib/shimmer/form/number_field.rb
155
158
  - lib/shimmer/form/password_field.rb
156
159
  - lib/shimmer/form/pdf_field.rb