compony 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/compony.gemspec +5 -5
- data/lib/compony/component.rb +4 -2
- data/lib/compony/component_mixins/default/standalone.rb +2 -1
- data/lib/compony/model_fields/anchormodel.rb +2 -1
- data/lib/compony/model_fields/association.rb +7 -2
- data/lib/compony/model_fields/color.rb +16 -0
- data/lib/compony/model_fields/date.rb +2 -2
- data/lib/compony/model_fields/datetime.rb +2 -2
- data/lib/compony/version.rb +1 -1
- data/lib/compony.rb +4 -1
- data/lib/generators/component/USAGE +2 -0
- data/lib/generators/component/component_generator.rb +1 -0
- data/lib/generators/component/templates/form.rb.erb +5 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 328b6b6671f93fa0575bf4224a5da90fecde74a0c00430346d36ca45a675cf24
|
4
|
+
data.tar.gz: a92107d9f9cf7b270d57059ad10bdec614d269615fd2eabfe58caeb0e44300bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ae81390416e9f14dcfb1a1d2723fbd3714e4f271afe9dc9e2a3ee2f27012a1ee82cb846fb8b80be14b6fac73451477b9b8e00a960b8f88777670a10e4dcec13
|
7
|
+
data.tar.gz: d318c0bdc852f4ff1fcf1aef638eac97356a03621f70bb4bac7957bece7050ba5e152a4114d165c79200d3e2eefe6d61af69ac4fec10371da354f908164ab929
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 0.0.8
|
2
|
+
|
3
|
+
- Support selecting anchormodel inputs via radio buttons
|
4
|
+
- Fix `value_for` for associations to elements that have no show component
|
5
|
+
- Fix spacing problem with invisible action buttons
|
6
|
+
- Pass the controller as argument to action buttons
|
7
|
+
- Support option `:label` in `value_for` of date and datetime, support superfluous options in association
|
8
|
+
- Support argument list in form generator
|
9
|
+
- Create new model field type :color
|
10
|
+
|
11
|
+
# 0.0.7
|
12
|
+
|
13
|
+
- Fix `standalone_access_permitted_for?` check for buttons pointing to non-get verbs
|
14
|
+
|
1
15
|
# 0.0.6
|
2
16
|
|
3
17
|
- Fix a bug that breaks hidden fields of type reference
|
data/compony.gemspec
CHANGED
@@ -2,19 +2,19 @@
|
|
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.8 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.8"
|
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_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]
|
14
|
+
s.date = "2023-10-03"
|
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/color.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
|
-
s.rubygems_version = "3.4.
|
17
|
+
s.rubygems_version = "3.4.19".freeze
|
18
18
|
s.summary = "Needs summary".freeze
|
19
19
|
|
20
20
|
s.specification_version = 4
|
data/lib/compony/component.rb
CHANGED
@@ -206,9 +206,11 @@ module Compony
|
|
206
206
|
button_htmls = @actions.map do |action|
|
207
207
|
next if @skipped_actions.include?(action.name)
|
208
208
|
Compony.with_button_defaults(feasibility_action: action.name.to_sym) do
|
209
|
-
action_button = action.block.call
|
209
|
+
action_button = action.block.call(controller)
|
210
210
|
next unless action_button
|
211
|
-
|
211
|
+
button_html = action_button.render(controller)
|
212
|
+
next if button_html.blank?
|
213
|
+
h.content_tag(:div, button_html, class: action_class)
|
212
214
|
end
|
213
215
|
end
|
214
216
|
next h.safe_join button_htmls
|
@@ -75,7 +75,8 @@ module Compony
|
|
75
75
|
# - when called standalone (via request to the component), the load data step must be completed
|
76
76
|
# - when called to check for permission only, e.g. to display a button to it, initialize the component by passing the :data keyword to `new`
|
77
77
|
# By default, this checks the authorization to access the main standalone entrypoint (with name `nil`) and HTTP verb GET.
|
78
|
-
def standalone_access_permitted_for?(controller, standalone_name: nil, verb:
|
78
|
+
def standalone_access_permitted_for?(controller, standalone_name: nil, verb: nil)
|
79
|
+
verb ||= :get
|
79
80
|
standalone_name = standalone_name&.to_sym
|
80
81
|
verb = verb.to_sym
|
81
82
|
standalone_config = standalone_configs[standalone_name] || fail("#{inspect} does not provide the standalone config #{standalone_config.inspect}.")
|
@@ -25,7 +25,8 @@ module Compony
|
|
25
25
|
collection: self.class.collect(anchormodel_class.all),
|
26
26
|
label_method: :first,
|
27
27
|
value_method: :second,
|
28
|
-
selected: selected_key,
|
28
|
+
selected: selected_key, # if used in select
|
29
|
+
checked: selected_key, # if used in radio buttons
|
29
30
|
include_blank: anchormodel_attribute.optional
|
30
31
|
}.merge(input_opts)
|
31
32
|
return form.input name || @name, **opts
|
@@ -6,11 +6,16 @@ module Compony
|
|
6
6
|
resolve_association!
|
7
7
|
end
|
8
8
|
|
9
|
-
def value_for(data, link_to_component: nil, link_opts: {}, controller: nil)
|
9
|
+
def value_for(data, link_to_component: nil, link_opts: {}, controller: nil, **_)
|
10
10
|
if link_to_component
|
11
11
|
fail('Must pass controller if link_to_component is given.') unless controller
|
12
12
|
return transform_and_join(data.send(@name), controller:) do |el|
|
13
|
-
|
13
|
+
next nil if el.nil?
|
14
|
+
if Compony.comp_class_for(link_to_component, el)
|
15
|
+
next controller.helpers.compony_link(link_to_component, el, **link_opts)
|
16
|
+
else
|
17
|
+
next el.label
|
18
|
+
end
|
14
19
|
end
|
15
20
|
else
|
16
21
|
return transform_and_join(data.send(@name), controller:) { |el| el&.label }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Compony
|
2
|
+
module ModelFields
|
3
|
+
class Color < Base
|
4
|
+
def value_for(data, controller: nil, **_)
|
5
|
+
return transform_and_join(data.send(@name), controller:) do |el|
|
6
|
+
next nil unless el
|
7
|
+
next controller.helpers.raw "#{el} <span style=\"background-color: #{el}\"> </span>"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def simpleform_input(form, _component, name: nil, **input_opts)
|
12
|
+
return form.input name || @name, as: :color, **input_opts
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Compony
|
2
2
|
module ModelFields
|
3
3
|
class Date < Base
|
4
|
-
def value_for(data, controller: nil, **_)
|
5
|
-
return transform_and_join(data.send(@name), controller:) { |el| el.nil? ? nil : I18n.l(el) }
|
4
|
+
def value_for(data, controller: nil, format: nil, **_)
|
5
|
+
return transform_and_join(data.send(@name), controller:) { |el| el.nil? ? nil : I18n.l(el, format:) }
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Compony
|
2
2
|
module ModelFields
|
3
3
|
class Datetime < Base
|
4
|
-
def value_for(data, controller: nil, **_)
|
5
|
-
return transform_and_join(data.send(@name), controller:) { |el| el.nil? ? nil : I18n.l(el) }
|
4
|
+
def value_for(data, controller: nil, format: nil, **_)
|
5
|
+
return transform_and_join(data.send(@name), controller:) { |el| el.nil? ? nil : I18n.l(el, format:) }
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/lib/compony/version.rb
CHANGED
data/lib/compony.rb
CHANGED
@@ -145,6 +145,7 @@ module Compony
|
|
145
145
|
params: nil,
|
146
146
|
feasibility_action: nil,
|
147
147
|
feasibility_target: nil,
|
148
|
+
method: nil,
|
148
149
|
**override_kwargs)
|
149
150
|
label_opts ||= button_defaults[:label_opts] || {}
|
150
151
|
params ||= button_defaults[:params] || {}
|
@@ -157,7 +158,8 @@ module Compony
|
|
157
158
|
icon: target_comp_instance.icon,
|
158
159
|
color: target_comp_instance.color,
|
159
160
|
path: Compony.path(target_comp_instance.comp_name, target_comp_instance.family_name, model, **params),
|
160
|
-
|
161
|
+
method:,
|
162
|
+
visible: ->(controller) { target_comp_instance.standalone_access_permitted_for?(controller, verb: method) }
|
161
163
|
}
|
162
164
|
if feasibility_target
|
163
165
|
options.merge!({
|
@@ -243,6 +245,7 @@ require 'compony/model_fields/anchormodel'
|
|
243
245
|
require 'compony/model_fields/association'
|
244
246
|
require 'compony/model_fields/attachment'
|
245
247
|
require 'compony/model_fields/boolean'
|
248
|
+
require 'compony/model_fields/color'
|
246
249
|
require 'compony/model_fields/currency'
|
247
250
|
require 'compony/model_fields/date'
|
248
251
|
require 'compony/model_fields/datetime'
|
@@ -8,6 +8,7 @@ class ComponentGenerator < Rails::Generators::NamedBase
|
|
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
|
+
@args = args
|
11
12
|
|
12
13
|
case @comp_cst
|
13
14
|
when 'Destroy'
|
@@ -1,8 +1,10 @@
|
|
1
1
|
class Components::<%= @family_cst %>::<%= @comp_cst %> < Compony::Components::Form
|
2
2
|
setup do
|
3
|
-
form_fields do
|
3
|
+
form_fields do<% @args.each do |arg| %>
|
4
|
+
concat field :<%= arg.strip %><% end %>
|
4
5
|
end
|
5
|
-
|
6
|
-
|
6
|
+
<% if @args.any? %><% @args.each do |arg| %>
|
7
|
+
schema_field :<%= arg.strip %><% end %><% else %>
|
8
|
+
schema_fields<% end %>
|
7
9
|
end
|
8
10
|
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.8
|
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-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- lib/compony/model_fields/attachment.rb
|
196
196
|
- lib/compony/model_fields/base.rb
|
197
197
|
- lib/compony/model_fields/boolean.rb
|
198
|
+
- lib/compony/model_fields/color.rb
|
198
199
|
- lib/compony/model_fields/currency.rb
|
199
200
|
- lib/compony/model_fields/date.rb
|
200
201
|
- lib/compony/model_fields/datetime.rb
|