compony 0.0.7 → 0.0.9

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: 5e3590a5ce07d22e7d483af2c98c972e9c64403e43084560e193bb6382215844
4
- data.tar.gz: 054e3c2ef26650cdf404b0615f74dc12f0a610728e9b9b1446a90a4c91952365
3
+ metadata.gz: 8157d970b7bb216a92e5ff27931775e1744063efcb91bd8c2c094d998bc0d74d
4
+ data.tar.gz: 1a10cfd007f6c94f2bd71076bd90688bd6761a597962414f56f31570cb4b6c31
5
5
  SHA512:
6
- metadata.gz: 90139644b0d2f3dd9adbff42e42bcdecae69d93676e5c4527795bd89a81103f5eabab4fd846fb3ad5e32b3463b0303b5e860f65d31939c0438f2e211bd28b4f6
7
- data.tar.gz: a9c0714b201b1df42f0996e1a965de71ed6c6738cf8a6e0e332883a1b97f9dcdb876d89a138965c63db957e6b99bf54bdba7cbfc6a977b68c94f0b98dba496f5
6
+ metadata.gz: 37fdaa0c7e0c6e905fbf5239d79dc9df15bb27e3cf805953fc9daf75e421f04dc14b087165e2049c5e4ff87a13464d197a837cea24517467d591ff115c7f2cd3
7
+ data.tar.gz: 3f59823928a888c4bb5f501f4e1440ff4e3a1f83f627d23117af9c5b5e7afba65db48168a70685010c9c251f4b7331a232843a6209634ad004c3a15a0ee6653a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ # 0.0.9
2
+
3
+ - Support forms with references to tables with uuid type primary key
4
+ - Support for `owned_by` in model:
5
+ - Smart redirect
6
+ - Auto-generate a back / cancel button
7
+ - Add `clear_standalone!` to components
8
+ - Allow passing an array to `prevent` to prevent multiple actions at once
9
+ - Add features `Compony.content_before_root_comp` and `Compony.content_after_root_comp`
10
+ - Add new field kind percentage
11
+
12
+ # 0.0.8
13
+
14
+ - Support selecting anchormodel inputs via radio buttons
15
+ - Fix `value_for` for associations to elements that have no show component
16
+ - Fix spacing problem with invisible action buttons
17
+ - Pass the controller as argument to action buttons
18
+ - Support option `:label` in `value_for` of date and datetime, support superfluous options in association
19
+ - Support argument list in form generator
20
+ - Create new model field type :color
21
+
1
22
  # 0.0.7
2
23
 
3
24
  - Fix `standalone_access_permitted_for?` check for buttons pointing to non-get verbs
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compony (0.0.1)
4
+ compony (0.0.9.edge)
5
5
  anchormodel (~> 0.1.2)
6
6
  cancancan (~> 3.4.0)
7
7
  dslblend (>= 0.0.3)
@@ -203,4 +203,4 @@ DEPENDENCIES
203
203
  yard (>= 0.9.28)
204
204
 
205
205
  BUNDLED WITH
206
- 2.4.13
206
+ 2.4.19
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.9 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.9"
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-11-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/percentage.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
@@ -1,5 +1,6 @@
1
1
  de:
2
2
  compony:
3
+ cancel: 'Abbrechen'
3
4
  filtered: '[Filtered]' # Not translated as this appears in log
4
5
  boolean:
5
6
  true: 'Ja'
@@ -1,5 +1,6 @@
1
1
  en:
2
2
  compony:
3
+ cancel: 'Cancel'
3
4
  filtered: '[Filtered]'
4
5
  boolean:
5
6
  yes: 'Yes'
@@ -146,8 +146,9 @@ module Compony
146
146
  end
147
147
 
148
148
  # Renders the component using the controller passsed to it and returns it as a string.
149
+ # @param standalone: pass true iff `render` is called from `render_standalone`
149
150
  # Do not overwrite.
150
- def render(controller, **locals)
151
+ def render(controller, standalone: false, **locals)
151
152
  # Call before_render hook if any and backfire instance variables back to the component
152
153
  RequestContext.new(self, controller, locals:).request_context.evaluate_with_backfire(&@before_render_block) if @before_render_block
