compony 0.5.3 → 0.5.5
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 +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +6 -6
- data/README.md +36 -0
- data/VERSION +1 -1
- data/app/controllers/compony_controller.rb +4 -0
- data/compony.gemspec +4 -4
- data/doc/ComponentGenerator.html +1 -1
- data/doc/Components.html +1 -1
- data/doc/ComponentsGenerator.html +1 -1
- data/doc/Compony/Component.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Labelling.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/ResourcefulVerbDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/StandaloneDsl.html +96 -27
- data/doc/Compony/ComponentMixins/Default/Standalone/VerbDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone.html +1 -1
- data/doc/Compony/ComponentMixins/Default.html +1 -1
- data/doc/Compony/ComponentMixins/Resourceful.html +1 -1
- data/doc/Compony/ComponentMixins.html +1 -1
- data/doc/Compony/Components/Button.html +1 -1
- data/doc/Compony/Components/Destroy.html +1 -1
- data/doc/Compony/Components/Edit.html +1 -1
- data/doc/Compony/Components/Form.html +210 -127
- data/doc/Compony/Components/New.html +1 -1
- data/doc/Compony/Components/WithForm.html +1 -1
- data/doc/Compony/Components.html +1 -1
- data/doc/Compony/ControllerMixin.html +1 -1
- data/doc/Compony/Engine.html +1 -1
- data/doc/Compony/MethodAccessibleHash.html +1 -1
- data/doc/Compony/ModelFields/Anchormodel.html +1 -1
- data/doc/Compony/ModelFields/Association.html +1 -1
- data/doc/Compony/ModelFields/Attachment.html +1 -1
- data/doc/Compony/ModelFields/Base.html +1 -1
- data/doc/Compony/ModelFields/Boolean.html +1 -1
- data/doc/Compony/ModelFields/Color.html +1 -1
- data/doc/Compony/ModelFields/Currency.html +1 -1
- data/doc/Compony/ModelFields/Date.html +1 -1
- data/doc/Compony/ModelFields/Datetime.html +1 -1
- data/doc/Compony/ModelFields/Decimal.html +1 -1
- data/doc/Compony/ModelFields/Email.html +1 -1
- data/doc/Compony/ModelFields/Float.html +1 -1
- data/doc/Compony/ModelFields/Integer.html +1 -1
- data/doc/Compony/ModelFields/Percentage.html +1 -1
- data/doc/Compony/ModelFields/Phone.html +1 -1
- data/doc/Compony/ModelFields/RichText.html +1 -1
- data/doc/Compony/ModelFields/String.html +1 -1
- data/doc/Compony/ModelFields/Text.html +1 -1
- data/doc/Compony/ModelFields/Time.html +1 -1
- data/doc/Compony/ModelFields/Url.html +1 -1
- data/doc/Compony/ModelFields.html +1 -1
- data/doc/Compony/ModelMixin.html +29 -29
- data/doc/Compony/NaturalOrdering.html +1 -1
- data/doc/Compony/RequestContext.html +1 -1
- data/doc/Compony/Version.html +1 -1
- data/doc/Compony/ViewHelpers.html +1 -1
- data/doc/Compony.html +3 -3
- data/doc/ComponyController.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +42 -7
- data/doc/index.html +42 -7
- data/doc/method_list.html +112 -96
- data/doc/top-level-namespace.html +1 -1
- data/lib/compony/component_mixins/default/standalone/standalone_dsl.rb +18 -10
- data/lib/compony/components/form.rb +49 -32
- data/lib/compony/model_mixin.rb +24 -14
- data/lib/compony.rb +2 -2
- metadata +3 -9
data/doc/index.html
CHANGED
@@ -195,7 +195,7 @@
|
|
195
195
|
|
196
196
|
<p>Here is what our Show component looks like when we have a layout with the bare minimum and no styling at all:</p>
|
197
197
|
|
198
|
-
<p><img src="doc/imgs/intro-example-show.png"
|
198
|
+
<p><img src="doc/imgs/intro-example-show.png" alt="Screenshot"> of our component with an absolutely minimal layout</p>
|
199
199
|
|
200
200
|
<p>It is important to note that actions, buttons, navigation, notifications etc. are handled by the application layout. In this and the subsequent screenshots, we explicitely use minimalism, as it makes the generated HTML clearer.</p>
|
201
201
|
|
@@ -209,7 +209,7 @@
|
|
209
209
|
|
210
210
|
<p>Note that this component is fully functional. All is handled by the class it inherits from:</p>
|
211
211
|
|
212
|
-
<p><img src="doc/imgs/intro-example-destroy.png"
|
212
|
+
<p><img src="doc/imgs/intro-example-destroy.png" alt="Screenshot"> of the destroy component</p>
|
213
213
|
|
214
214
|
<h3 id="label-The+New+component+and+the+Form+component">The New component and the Form component</h3>
|
215
215
|
|
@@ -243,7 +243,7 @@
|
|
243
243
|
|
244
244
|
<p>This is enough to render a fully functional form that creates new users:</p>
|
245
245
|
|
246
|
-
<p><img src="doc/imgs/intro-example-new.png"
|
246
|
+
<p><img src="doc/imgs/intro-example-new.png" alt="New"> form</p>
|
247
247
|
|
248
248
|
<h3 id="label-The+Edit+component">The Edit component</h3>
|
249
249
|
|
@@ -255,7 +255,7 @@
|
|
255
255
|
|
256
256
|
<p>It then looks like this:</p>
|
257
257
|
|
258
|
-
<p><img src="doc/imgs/intro-example-edit.png"
|
258
|
+
<p><img src="doc/imgs/intro-example-edit.png" alt="Edit"> form</p>
|
259
259
|
|
260
260
|
<h3 id="label-The+Index+component">The Index component</h3>
|
261
261
|
|
@@ -307,7 +307,7 @@
|
|
307
307
|
|
308
308
|
<p>The result looks like this:</p>
|
309
309
|
|
310
|
-
<p><img src="doc/imgs/intro-example-index.png"
|
310
|
+
<p><img src="doc/imgs/intro-example-index.png" alt="Index"> component</p>
|
311
311
|
|
312
312
|
<p>Note how the admin’s delete button is disabled due to the feasibility framework. Pointing the mouse at it causes a tooltip saying: “Cannot destroy admins.”, as specified in the model’s prevention.</p>
|
313
313
|
|
@@ -624,6 +624,8 @@
|
|
624
624
|
</li><li>
|
625
625
|
<p><code>skip_authentication!</code> which disables authentication, in case you provided some. You need to implement <code>authorize</code> regardless.</p>
|
626
626
|
</li><li>
|
627
|
+
<p><code>skip_forgery_protection!</code> which disables CSRF protection for the controller action generated for this standalone configuration.</p>
|
628
|
+
</li><li>
|
627
629
|
<p><code>layout</code> which takes the file name of a Rails layout and defaults to <code>layouts/application</code>. Use this to have your Rails application look differently depending on the component.</p>
|
628
630
|
</li><li>
|
629
631
|
<p><code>verb</code> which takes an HTTP verb as a symbol, one of: <code>%i[get head post put delete connect options trace patch]</code>. <code>verb</code> can be called up to once per verb. Inside each <code>verb</code> call, you can call (in the non-resourceful case):</p>
|
@@ -1009,7 +1011,7 @@ The number 8 has the binary form 1000. Enter a number and press ENTER: [8]
|
|
1009
1011
|
<p><code>respond</code> typically shows a flash and redirects to another component.</p>
|
1010
1012
|
</li></ul>
|
1011
1013
|
|
1012
|
-
<p><img src="doc/resourceful_lifecycle.png"
|
1014
|
+
<p><img src="doc/resourceful_lifecycle.png" alt="Graph"> of the complete resourceful lifecycle</p>
|
1013
1015
|
|
1014
1016
|
<h3 id="label-Nesting+resourceful+components">Nesting resourceful components</h3>
|
1015
1017
|
|
@@ -1518,6 +1520,39 @@ my_button = Compony.button(:index, :users, enabled: -> { |controller| control
|
|
1518
1520
|
cannot :set_password, User # This prohibits setting and changing passwords of any user
|
1519
1521
|
</code></pre>
|
1520
1522
|
|
1523
|
+
<h4 id="label-Dealing+with+multilingual+fields">Dealing with multilingual fields</h4>
|
1524
|
+
|
1525
|
+
<p>When using Gems such as <code>mobility</code>, Compony provides support for multilingual fields. For instance, assuming that a model has the attribute <code>label</code> translated in English and German, making <code>label</code> a virtual attribute reading either <code>label_en</code> and <code>label_de</code>, depending on the user’s language, Compony automatically generates a multilingual field if the following is used:</p>
|
1526
|
+
|
1527
|
+
<p>In the model:</p>
|
1528
|
+
|
1529
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Foo</span> <span class='op'><</span> <span class='const'>ApplicationRecord</span>
|
1530
|
+
<span class='comment'># No need to write:
|
1531
|
+
</span> <span class='id identifier rubyid_field'>field</span> <span class='symbol'>:label</span><span class='comma'>,</span> <span class='symbol'>:string</span><span class='comma'>,</span> <span class='label'>virtual:</span> <span class='kw'>true</span>
|
1532
|
+
<span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_available_locales'>available_locales</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_locale'>locale</span><span class='op'>|</span>
|
1533
|
+
<span class='id identifier rubyid_field'>field</span> <span class='symbol'>:"label_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_locale'>locale</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='symbol'>:string</span>
|
1534
|
+
<span class='kw'>end</span>
|
1535
|
+
|
1536
|
+
<span class='comment'># Instead, write this, which is equivalent:
|
1537
|
+
</span> <span class='id identifier rubyid_field'>field</span> <span class='symbol'>:label</span><span class='comma'>,</span> <span class='symbol'>:string</span><span class='comma'>,</span> <span class='label'>multilang:</span> <span class='kw'>true</span>
|
1538
|
+
<span class='kw'>end</span>
|
1539
|
+
</code></pre>
|
1540
|
+
|
1541
|
+
<p>In the same mindset, you can simplify your form as follows to generate one input per language:</p>
|
1542
|
+
|
1543
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'><span class='object_link'><a href="Components.html" title="Components (module)">Components</a></span></span><span class='op'>::</span><span class='const'>Foos</span><span class='op'>::</span><span class='const'>Form</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Compony.html" title="Compony (module)">Compony</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Compony/Components.html" title="Compony::Components (module)">Components</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Compony/Components/Form.html" title="Compony::Components::Form (class)">Form</a></span></span>
|
1544
|
+
<span class='id identifier rubyid_setup'>setup</span> <span class='kw'>do</span>
|
1545
|
+
<span class='id identifier rubyid_form_fields'>form_fields</span> <span class='kw'>do</span>
|
1546
|
+
<span class='comment'># Since `field` only generates an input, you must loop over them and render them as you wish, e.g. with "concat":
|
1547
|
+
</span> <span class='id identifier rubyid_field'>field</span><span class='lparen'>(</span><span class='symbol'>:label</span><span class='comma'>,</span> <span class='label'>multilang:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_inp'>inp</span><span class='op'>|</span> <span class='id identifier rubyid_concat'>concat</span> <span class='id identifier rubyid_inp'>inp</span> <span class='rbrace'>}</span>
|
1548
|
+
<span class='kw'>end</span>
|
1549
|
+
|
1550
|
+
<span class='comment'># Don't forget to mark `schema_field` as multilingual as well, which will accept label_en and label_de:
|
1551
|
+
</span> <span class='id identifier rubyid_schema_field'>schema_field</span> <span class='symbol'>:label</span><span class='comma'>,</span> <span class='label'>multilang:</span> <span class='kw'>true</span>
|
1552
|
+
<span class='kw'>end</span>
|
1553
|
+
<span class='kw'>end</span>
|
1554
|
+
</code></pre>
|
1555
|
+
|
1521
1556
|
<h3 id="label-New">New</h3>
|
1522
1557
|
|
1523
1558
|
<p>This component is the Compony equivalent to a typical Rails controller’s <code>new</code> and <code>create</code> actions.</p>
|
@@ -1695,7 +1730,7 @@ my_button = Compony.button(:index, :users, enabled: -> { |controller| control
|
|
1695
1730
|
</div></div>
|
1696
1731
|
|
1697
1732
|
<div id="footer">
|
1698
|
-
Generated on
|
1733
|
+
Generated on Mon Apr 7 13:00:51 2025 by
|
1699
1734
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1700
1735
|
0.9.37 (ruby-3.3.5).
|
1701
1736
|
</div>
|