compony 0.11.14 → 0.12.0

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.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/Gemfile.lock +1 -1
  4. data/VERSION +1 -1
  5. data/compony.gemspec +3 -3
  6. data/config/locales/de.yml +1 -1
  7. data/config/locales/en.yml +1 -1
  8. data/config/locales/es.yml +1 -1
  9. data/config/locales/fr.yml +1 -1
  10. data/doc/ComponentGenerator.html +1 -1
  11. data/doc/Components.html +1 -1
  12. data/doc/ComponentsGenerator.html +1 -1
  13. data/doc/Compony/Component.html +1 -1
  14. data/doc/Compony/ComponentMixins/Default/Labelling.html +1 -1
  15. data/doc/Compony/ComponentMixins/Default/Standalone/ResourcefulVerbDsl.html +1 -1
  16. data/doc/Compony/ComponentMixins/Default/Standalone/StandaloneDsl.html +1 -1
  17. data/doc/Compony/ComponentMixins/Default/Standalone/VerbDsl.html +1 -1
  18. data/doc/Compony/ComponentMixins/Default/Standalone.html +1 -1
  19. data/doc/Compony/ComponentMixins/Default.html +1 -1
  20. data/doc/Compony/ComponentMixins/Resourceful.html +1 -1
  21. data/doc/Compony/ComponentMixins.html +1 -1
  22. data/doc/Compony/Components/Buttons/CssButton.html +12 -1
  23. data/doc/Compony/Components/Buttons/Link.html +239 -16
  24. data/doc/Compony/Components/Buttons.html +1 -1
  25. data/doc/Compony/Components/Destroy.html +1 -1
  26. data/doc/Compony/Components/Edit.html +1 -1
  27. data/doc/Compony/Components/Form.html +83 -83
  28. data/doc/Compony/Components/Index.html +1 -1
  29. data/doc/Compony/Components/List.html +1 -1
  30. data/doc/Compony/Components/New.html +1 -1
  31. data/doc/Compony/Components/Show.html +1 -1
  32. data/doc/Compony/Components/WithForm.html +1 -1
  33. data/doc/Compony/Components.html +1 -1
  34. data/doc/Compony/ControllerMixin.html +1 -1
  35. data/doc/Compony/Engine.html +1 -1
  36. data/doc/Compony/Intent.html +1 -1
  37. data/doc/Compony/ManageIntentsDsl.html +1 -1
  38. data/doc/Compony/MethodAccessibleHash.html +1 -1
  39. data/doc/Compony/ModelFields/Anchormodel.html +1 -1
  40. data/doc/Compony/ModelFields/Association.html +1 -1
  41. data/doc/Compony/ModelFields/Attachment.html +13 -11
  42. data/doc/Compony/ModelFields/Base.html +1 -1
  43. data/doc/Compony/ModelFields/Boolean.html +1 -1
  44. data/doc/Compony/ModelFields/Color.html +1 -1
  45. data/doc/Compony/ModelFields/Currency.html +1 -1
  46. data/doc/Compony/ModelFields/Date.html +1 -1
  47. data/doc/Compony/ModelFields/Datetime.html +1 -1
  48. data/doc/Compony/ModelFields/Decimal.html +1 -1
  49. data/doc/Compony/ModelFields/Email.html +1 -1
  50. data/doc/Compony/ModelFields/Float.html +1 -1
  51. data/doc/Compony/ModelFields/Integer.html +1 -1
  52. data/doc/Compony/ModelFields/Percentage.html +1 -1
  53. data/doc/Compony/ModelFields/Phone.html +1 -1
  54. data/doc/Compony/ModelFields/RichText.html +1 -1
  55. data/doc/Compony/ModelFields/String.html +1 -1
  56. data/doc/Compony/ModelFields/Text.html +1 -1
  57. data/doc/Compony/ModelFields/Time.html +1 -1
  58. data/doc/Compony/ModelFields/Url.html +1 -1
  59. data/doc/Compony/ModelFields.html +1 -1
  60. data/doc/Compony/ModelMixin.html +1 -1
  61. data/doc/Compony/NaturalOrdering.html +1 -1
  62. data/doc/Compony/RequestContext.html +1 -1
  63. data/doc/Compony/Version.html +1 -1
  64. data/doc/Compony/ViewHelpers.html +1 -1
  65. data/doc/Compony/VirtualModel.html +1 -1
  66. data/doc/Compony.html +1 -1
  67. data/doc/ComponyController.html +1 -1
  68. data/doc/_index.html +1 -1
  69. data/doc/file.CHANGELOG.html +32 -9
  70. data/doc/file.README.html +1 -1
  71. data/doc/file.basic_component.html +1 -1
  72. data/doc/file.cookbook.html +1 -1
  73. data/doc/file.destroy.html +1 -1
  74. data/doc/file.dsl_reference.html +1 -1
  75. data/doc/file.edit.html +1 -1
  76. data/doc/file.example.html +1 -1
  77. data/doc/file.example_advanced.html +1 -1
  78. data/doc/file.feasibility.html +1 -1
  79. data/doc/file.form.html +1 -1
  80. data/doc/file.generators.html +1 -1
  81. data/doc/file.glossary.html +1 -1
  82. data/doc/file.gotchas.html +1 -1
  83. data/doc/file.index.html +1 -1
  84. data/doc/file.inheritance.html +1 -1
  85. data/doc/file.installation.html +1 -1
  86. data/doc/file.integrations.html +32 -2
  87. data/doc/file.intents.html +8 -4
  88. data/doc/file.internal_datastructures.html +1 -1
  89. data/doc/file.list.html +3 -1
  90. data/doc/file.maintaining.html +1 -1
  91. data/doc/file.model_fields.html +1 -1
  92. data/doc/file.nesting.html +1 -1
  93. data/doc/file.new.html +1 -1
  94. data/doc/file.ownership.html +1 -1
  95. data/doc/file.patterns.html +1 -1
  96. data/doc/file.pre_built_components.html +1 -1
  97. data/doc/file.resourceful.html +1 -1
  98. data/doc/file.show.html +1 -1
  99. data/doc/file.standalone.html +1 -1
  100. data/doc/file.virtual_models.html +1 -1
  101. data/doc/file.with_form.html +1 -1
  102. data/doc/guide/intents.md +6 -3
  103. data/doc/guide/pre_built_components/list.md +4 -0
  104. data/doc/index.html +1 -1
  105. data/doc/integrations.md +46 -1
  106. data/doc/method_list.html +69 -53
  107. data/doc/top-level-namespace.html +1 -1
  108. data/lib/compony/components/buttons/link.rb +37 -2
  109. data/lib/compony/components/form.rb +2 -6
  110. data/lib/compony/model_fields/attachment.rb +7 -6
  111. data/spec/compony/components/buttons/link_spec.rb +73 -0
  112. data/spec/compony/model_fields/attachment_spec.rb +41 -0
  113. data/spec/requests/users_crud_spec.rb +7 -0
  114. metadata +3 -1