153
154
  # Render, unless before_render has already issued a body (e.g. through redirecting).
@@ -155,12 +156,18 @@ module Compony
155
156
  fail "#{self.class.inspect} must define `content` or set a response body in `before_render`" if @content_blocks.none?
156
157
  return controller.render_to_string(
157
158
  type: :dyny,
158
- locals: { content_blocks: @content_blocks, component: self, render_locals: locals },
159
+ locals: { content_blocks: @content_blocks, standalone:, component: self, render_locals: locals },
159
160
  inline: <<~RUBY
161
+ if Compony.content_before_root_comp_block && standalone
162
+ Compony::RequestContext.new(component, controller, helpers: self, locals: render_locals).evaluate(&Compony.content_before_root_comp_block)
163
+ end
160
164
  content_blocks.each do |block|
161
165
  # Instanciate and evaluate a fresh RequestContext in order to use the buffer allocated by the ActionView (needed for `concat` calls)
162
166
  Compony::RequestContext.new(component, controller, helpers: self, locals: render_locals).evaluate(&block)
163
167
  end
168
+ if Compony.content_after_root_comp_block && standalone
169
+ Compony::RequestContext.new(component, controller, helpers: self, locals: render_locals).evaluate(&Compony.content_after_root_comp_block)
170
+ end
164
171
  RUBY
165
172
  )
166
173
  else
@@ -206,9 +213,11 @@ module Compony
206
213
  button_htmls = @actions.map do |action|
207
214
  next if @skipped_actions.include?(action.name)
208
215
  Compony.with_button_defaults(feasibility_action: action.name.to_sym) do
209
- action_button = action.block.call
216
+ action_button = action.block.call(controller)
210
217
  next unless action_button
211
- h.content_tag(:div, action_button.render(controller), class: action_class)
218
+ button_html = action_button.render(controller)
219
+ next if button_html.blank?
220
+ h.content_tag(:div, button_html, class: action_class)
212
221
  end
213
222
  end
214
223
  next h.safe_join button_htmls
@@ -88,7 +88,7 @@ module Compony
88
88
  # Do not overwrite
89
89
  def render_standalone(controller, status: nil, standalone_name: nil)
90
90
  # Start the render process. This produces a nil value if before_render has already produced a response, e.g. a redirect.
91
- rendered_html = render(controller)
91
+ rendered_html = render(controller, standalone: true)
92
92
  if rendered_html.present? # If nil, a response body was already produced in the controller and we take no action here (would have DoubleRenderError)
93
93
  opts = { html: rendered_html, layout: @standalone_configs[standalone_name].layout }
94
94
  opts[:status] = status if status.present?
@@ -111,6 +111,11 @@ module Compony
111
111
  @standalone_configs[name].deep_merge! StandaloneDsl.new(self, name, *args, **nargs).to_conf(&block)
112
112
  end
113
113
 
114
+ # Undoes previous standalone calls
115
+ def clear_standalone!
116
+ @standalone_configs = {}
117
+ end
118
+
114
119
  private
115
120
 
116
121
  def init_standalone
@@ -36,6 +36,11 @@ module Compony
36
36
  end
37
37
  end
38
38
 
39
+ action :back_to_owner do
40
+ next if data_class.owner_model_attr.blank?
41
+ Compony.button(:show, @data.send(data_class.owner_model_attr), icon: :xmark, color: :secondary, label: I18n.t('compony.cancel'))
42
+ end
43
+
39
44
  store_data do
40
45
  # Validate params against the form's schema
41
46
  local_data = @data # Capture data for usage in the Schemacop call
@@ -58,7 +63,11 @@ module Compony
58
63
  end
59
64
 
60
65
  on_destroyed_redirect_path do
61
- Compony.path(:index, family_cst)
66
+ if data_class.owner_model_attr.present?
67
+ Compony.path(:show, @data.send(data_class.owner_model_attr))
68
+ else
69
+ Compony.path(:index, family_cst)
70
+ end
62
71
  end
63
72
  end
64
73
 
@@ -30,6 +30,11 @@ module Compony
30
30
  label(:short) { |_| I18n.t('compony.components.edit.label.short') }
31
31
  icon { :pencil }
