wobapphelpers 4.0.0 → 4.1.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: 12c301fa73d2bc6e7ed490e0c4705e97fe958cecadab3cd603bb00c6bc9f43e0
4
- data.tar.gz: b2c5d81eb33f8f8cca05c2a51e5c835394db40a31f04304ecb4db9a0ac8712c8
3
+ metadata.gz: c4ec580d7a01144e453ef30299dd500f825826b2738d8432df36a0ef73809f08
4
+ data.tar.gz: 88bc7d97b4c93e6fc70866d023a61f48797d3073db6a0a5db4384e8c312dbcbe
5
5
  SHA512:
6
- metadata.gz: 5761d19b7170a14b1e870b938773dedc4eae005ff3a4be9d59f90e85c1d5b15263319b9b8610ac6035ed43aeb85f034ba00de04f335f093a6e433c45ef8950eb
7
- data.tar.gz: d3799fb2cb12d6706491f8e1e323bdb762f4f891201d65fe3c3a587a175b922a95769a7d4b6cc4a13f61122126a9171dadaf10d418d1503c1c83f0d1fd2e97f0
6
+ metadata.gz: ca45dcc4d286cc05e50e1e46cb7cd59ea3f912bd4fe5205234a62ec382a76ca9bb157d908bbe290c4789d83a11df730e4ddebc51414e5a773d043797c3c8e963
7
+ data.tar.gz: 4e7f2539d5ad7d7b2b4fe7c0c233328bad1415f3f0d57f1d24ede7c44eea3655eb02a221562125e373fcb28a072ed9e8a4f3a23190dc4796c96dabdd5984bf54
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2019 Wolfgang Barth
3
+ Copyright (c) 2014-2020 Wolfgang Barth
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -15,7 +15,7 @@ Requirements
15
15
 
16
16
  | branch | rails | ruby | bootstrap | icons |
17
17
  |------------|-------|--------|-----------|-------------|
18
- | master | 5.2 | >= 2.3 | v4 | fontawesome |
18
+ | master | >=5.2 | >= 2.3 | v4 | fontawesome |
19
19
  | 3-0-stable | 5.1 | >= 2.3 | v4 | fontawesome |
20
20
  | 2-0-stable | 5.0 | >= 2.2 | v3 | glyphicons |
21
21
  | 1-0-stable | 4.2 | >= 2.0 | v3 | glyphicons |
@@ -25,9 +25,10 @@ Requirements
25
25
  Installation
26
26
  ------------
27
27
 
28
+ gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "master"
29
+ gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "3-0-stable"
28
30
  gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "2-0-stable"
29
31
  gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "1-0-stable"
30
- gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "master"
31
32
 
32
33
  Generators
33
34
  ----------
@@ -155,7 +156,7 @@ other variable names you have to use :add_breadcrumbs_for, i.e.
155
156
  Licence
156
157
  -------
157
158
 
158
- Wobapphelpers Copyright (C) 2014-2019 Wolfgang Barth
159
+ Wobapphelpers Copyright (C) 2014-2020 Wolfgang Barth
159
160
 
160
161
  MIT License, see [LICENSE](LICENSE)
161
162
 
@@ -2,11 +2,13 @@ module Wobapphelpers
2
2
  module Helpers
3
3
  autoload :IconHelper, 'wobapphelpers/helpers/icon_helper.rb'
4
4
  autoload :ActionViewHelper, 'wobapphelpers/helpers/action_view_helper.rb'
5
+ autoload :PolymorphicHelper, 'wobapphelpers/helpers/polymorphic_helper.rb'
5
6
 
6
7
  # one module to rule all
7
8
  module All
8
9
  include IconHelper
9
10
  include ActionViewHelper
11
+ # PolymorphicHelper must be explicit included
10
12
  end
11
13
  end
12
14
  end
@@ -0,0 +1,49 @@
1
+ module Wobapphelpers
2
+ module Helpers
3
+ module PolymorphicHelper
4
+ def polymorphic_selector(form, poly, types, group_method = :all, options = {})
5
+ msg = ""
6
+ # -- object available?
7
+ if form.object.send(poly).present?
8
+ msg += poly_type_display(form, poly)
9
+ msg += poly_id_select(form, poly, form.object.send("#{poly}_type"), :all, options)
10
+ elsif types.size == 1
11
+ msg += poly_type_display(form, poly, Array(types).first)
12
+ msg += poly_id_select(form, poly, Array(types).first, :all, options)
13
+ else
14
+ msg += poly_type_select(form, poly, types)
15
+ msg += poly_id_select(form, poly, types, group_method, options)
16
+ end
17
+ msg.html_safe
18
+ end
19
+
20
+ private
21
+
22
+ def poly_type_select(f, poly, types)
23
+ f.input "#{poly}_type".to_sym, collection: types,
24
+ label_method: lambda {|x| t('activerecord.models.' + x.underscore)}
25
+ end
26
+
27
+ def poly_type_display(f, poly, type = nil)
28
+ if type.present?
29
+ f.input("#{poly}_type".to_sym, collection: Array(type),
30
+ label_method: lambda {|x| t('activerecord.models.' + x.underscore)},
31
+ include_blank: false, disabled: true) +
32
+ f.hidden_field("#{poly}_type".to_sym, value: type, id: "#{poly}_type_hidden")
33
+ else
34
+ f.input("#{poly}_type".to_sym, collection: Array(f.object.send("#{poly}_type")),
35
+ label_method: lambda {|x| t('activerecord.models.' + x.underscore)},
36
+ disabled: true) +
37
+ f.hidden_field("#{poly}_type".to_sym, value: f.object.send("#{poly}_type"), id: "#{poly}_type_hidden")
38
+ end
39
+ end
40
+
41
+ def poly_id_select(f, poly, types, group_method, options = {})
42
+ collections = Array(types).map {|t| t.constantize}
43
+ f.input "#{poly}_id".to_sym, collection: collections,
44
+ as: :grouped_select, group_method: group_method,
45
+ input_html: options
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,4 +1,4 @@
1
1
  module Wobapphelpers
2
- VERSION = "4.0.0".freeze
3
- RELEASEDATE = "2019-11-28".freeze
2
+ VERSION = "4.1.0".freeze
3
+ RELEASEDATE = "2020-04-05".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wobapphelpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wolfgang Barth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-28 00:00:00.000000000 Z
11
+ date: 2020-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sassc-rails
@@ -314,6 +314,7 @@ files:
314
314
  - lib/wobapphelpers/helpers.rb
315
315
  - lib/wobapphelpers/helpers/action_view_helper.rb
316
316
  - lib/wobapphelpers/helpers/icon_helper.rb
317
+ - lib/wobapphelpers/helpers/polymorphic_helper.rb
317
318
  - lib/wobapphelpers/rails.rb
318
319
  - lib/wobapphelpers/responders.rb
319
320
  - lib/wobapphelpers/responders/locales/de.yml