@@ -119,7 +119,7 @@
119
119
  </div></div>
120
120
 
121
121
  <div id="footer">
122
- Generated on Wed Oct 7 10:48:18 2026 by
122
+ Generated on Wed Nov 25 14:15:17 2026 by
123
123
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
124
124
  0.9.34 (ruby-3.4.9).
125
125
  </div>
data/doc/file.list.html CHANGED
@@ -111,6 +111,8 @@
111
111
 
112
112
  <h2 id="filtering--sorting-ransack">Filtering &amp; sorting (Ransack)</h2>
113
113
 
114
+ <p>Requires the <code>ransack</code> gem in the host app. Compony allowlists the searchable attributes based on the current user’s <code>:read</code> permission; associations and scopes must be allowlisted by the app. Setup: <a href="/doc/integrations_md.html#ransack">integrations.md § Ransack</a>.</p>
115
+
114
116
  <table role="table">
115
117
  <thead>
116
118
  <tr>
@@ -243,7 +245,7 @@
243
245
  </div></div>
244
246
 
245
247
  <div id="footer">
246
- Generated on Wed Oct 7 10:48:18 2026 by
248
+ Generated on Wed Nov 25 14:15:18 2026 by
247
249
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
248
250
  0.9.34 (ruby-3.4.9).
