optimism 0.3.5 → 0.4.0

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: 4243758152d4a7299eecfe0104b01187a272be5f1da3873b618441b532289f01
4
- data.tar.gz: fcdf8b15dacfa3e211e0f3ffd2bba7ba0dd9f095a93152315795bba37430e896
3
+ metadata.gz: cea48e2dd50fa40be2694720407b8f39d38dc4923eb417d98b99a2f4c7260a53
4
+ data.tar.gz: 8ff0f3651eda96026413b22296f1c98beaedb5bf1148a66ab60b7ba1c90a3645
5
5
  SHA512:
6
- metadata.gz: 0ae487f731194a11c364aea1fc5baefbdef1496dc536c5d3723be3d304d73a4fab36d6179ff2b86ddc5949a39129fe1a1edb284742ae88d7f68c7b99f78f1398
7
- data.tar.gz: ae7cb3a35fcbe92e3a03ce5698c7dc0e8029b2bbd80ec038762066295803f64692196a04505b5ce5851ed012734e48f56b5685ed79dc537fa535423213a40733
6
+ metadata.gz: 0d3ee3375b300564884967856f89da6e1a8739d5a9d891f7e714746a4168eea707e16f0819a5a47ce4d5d3771001ebd8a940a11f6ec782a699aba2b710d01dd2
7
+ data.tar.gz: 8b6443e2a38150dfe80466a02c58360033aee50f95f661f48046c410e16f8fa07c4e6f6025954ed7778782582c0f1e5f9c53dcc17c6987cc70f3d77b4ef60209
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- optimism (0.3.1)
4
+ optimism (0.3.5)
5
5
  cable_ready (>= 4)
6
6
  rack (~> 2.0)
7
7
  rails (>= 6, >= 5.2)
@@ -9,75 +9,79 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (6.0.3.2)
13
- actionpack (= 6.0.3.2)
12
+ actioncable (6.1.0)
13
+ actionpack (= 6.1.0)
14
+ activesupport (= 6.1.0)
14
15
  nio4r (~> 2.0)
15
16
  websocket-driver (>= 0.6.1)
16
- actionmailbox (6.0.3.2)
17
- actionpack (= 6.0.3.2)
18
- activejob (= 6.0.3.2)
19
- activerecord (= 6.0.3.2)
20
- activestorage (= 6.0.3.2)
21
- activesupport (= 6.0.3.2)
17
+ actionmailbox (6.1.0)
18
+ actionpack (= 6.1.0)
19
+ activejob (= 6.1.0)
20
+ activerecord (= 6.1.0)
21
+ activestorage (= 6.1.0)
22
+ activesupport (= 6.1.0)
22
23
  mail (>= 2.7.1)
23
- actionmailer (6.0.3.2)
24
- actionpack (= 6.0.3.2)
25
- actionview (= 6.0.3.2)
26
- activejob (= 6.0.3.2)
24
+ actionmailer (6.1.0)
25
+ actionpack (= 6.1.0)
26
+ actionview (= 6.1.0)
27
+ activejob (= 6.1.0)
28
+ activesupport (= 6.1.0)
27
29
  mail (~> 2.5, >= 2.5.4)
28
30
  rails-dom-testing (~> 2.0)
29
- actionpack (6.0.3.2)
30
- actionview (= 6.0.3.2)
31
- activesupport (= 6.0.3.2)
32
- rack (~> 2.0, >= 2.0.8)
31
+ actionpack (6.1.0)
32
+ actionview (= 6.1.0)
33
+ activesupport (= 6.1.0)
34
+ rack (~> 2.0, >= 2.0.9)
33
35
  rack-test (>= 0.6.3)
34
36
  rails-dom-testing (~> 2.0)
35
37
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.0.3.2)
37
- actionpack (= 6.0.3.2)
38
- activerecord (= 6.0.3.2)
39
- activestorage (= 6.0.3.2)
40
- activesupport (= 6.0.3.2)
38
+ actiontext (6.1.0)
39
+ actionpack (= 6.1.0)
40
+ activerecord (= 6.1.0)
41
+ activestorage (= 6.1.0)
42
+ activesupport (= 6.1.0)
41
43
  nokogiri (>= 1.8.5)