32
32
 
33
+ action :back_to_owner do
34
+ next if data_class.owner_model_attr.blank?
35
+ Compony.button(:show, @data.send(data_class.owner_model_attr), icon: :xmark, color: :secondary, label: I18n.t('compony.cancel'))
36
+ end
37
+
33
38
  content do
34
39
  concat form_comp.render(controller, data: @data)
35
40
  end
@@ -65,6 +70,8 @@ module Compony
65
70
  on_updated_redirect_path do
66
71
  if Compony.comp_class_for(:show, @data)
67
72
  Compony.path(:show, @data)
73
+ elsif data_class.owner_model_attr.present?
74
+ Compony.path(:show, @data.send(data_class.owner_model_attr))
68
75
  else
69
76
  Compony.path(:index, @data)
70
77
  end
@@ -64,6 +64,8 @@ module Compony
64
64
  on_created_redirect_path do
65
65
  if Compony.comp_class_for(:show, @data)
66
66
  Compony.path(:show, @data)
67
+ elsif data_class.owner_model_attr.present?
68
+ Compony.path(:show, @data.send(data_class.owner_model_attr))
67
69
  else
68
70
  Compony.path(:index, @data)
69
71
  end
@@ -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 }
@@ -19,15 +24,28 @@ module Compony
19
24
 
20
25
  def schema_line
21
26
  local_schema_key = @schema_key # Capture schema_key as it will not be available within the lambda
27
+ target_primary_key_type = @target_class.primary_key_type_key
22
28
  if multi?
23
29
  return proc do
24
30
  ary? local_schema_key do
25
- list :integer, cast_str: true
31
+ if target_primary_key_type == :integer
32
+ list :integer, cast_str: true
33
+ elsif target_primary_key_type == :string
34
+ list :string
35
+ else
36
+ fail("Unsupported target primary_key_type_key #{target_primary_key_type}")
37
+ end
26
38
  end
27
39
  end
28
40
  else
29
41
  return proc do
30
- int? local_schema_key, cast_str: true
42
+ if target_primary_key_type == :integer
43
+ int? local_schema_key, cast_str: true
44
+ elsif target_primary_key_type == :string
45
+ str? local_schema_key
46
+ else
47
+ fail("Unsupported target primary_key_type_key #{target_primary_key_type}")
48
+ end
31
49
  end
32
50
  end
33
51
  end
@@ -48,6 +66,7 @@ module Compony
48
66
  @association = true
49
67
  association_info = @model_class.reflect_on_association(@name) || fail("Association #{@name.inspect} does not exist for #{@model_class.inspect}.")
50
68
  @multi = association_info.macro == :has_many
69
+ @target_class = association_info.klass
51
70
  id_name = "#{@name.to_s.singularize}_id"
52
71
  @schema_key = @multi ? id_name.pluralize.to_sym : id_name.to_sym
53
72
  rescue ActiveRecord::NoDatabaseError
@@ -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
@@ -0,0 +1,9 @@
1
+ module Compony
2
+ module ModelFields
3
+ class Percentage < Base
4
+ def value_for(data, controller: nil, **_)
5
+ return transform_and_join(data.send(@name), controller:) { |el| controller.helpers.sanitize "#{(el * 100.0).round(2)}%" }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -6,6 +6,7 @@ module Compony
6
6
  class_attribute :fields, default: {}
7
7
  class_attribute :feasibility_preventions, default: {}
8
8
  class_attribute :primary_key_type_key, default: :integer
9
+ class_attribute :owner_model_attr
9
10
 
10
11
  class_attribute :autodetect_feasibilities_completed, default: false
11
12
  end
@@ -34,12 +35,23 @@ module Compony
34
35
  self.primary_key_type_key = new_type.to_sym
35
36
  end
36
37
 
38
+ # DSL method, sets the containing model.
39
+ # Use this when a model only makes sense within the context of another model and typically has no own index page.
40
+ # For instance, a model LineItem that belongs_to :invoice would typically be owned_by :invoice.
41
+ # Compony will automatically adjust Redirects and top actions.
42
+ def owned_by(attribute_name)
43
+ self.owner_model_attr = attribute_name.to_sym
44
+ end
45
+
37
46
  # DSL method, part of the Feasibility feature