249
251
  </div>
@@ -117,7 +117,7 @@
117
117
  </div></div>
118
118
 
119
119
  <div id="footer">
120
- Generated on Wed Oct 7 10:48:19 2026 by
120
+ Generated on Wed Nov 25 14:15:19 2026 by
121
121
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
122
122
  0.9.34 (ruby-3.4.9).
123
123
  </div>
@@ -127,7 +127,7 @@
127
127
  </div></div>
128
128
 
129
129
  <div id="footer">
130
- Generated on Wed Oct 7 10:48:18 2026 by
130
+ Generated on Wed Nov 25 14:15:17 2026 by
131
131
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
132
132
  0.9.34 (ruby-3.4.9).
133
133
  </div>
@@ -227,7 +227,7 @@ The number 8 has the binary form 1000. Enter a number and press ENTER: [8]
227
227
  </div></div>
228
228
 
229
229
  <div id="footer">
230
- Generated on Wed Oct 7 10:48:17 2026 by
230
+ Generated on Wed Nov 25 14:15:17 2026 by
231
231
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
232
232
  0.9.34 (ruby-3.4.9).
233
233
  </div>
data/doc/file.new.html CHANGED
@@ -99,7 +99,7 @@
99
99
  </div></div>
100
100
 
101
101
  <div id="footer">
102
- Generated on Wed Oct 7 10:48:18 2026 by
102
+ Generated on Wed Nov 25 14:15:18 2026 by
103
103
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
104
104
  0.9.34 (ruby-3.4.9).
105
105
  </div>
@@ -88,7 +88,7 @@
88
88
  </div></div>
89
89
 
90
90
  <div id="footer">
91
- Generated on Wed Oct 7 10:48:18 2026 by
91
+ Generated on Wed Nov 25 14:15:17 2026 by
92
92
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
93
93
  0.9.34 (ruby-3.4.9).
94
94
  </div>
@@ -659,7 +659,7 @@
659
659
  </div></div>
660
660
 
661
661
  <div id="footer">
662
- Generated on Wed Oct 7 10:48:19 2026 by
662
+ Generated on Wed Nov 25 14:15:19 2026 by
663
663
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
664
664
  0.9.34 (ruby-3.4.9).
665
665
  </div>
@@ -89,7 +89,7 @@
89
89
  </div></div>
90
90
 
91
91
  <div id="footer">
92
- Generated on Wed Oct 7 10:48:18 2026 by
92
+ Generated on Wed Nov 25 14:15:17 2026 by
93
93
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
94
94
  0.9.34 (ruby-3.4.9).
95
95
  </div>
@@ -171,7 +171,7 @@
171
171
  </div></div>
172
172
 
173
173
  <div id="footer">
174
- Generated on Wed Oct 7 10:48:17 2026 by
174
+ Generated on Wed Nov 25 14:15:17 2026 by
175
175
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
176
176
  0.9.34 (ruby-3.4.9).
177
177
  </div>
data/doc/file.show.html CHANGED
@@ -148,7 +148,7 @@
148
148
  </div></div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Wed Oct 7 10:48:18 2026 by
151
+ Generated on Wed Nov 25 14:15:17 2026 by
152
152
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.9.34 (ruby-3.4.9).
154
154
  </div>
@@ -223,7 +223,7 @@
223
223
  </div></div>
224
224
 
225
225
  <div id="footer">
226
- Generated on Wed Oct 7 10:48:17 2026 by
226
+ Generated on Wed Nov 25 14:15:17 2026 by
227
227
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
228
228
  0.9.34 (ruby-3.4.9).
229
229
  </div>
@@ -107,7 +107,7 @@
107
107
  </div></div>
108
108
 
109
109
  <div id="footer">
110
- Generated on Wed Oct 7 10:48:18 2026 by
110
+ Generated on Wed Nov 25 14:15:17 2026 by
111
111
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
112
112
  0.9.34 (ruby-3.4.9).
113
113
  </div>
@@ -147,7 +147,7 @@
147
147
  </div></div>
148
148
 
149
149
  <div id="footer">