42
- actionview (6.0.3.2)
43
- activesupport (= 6.0.3.2)
44
+ actionview (6.1.0)
45
+ activesupport (= 6.1.0)
44
46
  builder (~> 3.1)
45
47
  erubi (~> 1.4)
46
48
  rails-dom-testing (~> 2.0)
47
49
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.0.3.2)
49
- activesupport (= 6.0.3.2)
50
+ activejob (6.1.0)
51
+ activesupport (= 6.1.0)
50
52
  globalid (>= 0.3.6)
51
- activemodel (6.0.3.2)
52
- activesupport (= 6.0.3.2)
53
- activerecord (6.0.3.2)
54
- activemodel (= 6.0.3.2)
55
- activesupport (= 6.0.3.2)
56
- activestorage (6.0.3.2)
57
- actionpack (= 6.0.3.2)
58
- activejob (= 6.0.3.2)
59
- activerecord (= 6.0.3.2)
53
+ activemodel (6.1.0)
54
+ activesupport (= 6.1.0)
55
+ activerecord (6.1.0)
56
+ activemodel (= 6.1.0)
57
+ activesupport (= 6.1.0)
58
+ activestorage (6.1.0)
59
+ actionpack (= 6.1.0)
60
+ activejob (= 6.1.0)
61
+ activerecord (= 6.1.0)
62
+ activesupport (= 6.1.0)
60
63
  marcel (~> 0.3.1)
61
- activesupport (6.0.3.2)
64
+ mimemagic (~> 0.3.2)
65
+ activesupport (6.1.0)
62
66
  concurrent-ruby (~> 1.0, >= 1.0.2)
63
- i18n (>= 0.7, < 2)
64
- minitest (~> 5.1)
65
- tzinfo (~> 1.1)
66
- zeitwerk (~> 2.2, >= 2.2.2)
67
+ i18n (>= 1.6, < 2)
68
+ minitest (>= 5.1)
69
+ tzinfo (~> 2.0)
70
+ zeitwerk (~> 2.3)
67
71
  ast (2.4.0)
68
72
  builder (3.2.4)
69
- cable_ready (4.1.2)
73
+ cable_ready (4.4.5)
70
74
  rails (>= 5.2)
71
75
  coderay (1.1.2)
72
- concurrent-ruby (1.1.6)
76
+ concurrent-ruby (1.1.7)
73
77
  crass (1.0.6)
74
- erubi (1.9.0)
78
+ erubi (1.10.0)
75
79
  globalid (0.4.2)
76
80
  activesupport (>= 4.2.0)
77
- i18n (1.8.3)
81
+ i18n (1.8.5)
78
82
  concurrent-ruby (~> 1.0)
79
83
  jaro_winkler (1.5.4)
80
- loofah (2.6.0)
84
+ loofah (2.8.0)
81
85
  crass (~> 1.0.2)
82
86
  nokogiri (>= 1.5.9)
83
87
  mail (2.7.1)
@@ -88,9 +92,9 @@ GEM
88
92
  mimemagic (0.3.5)
89
93
  mini_mime (1.0.2)
90
94
  mini_portile2 (2.4.0)
91
- minitest (5.14.1)
92
- nio4r (2.5.2)
93
- nokogiri (1.10.9)
95
+ minitest (5.14.2)
96
+ nio4r (2.5.4)
97
+ nokogiri (1.10.10-x64-mingw32)
94
98
  mini_portile2 (~> 2.4.0)
95
99
  parallel (1.19.1)
96
100
  parser (2.7.0.2)
@@ -103,32 +107,32 @@ GEM
103
107
  rack (2.2.3)
104
108
  rack-test (1.1.0)
105
109
  rack (>= 1.0, < 3)
