compony 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e3590a5ce07d22e7d483af2c98c972e9c64403e43084560e193bb6382215844
4
- data.tar.gz: 054e3c2ef26650cdf404b0615f74dc12f0a610728e9b9b1446a90a4c91952365
3
+ metadata.gz: 328b6b6671f93fa0575bf4224a5da90fecde74a0c00430346d36ca45a675cf24
4
+ data.tar.gz: a92107d9f9cf7b270d57059ad10bdec614d269615fd2eabfe58caeb0e44300bc
5
5
  SHA512:
6
- metadata.gz: 90139644b0d2f3dd9adbff42e42bcdecae69d93676e5c4527795bd89a81103f5eabab4fd846fb3ad5e32b3463b0303b5e860f65d31939c0438f2e211bd28b4f6
7
- data.tar.gz: a9c0714b201b1df42f0996e1a965de71ed6c6738cf8a6e0e332883a1b97f9dcdb876d89a138965c63db957e6b99bf54bdba7cbfc6a977b68c94f0b98dba496f5
6
+ metadata.gz: 1ae81390416e9f14dcfb1a1d2723fbd3714e4f271afe9dc9e2a3ee2f27012a1ee82cb846fb8b80be14b6fac73451477b9b8e00a960b8f88777670a10e4dcec13
7
+ data.tar.gz: d318c0bdc852f4ff1fcf1aef638eac97356a03621f70bb4bac7957bece7050ba5e152a4114d165c79200d3e2eefe6d61af69ac4fec10371da354f908164ab929
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
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
+
1
11
  # 0.0.7
2
12
 
3
13
  - Fix `standalone_access_permitted_for?` check for buttons pointing to non-get verbs
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.7 ruby lib
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.7"
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-09-18"
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
17
  s.rubygems_version = "3.4.19".freeze
18
18
  s.summary = "Needs summary".freeze
@@ -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
- h.content_tag(:div, action_button.render(controller), class: action_class)
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
@@ -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
- el.nil? ? nil : controller.helpers.compony_link(link_to_component, el, **link_opts)
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}&nbsp;<span style=\"background-color: #{el}\">&nbsp;&nbsp;&nbsp;&nbsp;</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
@@ -2,7 +2,7 @@ module Compony
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 7
5
+ PATCH = 8
6
6
 
7
7
  EDGE = false
8
8
 
data/lib/compony.rb CHANGED
@@ -245,6 +245,7 @@ require 'compony/model_fields/anchormodel'
245
245
  require 'compony/model_fields/association'
246
246
  require 'compony/model_fields/attachment'
247
247
  require 'compony/model_fields/boolean'
248
+ require 'compony/model_fields/color'
248
249
  require 'compony/model_fields/currency'
249
250
  require 'compony/model_fields/date'
250
251
  require 'compony/model_fields/datetime'
@@ -6,3 +6,5 @@ Example:
6
6
 
7
7
  This will create:
8
8
  app/components/users/new.rb
9
+
10
+ For Foo::Form, arguments will produce form fields.
@@ -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
- schema_fields
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.7
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-09-18 00:00:00.000000000 Z
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