150
- Generated on Wed Oct 7 10:48:18 2026 by
150
+ Generated on Wed Nov 25 14:15:18 2026 by
151
151
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
152
152
  0.9.34 (ruby-3.4.9).
153
153
  </div>
data/doc/guide/intents.md CHANGED
@@ -108,7 +108,8 @@ Compony comes with two button styles:
108
108
  All button styles support the following keyword arguments to their initializer:
109
109
 
110
110
  - `label` is a String which will be displayed as the text of the link or button.
111
- - `href` is the url/path that the button points to. If `nil`, will change to `javascript:void(0)`.
111
+ - `href` is the url/path that the button points to. If `nil`, an `<a>` without `href` is rendered, which does nothing when clicked.
112
+ - `type` renders a `<button>` of that type instead of a link, e.g. `type: :submit` for a button submitting the surrounding form.
112
113
  - `method` takes a HTTP verb will generate a suitable `turbo_method` data attribute.
113
114
  - `class` will mostly let be as-is, but checked for the `disabled` class - if given, the style will be ovewritten.
114
115
 
@@ -116,11 +117,13 @@ Note that since buttons are full components, they can be [nested](/doc/guide/nes
116
117
 
117
118
  As implicitely mentioned above, Compony buttons are referenced to by a name called a style (`:css_button` actually points to `Compony::Components::Buttons::CssButton`). When rendering an intent, the style can be passed as an argument: `render_intent(:show, User.first, style: :link)` and the intent will automatically instanciate the desired component class.
118
119
 
119
- Note: it is possible to use a button component to submit a form. In order to achieve this, you must implement a hidden submit button (for handling keyboard Enter and Return), as well as pass `onclick: "this.closest('form').requestSubmit(); return false;"` as an argument. See the pre-built Form component's implementation for an example.
120
+ To use a button component to submit a form, pass `type: :submit` (e.g. `render_intent(name: :submit, label: 'Save', button: { type: :submit })`). This renders a real `<button type="submit">`, which also submits the form on Return and needs no JavaScript. See the pre-built Form component's `submit_button` content block for an example.
121
+
122
+ Compony's buttons render no inline JavaScript (`onclick` attributes, `javascript:` URLs), so they keep working under a Content Security Policy that only allows scripts carrying a nonce.
120
123
 
121
124
  ### Adding your own styles
122
125
 
123
- In your application, you will likely want to implement your own button styles. Create a component (e.g. `Components::Commons::MyButton`) and inherit from `Compony::Components::Buttons::Link`. Override the method `prepare_opts!` and don't forget to call `super` first. Then, go through any `@comp_args` that might be of interest to you and mutate `@comp_args[:style]` and/or `@comp_args[:class]` to suit your needs. Make sure to handle the class `disabled`, as intents will set them if the intent is not feasible. Note that if a user is lacking authorization to perform an intent, the intent will not even instanciate the button.
126
+ In your application, you will likely want to implement your own button styles. Create a component (e.g. `Components::Commons::MyButton`) and inherit from `Compony::Components::Buttons::Link`. Override the method `prepare_opts!` and don't forget to call `super` first. Then, go through any `@comp_args` that might be of interest to you and mutate `@comp_args[:style]` and/or `@comp_args[:class]` to suit your needs. Make sure to handle the class `disabled`, as intents will set them if the intent is not feasible. If you also override the `content` block (e.g. to add an icon), render the element through `component.link_or_button(inner_html, **opts)` rather than calling `link_to(@href, ...)` yourself: it renders the `<button>` for `type:` and the `<a>` without `href`, e.g. `concat component.link_or_button(capture { span @label }, **@comp_opts)`. A button style given `type:` that does not render through `link_or_button` raises an error, as it would otherwise render a link that cannot submit the form. Note that if a user is lacking authorization to perform an intent, the intent will not even instanciate the button.
124
127
 
125
128
  Once your button class is ready, register it in `config/initializers/compony.rb` with: `Compony.register_button_style :my_button, '::Components::Commons::MyButton'`. You can also change the default button style there using: `Compony.default_button_style = :my_button`.
126
129
 
@@ -34,6 +34,10 @@ end
34
34
 
35
35
  ## Filtering & sorting (Ransack)
36
36
 
37
+ Requires the `ransack` gem in the host app. Compony allowlists the searchable attributes based
38
+ on the current user's `:read` permission; associations and scopes must be allowlisted by the
39
+ app. Setup: [integrations.md § Ransack](/doc/integrations.md#ransack).
40
+
37
41
  | Method | Signature | Description |
38
42
  | --- | --- | --- |
39
43
  | `filter` | `filter(:name, label: nil) { \|f\| ... }` | Add a filter. No block → field filter or a Ransack predicate string (e.g. `:id_eq`). Block gets the Ransack search form and renders label + input. |
data/doc/index.html CHANGED
@@ -230,7 +230,7 @@
230
230
  </div></div>
231
231
 
232
232
  <div id="footer">
233
- Generated on Wed Oct 7 10:48:16 2026 by
233
+ Generated on Wed Nov 25 14:15:16 2026 by
234
234
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
235
235
  0.9.34 (ruby-3.4.9).
236
236
  </div>
data/doc/integrations.md CHANGED
@@ -34,7 +34,52 @@ are in the host app's bundle.
34
34
  | Gem | Unlocks |
35
35
  | --- | --- |
36
36
  | `active_type` | `Compony::VirtualModel` (loaded only if `ActiveType::Object` is defined). Non-persistent / upload / wizard forms — [patterns §12](/doc/guide/patterns.md#12-virtual-model-for-non-persistent--upload-forms), [virtual_models.md](/doc/guide/virtual_models.md). |
37
- | `ransack` | List filtering, sorting links and the sort select in [`List`](/doc/guide/pre_built_components/list.md). Without it, declare no `filter`/`sort` and those UIs stay off. |
37
+ | `ransack` | List filtering, sorting links and the sort select in [`List`](/doc/guide/pre_built_components/list.md). Without it, declare no `filter`/`sort` and those UIs stay off. Setup: [Ransack](#ransack) below. |
38
+
39
+ ### Ransack
40
+
41
+ To enable filtering and sorting in [`List`](/doc/guide/pre_built_components/list.md), add the
42
+ gem to the host app's `Gemfile`; Compony detects it via `defined?(Ransack)`, no initializer
43
+ needed:
44
+
45
+ ```ruby
46
+ gem 'ransack'
47
+ ```
48
+
49
+ Ransack only searches and sorts by attributes a model explicitly allows. Compony fills in that
50
+ allowlist for you: `Compony::ModelMixin` defines
51
+
52
+ ```ruby
53
+ def self.ransackable_attributes(auth_object)
54
+ auth_object.permitted_attributes(:read, self).map(&:to_s)
55
+ end
56
+ ```
57
+
58
+ and `List` passes `auth_object: controller.current_ability`. So a user can filter and sort only
59
+ by the attributes CanCanCan lets them `:read`. A field's auto-generated filter therefore needs
60
+ both a `field` declaration and read permission on it.
61
+
62
+ What you still provide yourself:
63
+
64
+ - **`ransackable_associations`** when a filter or sort goes through an association, e.g.
65
+ `filter :customer_name_cont`. Compony does not define it, so Ransack refuses such searches
66
+ until the model allows them:
67
+
68
+ ```ruby
69
+ def self.ransackable_associations(_auth_object = nil)
70
+ %w[customer]
71
+ end
72
+ ```
73
+
74
+ - **`ransackable_scopes`** when a filter calls a model scope.
75
+ - **Your own `Model.ransack(...)` calls outside `List`** must pass
76
+ `auth_object: current_ability`. Without it, Compony's default calls `permitted_attributes`
77
+ on `nil` and raises `NoMethodError`. Alternatively, override `ransackable_attributes` in
78
+ the model, which also replaces the permission-based default for `List`.
79
+
80
+ Default filter per field type (see `ransack_filter_name` in `lib/compony/model_fields/`):
81
+ `<field>_cont` (text search), `<field>_eq` for `:integer`, a select for `:boolean` and
82
+ `:anchormodel`.
38
83
 
39
84
  ## App-side companions (you add these)
40
85