106
- rails (6.0.3.2)
107
- actioncable (= 6.0.3.2)
108
- actionmailbox (= 6.0.3.2)
109
- actionmailer (= 6.0.3.2)
110
- actionpack (= 6.0.3.2)
111
- actiontext (= 6.0.3.2)
112
- actionview (= 6.0.3.2)
113
- activejob (= 6.0.3.2)
114
- activemodel (= 6.0.3.2)
115
- activerecord (= 6.0.3.2)
116
- activestorage (= 6.0.3.2)
117
- activesupport (= 6.0.3.2)
118
- bundler (>= 1.3.0)
119
- railties (= 6.0.3.2)
110
+ rails (6.1.0)
111
+ actioncable (= 6.1.0)
112
+ actionmailbox (= 6.1.0)
113
+ actionmailer (= 6.1.0)
114
+ actionpack (= 6.1.0)
115
+ actiontext (= 6.1.0)
116
+ actionview (= 6.1.0)
117
+ activejob (= 6.1.0)
118
+ activemodel (= 6.1.0)
119
+ activerecord (= 6.1.0)
120
+ activestorage (= 6.1.0)
121
+ activesupport (= 6.1.0)
122
+ bundler (>= 1.15.0)
123
+ railties (= 6.1.0)
120
124
  sprockets-rails (>= 2.0.0)
121
125
  rails-dom-testing (2.0.3)
122
126
  activesupport (>= 4.2.0)
123
127
  nokogiri (>= 1.6)
124
128
  rails-html-sanitizer (1.3.0)
125
129
  loofah (~> 2.3)
126
- railties (6.0.3.2)
127
- actionpack (= 6.0.3.2)
128
- activesupport (= 6.0.3.2)
130
+ railties (6.1.0)
131
+ actionpack (= 6.1.0)
132
+ activesupport (= 6.1.0)
129
133
  method_source
130
134
  rake (>= 0.8.7)
131
- thor (>= 0.20.3, < 2.0)
135
+ thor (~> 1.0)
132
136
  rainbow (3.0.0)
133
137
  rake (13.0.1)
134
138
  rubocop (0.79.0)
@@ -144,7 +148,7 @@ GEM
144
148
  sprockets (4.0.2)
145
149
  concurrent-ruby (~> 1.0)
146
150
  rack (> 1, < 3)
147
- sprockets-rails (3.2.1)
151
+ sprockets-rails (3.2.2)
148
152
  actionpack (>= 4.0)
149
153
  activesupport (>= 4.0)
150
154
  sprockets (>= 3.0.0)
@@ -154,17 +158,17 @@ GEM
154
158
  standardrb (1.0.0)
155
159
  standard
156
160
  thor (1.0.1)
157
- thread_safe (0.3.6)
158
- tzinfo (1.2.7)
159
- thread_safe (~> 0.1)
161
+ tzinfo (2.0.4)
162
+ concurrent-ruby (~> 1.0)
160
163
  unicode-display_width (1.6.1)
161
- websocket-driver (0.7.2)
164
+ websocket-driver (0.7.3)
162
165
  websocket-extensions (>= 0.1.0)
163
166
  websocket-extensions (0.1.5)
164
- zeitwerk (2.3.0)
167
+ zeitwerk (2.4.2)
165
168
 
166
169
  PLATFORMS
167
170
  ruby
171
+ x64-mingw32
168
172
 
169
173
  DEPENDENCIES
170
174
  bundler (~> 2.0)
@@ -3,22 +3,19 @@ require "optimism/version"
3
3
  require "optimism/railtie" if defined?(Rails)
4
4
 
5
5
  module Optimism
6
- include CableReady::Broadcaster
7
- class << self
8
- mattr_accessor :channel, :form_class, :error_class, :disable_submit, :suffix, :emit_events, :add_css, :inject_inline, :container_selector, :error_selector, :form_selector, :submit_selector
9
- self.channel = ->(context) { "OptimismChannel" }
10
- self.form_class = "invalid"
11
- self.error_class = "error"
12
- self.disable_submit = false
13
- self.suffix = ""
14
- self.emit_events = false
15
- self.add_css = true
16
- self.inject_inline = true
17
- self.container_selector = "#RESOURCE_ATTRIBUTE_container"
18
- self.error_selector = "#RESOURCE_ATTRIBUTE_error"
19
- self.form_selector = "#RESOURCE_form"
20
- self.submit_selector = "#RESOURCE_submit"
21
- end
6
+ mattr_accessor :channel_proc, :form_class, :error_class, :disable_submit, :suffix, :emit_events, :add_css, :inject_inline, :container_selector, :error_selector, :form_selector, :submit_selector
7
+ self.channel_proc = ->(context) { "OptimismChannel" }
8
+ self.form_class = "invalid"
9
+ self.error_class = "error"
10
+ self.disable_submit = false
11
+ self.suffix = ""
12
+ self.emit_events = false
13
+ self.add_css = true
14
+ self.inject_inline = true
15
+ self.container_selector = "#RESOURCE_ATTRIBUTE_container"
16
+ self.error_selector = "#RESOURCE_ATTRIBUTE_error"
17
+ self.form_selector = "#RESOURCE_form"
18
+ self.submit_selector = "#RESOURCE_submit"
22
19
 