38
47
  # Block must return `false` if the action should be prevented.
39
- def prevent(action_name, message, &block)
40
- self.feasibility_preventions = feasibility_preventions.dup # Prevent cross-class contamination
41
- feasibility_preventions[action_name.to_sym] ||= []
42
- feasibility_preventions[action_name.to_sym] << MethodAccessibleHash.new(action_name:, message:, block:)
48
+ def prevent(action_names, message, &block)
49
+ action_names = [action_names] unless action_names.is_a? Enumerable
50
+ action_names.each do |action_name|
51
+ self.feasibility_preventions = feasibility_preventions.dup # Prevent cross-class contamination
52
+ feasibility_preventions[action_name.to_sym] ||= []
53
+ feasibility_preventions[action_name.to_sym] << MethodAccessibleHash.new(action_name:, message:, block:)
54
+ end
43
55
  end
44
56
 
45
57
  # DSL method, part of the Feasibility feature
@@ -2,7 +2,7 @@ module Compony
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 7
5
+ PATCH = 9
6
6
 
7
7
  EDGE = false
8
8
 
data/lib/compony.rb CHANGED
@@ -40,6 +40,20 @@ module Compony
40
40
  @authentication_before_action = authentication_before_action.to_sym
41
41
  end
42
42
 
43
+ # Setter for a content block that runs before the root component gets rendered (standalone only). Usage is the same as `content`.
44
+ # The block runs between `before_render` and `render`, i.e. before the first `content` block.
45
+ def self.content_before_root_comp(&block)
46
+ fail('`Compony.content_before` requires a block.') unless block_given?
47
+ @content_before_root_comp_block = block
48
+ end
49
+
50
+ # Setter for a content block that runs after the root component gets rendered (standalone only). Usage is the same as `content`.
51
+ # The block runs after `render`, i.e. after the last `content` block.
52
+ def self.content_after_root_comp(&block)
53
+ fail('`Compony.content_after` requires a block.') unless block_given?
54
+ @content_after_root_comp_block = block
55
+ end
56
+
43
57
  ##########=====-------
44
58
  # Configuration readers
45
59
  ##########=====-------
@@ -64,6 +78,18 @@ module Compony
64
78
  @authentication_before_action
65
79
  end
66
80
 
81
+ # Getter for content_before_root_comp_block
82
+ # @see Compony#content_before_root_comp
83
+ def self.content_before_root_comp_block
84
+ @content_before_root_comp_block
85
+ end
86
+
87
+ # Getter for content_after_root_comp_block
88
+ # @see Compony#content_after_root_comp
89
+ def self.content_after_root_comp_block
90
+ @content_after_root_comp_block
91
+ end
92
+
67
93
  ##########=====-------
68
94
  # Application-wide available pure helpers
69
95
  ##########=====-------
@@ -245,6 +271,7 @@ require 'compony/model_fields/anchormodel'
245
271
  require 'compony/model_fields/association'
246
272
  require 'compony/model_fields/attachment'
247
273
  require 'compony/model_fields/boolean'
274
+ require 'compony/model_fields/color'
248
275
  require 'compony/model_fields/currency'
249
276
  require 'compony/model_fields/date'
250
277
  require 'compony/model_fields/datetime'
@@ -252,6 +279,7 @@ require 'compony/model_fields/decimal'
252
279
  require 'compony/model_fields/email'
253
280
  require 'compony/model_fields/float'
254
281
  require 'compony/model_fields/integer'
282
+ require 'compony/model_fields/percentage'
255
283
  require 'compony/model_fields/phone'
256
284
  require 'compony/model_fields/rich_text'
257
285
  require 'compony/model_fields/string'
@@ -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.9
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-11-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
@@ -202,6 +203,7 @@ files:
202
203
  - lib/compony/model_fields/email.rb
203
204
  - lib/compony/model_fields/float.rb
204
205
  - lib/compony/model_fields/integer.rb
206
+ - lib/compony/model_fields/percentage.rb
205
207
  - lib/compony/model_fields/phone.rb
206
208
  - lib/compony/model_fields/rich_text.rb
207
209
  - lib/compony/model_fields/string.rb