shimmer 0.0.22 → 0.0.23

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: 5b8e13a67c158deb5255b9a047415eca407baded8da093d1710c2a63d4e505fb
4
+ data.tar.gz: ecdfa43b53f32bca080085f2a1ffafe6393ba2c6739137843d54913fdadd0327
5
5
  SHA512:
6
- metadata.gz: d8bb839595c9e32ab185276bdaac0c8a6f43b4ce1fb1ce0d82d47a1c18c5ae082e29caa68c34d14856db2ebb2001fe4774f5b687599b794706d199767bd46de1
7
- data.tar.gz: 885c2bdb0326b02c3eebd7d4606d79906b52264ef8b6043dc6f4061dffd6c8b5a786af22f9d25378d7aa21988a34d6412409adcd7acb6acce7f478e342323eba
6
+ metadata.gz: 84811ac4a7369eff4cd958e0a111151dc98a9998ef0a087959b2ecb41cc883def34ffe4db77d0eb2ec66be752106f654a8884d01aad7e8d5666a02ef80555ca9
7
+ data.tar.gz: 5830376aea6021ddf9b557ddab8ebe3b1157cc08ecc5badaead61cf024d24bed9013b3264b350c362b0b3b4f63eb295496595b07d900a36a0f2efe5b3a7a3912
@@ -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
@@ -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.23"
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.23
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