23
20
  def self.configure(&block)
24
21
  yield self
@@ -41,15 +38,15 @@ module Optimism
41
38
  model.valid? if model.errors.empty?
42
39
  process_resource(model, attributes, [resource])
43
40
  if model.errors.any?
44
- cable_ready[Optimism.channel[self]].dispatch_event(name: "optimism:form:invalid", detail: {resource: resource}) if Optimism.emit_events
45
- cable_ready[Optimism.channel[self]].add_css_class(selector: form_selector, name: Optimism.form_class) if Optimism.form_class.present?
46
- cable_ready[Optimism.channel[self]].set_attribute(selector: submit_selector, name: "disabled") if Optimism.disable_submit
41
+ CableReady::Channels.instance[Optimism.channel_proc[self]].dispatch_event(name: "optimism:form:invalid", detail: {resource: resource}) if Optimism.emit_events
42
+ CableReady::Channels.instance[Optimism.channel_proc[self]].add_css_class(selector: form_selector, name: Optimism.form_class) if Optimism.form_class.present?
43
+ CableReady::Channels.instance[Optimism.channel_proc[self]].set_attribute(selector: submit_selector, name: "disabled") if Optimism.disable_submit
47
44
  else
48
- cable_ready[Optimism.channel[self]].dispatch_event(name: "optimism:form:valid", detail: {resource: resource}) if Optimism.emit_events
49
- cable_ready[Optimism.channel[self]].remove_css_class(selector: form_selector, name: Optimism.form_class) if Optimism.form_class.present?
50
- cable_ready[Optimism.channel[self]].remove_attribute(selector: submit_selector, name: "disabled") if Optimism.disable_submit
45
+ CableReady::Channels.instance[Optimism.channel_proc[self]].dispatch_event(name: "optimism:form:valid", detail: {resource: resource}) if Optimism.emit_events
46
+ CableReady::Channels.instance[Optimism.channel_proc[self]].remove_css_class(selector: form_selector, name: Optimism.form_class) if Optimism.form_class.present?
47
+ CableReady::Channels.instance[Optimism.channel_proc[self]].remove_attribute(selector: submit_selector, name: "disabled") if Optimism.disable_submit
51
48
  end
52
- cable_ready.broadcast
49
+ CableReady::Channels.instance.broadcast
53
50
  head :ok if defined?(head)
54
51
  end
55
52
 
@@ -81,18 +78,28 @@ module Optimism
81
78
  container_selector, error_selector = Optimism.container_selector.sub("RESOURCE", resource).sub("ATTRIBUTE", attribute), Optimism.error_selector.sub("RESOURCE", resource).sub("ATTRIBUTE", attribute)
82
79
  if model.errors.any? && model.errors.messages.map(&:first).include?(attribute.to_sym)
83
80
  message = "#{model.errors.full_message(attribute.to_sym, model.errors.messages[attribute.to_sym].first)}#{Optimism.suffix}"
