compony 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/compony.gemspec +4 -4
- data/lib/compony/components/form.rb +6 -1
- data/lib/compony/model_fields/anchormodel.rb +7 -0
- data/lib/compony/model_fields/base.rb +6 -0
- data/lib/compony/model_fields/email.rb +2 -1
- data/lib/compony/model_fields/url.rb +13 -0
- data/lib/compony/model_mixin.rb +7 -0
- data/lib/compony/version.rb +1 -1
- data/lib/compony.rb +1 -0
- data/lib/generators/component/component_generator.rb +13 -2
- data/lib/generators/component/templates/component.rb.erb +1 -1
- data/lib/generators/component/templates/destroy.rb.erb +2 -0
- data/lib/generators/component/templates/edit.rb.erb +2 -0
- data/lib/generators/component/templates/form.rb.erb +8 -0
- data/lib/generators/component/templates/new.rb.erb +2 -0
- data/lib/generators/components/USAGE +8 -0
- data/lib/generators/components/components_generator.rb +12 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fa06e0cecacc05de1b6567e29594a44fcbfed063d0268e08de239432c51a7f2
|
4
|
+
data.tar.gz: 24ec1426a6259b2cc3b1ddbd0127d8878a46701a0d7b2003bf5668eddf1eb8a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66fc9fe7beb64285bc2f21a945d1596c24206072b0fd64172a3eea2130754363f11d980b9159b0ebc1702be72526eb2ce8e613d17ece625ac377eeb0698ee876
|
7
|
+
data.tar.gz: fce5758f4f812d6ba053cf085c807ffecbce5163ed676d529d00aaa36257478a3887f60d3d6bc1ec0294151144edb6d63dc415f82c8fa6b7727fc4f84be34a97
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 0.0.5
|
2
|
+
|
3
|
+
- Fix row bug for Email field type
|
4
|
+
- Auto-focus first non-hidden element in forms
|
5
|
+
- Add field type :url
|
6
|
+
- Automatically set the correct class when generating known components
|
7
|
+
- Add generator `components` that is able to mass-produce the most used components
|
8
|
+
- Make fields point to the correct `model_class` in case of STI
|
9
|
+
- Support hidden Anchormodel fields
|
10
|
+
|
1
11
|
# 0.0.4
|
2
12
|
|
3
13
|
- Unscope the namespace of resourceful components
|
data/compony.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# This file is auto-generated via: 'rake gemspec'.
|
3
3
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: compony 0.0.
|
5
|
+
# stub: compony 0.0.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "compony".freeze
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Sandro Kalbermatter".freeze, "contributors".freeze]
|
14
|
-
s.date = "2023-
|
15
|
-
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "app/controllers/compony_controller.rb".freeze, "compony.gemspec".freeze, "config/locales/de.yml".freeze, "config/locales/en.yml".freeze, "config/routes.rb".freeze, "doc/resourceful_lifecycle.graphml".freeze, "doc/resourceful_lifecycle.pdf".freeze, "lib/compony.rb".freeze, "lib/compony/component.rb".freeze, "lib/compony/component_mixins/default/labelling.rb".freeze, "lib/compony/component_mixins/default/standalone.rb".freeze, "lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/standalone_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/verb_dsl.rb".freeze, "lib/compony/component_mixins/resourceful.rb".freeze, "lib/compony/components/button.rb".freeze, "lib/compony/components/destroy.rb".freeze, "lib/compony/components/edit.rb".freeze, "lib/compony/components/form.rb".freeze, "lib/compony/components/new.rb".freeze, "lib/compony/components/with_form.rb".freeze, "lib/compony/controller_mixin.rb".freeze, "lib/compony/engine.rb".freeze, "lib/compony/method_accessible_hash.rb".freeze, "lib/compony/model_fields/anchormodel.rb".freeze, "lib/compony/model_fields/association.rb".freeze, "lib/compony/model_fields/attachment.rb".freeze, "lib/compony/model_fields/base.rb".freeze, "lib/compony/model_fields/boolean.rb".freeze, "lib/compony/model_fields/currency.rb".freeze, "lib/compony/model_fields/date.rb".freeze, "lib/compony/model_fields/datetime.rb".freeze, "lib/compony/model_fields/decimal.rb".freeze, "lib/compony/model_fields/email.rb".freeze, "lib/compony/model_fields/float.rb".freeze, "lib/compony/model_fields/integer.rb".freeze, "lib/compony/model_fields/phone.rb".freeze, "lib/compony/model_fields/rich_text.rb".freeze, "lib/compony/model_fields/string.rb".freeze, "lib/compony/model_fields/text.rb".freeze, "lib/compony/model_fields/time.rb".freeze, "lib/compony/model_mixin.rb".freeze, "lib/compony/request_context.rb".freeze, "lib/compony/version.rb".freeze, "lib/compony/view_helpers.rb".freeze, "lib/generators/component/USAGE".freeze, "lib/generators/component/component_generator.rb".freeze, "lib/generators/component/templates/component.rb.erb".freeze]
|
14
|
+
s.date = "2023-06-20"
|
15
|
+
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "app/controllers/compony_controller.rb".freeze, "compony.gemspec".freeze, "config/locales/de.yml".freeze, "config/locales/en.yml".freeze, "config/routes.rb".freeze, "doc/resourceful_lifecycle.graphml".freeze, "doc/resourceful_lifecycle.pdf".freeze, "lib/compony.rb".freeze, "lib/compony/component.rb".freeze, "lib/compony/component_mixins/default/labelling.rb".freeze, "lib/compony/component_mixins/default/standalone.rb".freeze, "lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/standalone_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/verb_dsl.rb".freeze, "lib/compony/component_mixins/resourceful.rb".freeze, "lib/compony/components/button.rb".freeze, "lib/compony/components/destroy.rb".freeze, "lib/compony/components/edit.rb".freeze, "lib/compony/components/form.rb".freeze, "lib/compony/components/new.rb".freeze, "lib/compony/components/with_form.rb".freeze, "lib/compony/controller_mixin.rb".freeze, "lib/compony/engine.rb".freeze, "lib/compony/method_accessible_hash.rb".freeze, "lib/compony/model_fields/anchormodel.rb".freeze, "lib/compony/model_fields/association.rb".freeze, "lib/compony/model_fields/attachment.rb".freeze, "lib/compony/model_fields/base.rb".freeze, "lib/compony/model_fields/boolean.rb".freeze, "lib/compony/model_fields/currency.rb".freeze, "lib/compony/model_fields/date.rb".freeze, "lib/compony/model_fields/datetime.rb".freeze, "lib/compony/model_fields/decimal.rb".freeze, "lib/compony/model_fields/email.rb".freeze, "lib/compony/model_fields/float.rb".freeze, "lib/compony/model_fields/integer.rb".freeze, "lib/compony/model_fields/phone.rb".freeze, "lib/compony/model_fields/rich_text.rb".freeze, "lib/compony/model_fields/string.rb".freeze, "lib/compony/model_fields/text.rb".freeze, "lib/compony/model_fields/time.rb".freeze, "lib/compony/model_fields/url.rb".freeze, "lib/compony/model_mixin.rb".freeze, "lib/compony/request_context.rb".freeze, "lib/compony/version.rb".freeze, "lib/compony/view_helpers.rb".freeze, "lib/generators/component/USAGE".freeze, "lib/generators/component/component_generator.rb".freeze, "lib/generators/component/templates/component.rb.erb".freeze, "lib/generators/component/templates/destroy.rb.erb".freeze, "lib/generators/component/templates/edit.rb.erb".freeze, "lib/generators/component/templates/form.rb.erb".freeze, "lib/generators/component/templates/new.rb.erb".freeze, "lib/generators/components/USAGE".freeze, "lib/generators/components/components_generator.rb".freeze]
|
16
16
|
s.required_ruby_version = Gem::Requirement.new(">= 3.0.0".freeze)
|
17
17
|
s.rubygems_version = "3.4.13".freeze
|
18
18
|
s.summary = "Needs summary".freeze
|
@@ -71,6 +71,7 @@ module Compony
|
|
71
71
|
# @todo Refactor? Could this be greatly simplified by having `form_field to |f|` ?
|
72
72
|
def with_simpleform(simpleform)
|
73
73
|
@simpleform = simpleform
|
74
|
+
@focus_given = false
|
74
75
|
yield
|
75
76
|
@simpleform = nil
|
76
77
|
end
|
@@ -85,8 +86,12 @@ module Compony
|
|
85
86
|
fail("Field #{name.to_sym.inspect} is not defined on #{@simpleform.object.inspect} but was requested in #{inspect}.") unless model_field
|
86
87
|
|
87
88
|
if hidden
|
88
|
-
return @simpleform
|
89
|
+
return model_field.simpleform_input_hidden(@simpleform, self, **input_opts)
|
89
90
|
else
|
91
|
+
unless @focus_given
|
92
|
+
input_opts[:autofocus] = true unless input_opts.key? :autofocus
|
93
|
+
@focus_given = true
|
94
|
+
end
|
90
95
|
return model_field.simpleform_input(@simpleform, self, **input_opts)
|
91
96
|
end
|
92
97
|
end
|
@@ -23,6 +23,13 @@ module Compony
|
|
23
23
|
}.merge(input_opts)
|
24
24
|
return form.input @name, **opts
|
25
25
|
end
|
26
|
+
|
27
|
+
def simpleform_input_hidden(form, _component, **input_opts)
|
28
|
+
selected_cst = form.object.send(@name)
|
29
|
+
input_opts[:input_html] ||= {}
|
30
|
+
input_opts[:input_html][:value] = selected_cst.is_a?(::Anchormodel) ? selected_cst.key : selected_cst
|
31
|
+
return form.input @name, as: :hidden, **input_opts
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
@@ -46,6 +46,12 @@ module Compony
|
|
46
46
|
return form.input @name, **input_opts
|
47
47
|
end
|
48
48
|
|
49
|
+
# Used in form helper
|
50
|
+
# Given a simpleform instance, returns a suitable hidden input for thetype
|
51
|
+
def simpleform_input_hidden(form, _component, **input_opts)
|
52
|
+
return form.input @name, as: :hidden, **input_opts
|
53
|
+
end
|
54
|
+
|
49
55
|
protected
|
50
56
|
|
51
57
|
# If given a scalar, calls the block on the scalar. If given a list, calls the block on every member and joins the result with ",".
|
@@ -4,7 +4,8 @@ module Compony
|
|
4
4
|
def value_for(data, controller: nil, **_)
|
5
5
|
return transform_and_join(data.send(@name), controller:) do |el|
|
6
6
|
fail('Must pass controller to generate the link to the email.') unless controller
|
7
|
-
return
|
7
|
+
return nil unless el
|
8
|
+
return controller.helpers.mail_to(el)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Compony
|
2
|
+
module ModelFields
|
3
|
+
class Url < Base
|
4
|
+
def value_for(data, controller: nil, **_)
|
5
|
+
return transform_and_join(data.send(@name), controller:) do |el|
|
6
|
+
fail('Must pass controller to generate the link to the link.') unless controller
|
7
|
+
return nil unless el
|
8
|
+
return controller.helpers.link_to(el, el, target: '_blank', rel: 'noopener')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/compony/model_mixin.rb
CHANGED
@@ -11,6 +11,13 @@ module Compony
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class_methods do
|
14
|
+
# This hook updates all fields from a subclass, making sure that fields point to correct model classes even in STI
|
15
|
+
# e.g. in Parent: field :foo, ... omitted in child -> child.fields[:foo] should point to Child and not Parent.
|
16
|
+
def inherited(subclass)
|
17
|
+
super
|
18
|
+
subclass.fields = subclass.fields.transform_values { |f| f.class.new(f.name, subclass, **f.extra_attrs) }
|
19
|
+
end
|
20
|
+
|
14
21
|
# DSL method, defines a new field which will be translated and can be added to field groups
|
15
22
|
# For virtual attributes, you must pass a type explicitely, otherwise it's auto-infered.
|
16
23
|
def field(name, type, **extra_attrs)
|
data/lib/compony/version.rb
CHANGED
data/lib/compony.rb
CHANGED
@@ -255,6 +255,7 @@ require 'compony/model_fields/rich_text'
|
|
255
255
|
require 'compony/model_fields/string'
|
256
256
|
require 'compony/model_fields/text'
|
257
257
|
require 'compony/model_fields/time'
|
258
|
+
require 'compony/model_fields/url'
|
258
259
|
require 'compony/component_mixins/default/standalone'
|
259
260
|
require 'compony/component_mixins/default/standalone/standalone_dsl'
|
260
261
|
require 'compony/component_mixins/default/standalone/verb_dsl'
|
@@ -3,12 +3,23 @@ class ComponentGenerator < Rails::Generators::NamedBase
|
|
3
3
|
|
4
4
|
def add_component
|
5
5
|
segments = name.underscore.split('/')
|
6
|
-
fail(
|
6
|
+
fail("NAME must be of the form Family::ComponentName or family/component_name but got #{name.inspect}") if segments.size != 2
|
7
7
|
@family, @comp = segments
|
8
8
|
@family = @family.pluralize # Force plural
|
9
9
|
@family_cst = @family.camelize.pluralize # Force plural
|
10
10
|
@comp_cst = @comp.camelize # Tolerate singular and plural
|
11
11
|
|
12
|
-
|
12
|
+
case @comp_cst
|
13
|
+
when 'Destroy'
|
14
|
+
template 'destroy.rb.erb', "app/components/#{@family}/#{@comp}.rb"
|
15
|
+
when 'Edit'
|
16
|
+
template 'edit.rb.erb', "app/components/#{@family}/#{@comp}.rb"
|
17
|
+
when 'Form'
|
18
|
+
template 'form.rb.erb', "app/components/#{@family}/#{@comp}.rb"
|
19
|
+
when 'New'
|
20
|
+
template 'new.rb.erb', "app/components/#{@family}/#{@comp}.rb"
|
21
|
+
else
|
22
|
+
template 'component.rb.erb', "app/components/#{@family}/#{@comp}.rb"
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ComponentsGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
3
|
+
|
4
|
+
def add_component
|
5
|
+
@family = name.underscore.pluralize # Force plural
|
6
|
+
@family_cst = @family.camelize.pluralize # Force plural
|
7
|
+
|
8
|
+
%w[Destroy Edit Form New].each do |comp_cst|
|
9
|
+
generate "component #{name}::#{comp_cst}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Kalbermatter
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/compony/model_fields/string.rb
|
208
208
|
- lib/compony/model_fields/text.rb
|
209
209
|
- lib/compony/model_fields/time.rb
|
210
|
+
- lib/compony/model_fields/url.rb
|
210
211
|
- lib/compony/model_mixin.rb
|
211
212
|
- lib/compony/request_context.rb
|
212
213
|
- lib/compony/version.rb
|
@@ -214,6 +215,12 @@ files:
|
|
214
215
|
- lib/generators/component/USAGE
|
215
216
|
- lib/generators/component/component_generator.rb
|
216
217
|
- lib/generators/component/templates/component.rb.erb
|
218
|
+
- lib/generators/component/templates/destroy.rb.erb
|
219
|
+
- lib/generators/component/templates/edit.rb.erb
|
220
|
+
- lib/generators/component/templates/form.rb.erb
|
221
|
+
- lib/generators/component/templates/new.rb.erb
|
222
|
+
- lib/generators/components/USAGE
|
223
|
+
- lib/generators/components/components_generator.rb
|
217
224
|
homepage:
|
218
225
|
licenses: []
|
219
226
|
metadata: {}
|