84
- cable_ready[Optimism.channel[self]].dispatch_event(name: "optimism:attribute:invalid", detail: {resource: resource, attribute: attribute, text: message}) if Optimism.emit_events
85
- cable_ready[Optimism.channel[self]].add_css_class(selector: container_selector, name: Optimism.error_class) if Optimism.add_css
86
- cable_ready[Optimism.channel[self]].text_content(selector: error_selector, text: message) if Optimism.inject_inline
81
+ CableReady::Channels.instance[Optimism.channel_proc[self]].dispatch_event(name: "optimism:attribute:invalid", detail: {resource: resource, attribute: attribute, text: message}) if Optimism.emit_events
82
+ CableReady::Channels.instance[Optimism.channel_proc[self]].add_css_class(selector: container_selector, name: Optimism.error_class) if Optimism.add_css
83
+ CableReady::Channels.instance[Optimism.channel_proc[self]].text_content(selector: error_selector, text: message) if Optimism.inject_inline
87
84
  else
88
- cable_ready[Optimism.channel[self]].dispatch_event(name: "optimism:attribute:valid", detail: {resource: resource, attribute: attribute}) if Optimism.emit_events
89
- cable_ready[Optimism.channel[self]].remove_css_class(selector: container_selector, name: Optimism.error_class) if Optimism.add_css
90
- cable_ready[Optimism.channel[self]].text_content(selector: error_selector, text: "") if Optimism.inject_inline
85
+ CableReady::Channels.instance[Optimism.channel_proc[self]].dispatch_event(name: "optimism:attribute:valid", detail: {resource: resource, attribute: attribute}) if Optimism.emit_events
86
+ CableReady::Channels.instance[Optimism.channel_proc[self]].remove_css_class(selector: container_selector, name: Optimism.error_class) if Optimism.add_css
87
+ CableReady::Channels.instance[Optimism.channel_proc[self]].text_content(selector: error_selector, text: "") if Optimism.inject_inline
91
88
  end
92
89
  end
93
90
  end
94
91
 
95
92
  module ActionView::Helpers
93
+ module FormHelper
94
+ def error_for(object_name, attribute, **options)
95
+ tag.span options.merge! id: error_id_for(object_name, attribute)
96
+ end
97
+
98
+ def error_id_for(object_name, attribute)
99
+ Optimism.error_selector.sub("RESOURCE", object_name.to_s.delete("]").tr("[", "_")).sub("ATTRIBUTE", attribute.to_s)[1..-1]
100
+ end
101
+ end
102
+
96
103
  class FormBuilder
97
104
  def container_for(attribute, **options, &block)
98
105
  @template.tag.div @template.capture(&block), options.merge!(id: container_id_for(attribute)) if block_given?
@@ -103,11 +110,7 @@ module ActionView::Helpers
103
110
  end
104
111
 
105
112
  def error_for(attribute, **options)
106
- @template.tag.span options.merge! id: error_id_for(attribute)
107
- end
108
-
109
- def error_id_for(attribute)
110
- Optimism.error_selector.sub("RESOURCE", object_name.to_s.delete("]").tr("[", "_")).sub("ATTRIBUTE", attribute.to_s)[1..-1]
113
+ @template.error_for(object_name, attribute, options)
111
114
  end
112
115
  end
113
116
  end
@@ -1,3 +1,3 @@
1
1
  module Optimism
2
- VERSION = "0.3.5"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "standardrb", "~> 1.0.0"
28
28
  spec.add_dependency "rack", "~> 2.0"
29
29
  spec.add_dependency "rails", [">= 5.2", ">= 6"]
30
- spec.add_dependency "cable_ready", ">= 4"
30
+ spec.add_dependency "cable_ready", ">= 4.4.6"
31
31
  end
@@ -93,7 +93,7 @@ Optimism is configurable via an optional initializer file. As with all initializ
93
93
  {% code title="config/initializers/optimism.rb" %}
94
94
  ```ruby
95
95
  Optimism.configure do |config|
96
- config.channel = ->(context) { "OptimismChannel" }
96
+ config.channel_proc = ->(context) { "OptimismChannel" }
97
97
  config.form_class = "invalid"
98
98
  config.error_class = "error"
99
99
  config.disable_submit = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - leastbad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-22 00:00:00.000000000 Z
11
+ date: 2020-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
- version: '4'
123
+ version: 4.4.6
124
124
  type: :runtime
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
- version: '4'
130
+ version: 4.4.6
131
131
  description: Realtime remote form input validations delivered via websockets
132
132
  email:
133
133
  - hello@leastbad.com