compony 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +23 -0
- data/Gemfile.lock +3 -3
- data/README.md +80 -13
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/compony.gemspec +5 -5
- data/doc/ComponentGenerator.html +1 -1
- data/doc/Components.html +1 -1
- data/doc/ComponentsGenerator.html +1 -1
- data/doc/Compony/Component.html +308 -341
- 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 +1 -1
- 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 +3 -3
- data/doc/Compony/Components/Destroy.html +3 -3
- data/doc/Compony/Components/Edit.html +19 -19
- data/doc/Compony/Components/Form.html +3 -3
- data/doc/Compony/Components/New.html +19 -19
- data/doc/Compony/Components/WithForm.html +4 -4
- 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 +7 -3
- 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 +1 -1
- data/doc/Compony/NaturalOrdering.html +292 -0
- data/doc/Compony/RequestContext.html +72 -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 +8 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +73 -16
- data/doc/index.html +73 -16
- data/doc/method_list.html +100 -100
- data/doc/top-level-namespace.html +1 -1
- data/lib/compony/component.rb +30 -54
- data/lib/compony/components/edit.rb +2 -4
- data/lib/compony/components/new.rb +4 -6
- data/lib/compony/components/with_form.rb +1 -1
- data/lib/compony/model_fields/anchormodel.rb +3 -1
- data/lib/compony/natural_ordering.rb +56 -0
- data/lib/compony/request_context.rb +8 -0
- data/lib/compony.rb +1 -0
- metadata +6 -4
data/doc/index.html
CHANGED
@@ -87,7 +87,7 @@
|
|
87
87
|
</li><li>
|
88
88
|
<p>Compony is built for Rails 7 and fully supports Stimulus and Turbo Drive. Turbo Frames and Streams are not yet targeted, so Compony is currently meant for websites where every click triggers a “full page load” (in quotes because they are not actually full page loads due to Turbo Drive).</p>
|
89
89
|
</li><li>
|
90
|
-
<p>Compony uses
|
90
|
+
<p>Compony uses <a href="https://github.com/CanCanCommunity/cancancan">CanCanCan</a> for authorization but does not provide an authentication mechanism. You can easily build your own by creating login/logout components that manage cookies, and configure Compony to enforce authentication using the <code>Compony.authentication_before_action</code> setter. We have also successfully tested Compony to work with <a href="https://github.com/heartcombo/devise">Devise</a>.</p>
|
91
91
|
</li></ul>
|
92
92
|
|
93
93
|
<h2 id="label-State+of+the+project">State of the project</h2>
|
@@ -311,6 +311,10 @@
|
|
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
|
|
314
|
+
<h1 id="label-Related+projects">Related projects</h1>
|
315
|
+
|
316
|
+
<p>A project with a similar aim, but a different approach, is <a href="https://github.com/phlex-ruby/phlex">Phlex</a>.</p>
|
317
|
+
|
314
318
|
<h1 id="label-Installation">Installation</h1>
|
315
319
|
|
316
320
|
<h2 id="label-Installing+Compony">Installing Compony</h2>
|
@@ -473,32 +477,87 @@
|
|
473
477
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_setup'>setup</span> <span class='kw'>do</span>
|
474
478
|
<span class='id identifier rubyid_label'>label</span><span class='lparen'>(</span><span class='symbol'>:all</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Welcome</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span>
|
475
479
|
<span class='id identifier rubyid_content'>content</span> <span class='kw'>do</span>
|
476
|
-
<span class='id identifier rubyid_h1'>h1</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Welcome to my basic component
|
480
|
+
<span class='id identifier rubyid_h1'>h1</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Welcome to my basic component.</span><span class='tstring_end'>'</span></span>
|
477
481
|
<span class='id identifier rubyid_para'>para</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>It's not much, but it's honest work.</span><span class='tstring_end'>"</span></span>
|
478
482
|
<span class='kw'>end</span>
|
479
483
|
<span class='kw'>end</span>
|
480
484
|
</code></pre>
|
481
485
|
|
482
|
-
<
|
486
|
+
<h5 id="label-Naming+content+blocks-2C+ordering+and+overriding+them+in+subclasses">Naming content blocks, ordering and overriding them in subclasses</h5>
|
487
|
+
|
488
|
+
<p>Content blocks are actually named. The <code>content</code> call adds or replaces a previously defined content block, e.g. in an earlier call to <code>setup</code> in a component’s superclass. When calling <code>content</code> without a name, it defaults to <code>main</code> and will overwrite any previous <code>main</code> content. However, you can provide your own name and refer to other names by using the <code>before:</code> keyword.</p>
|
483
489
|
|
484
490
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_setup'>setup</span> <span class='kw'>do</span>
|
485
|
-
<span class='id identifier rubyid_content'>content</span> <span class='kw'>do</span>
|
486
|
-
<span class='id identifier rubyid_h1'>h1</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Welcome to my basic component
|
491
|
+
<span class='id identifier rubyid_content'>content</span> <span class='kw'>do</span> <span class='comment'># will become :main
|
492
|
+
</span> <span class='id identifier rubyid_h1'>h1</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Welcome to my basic component.</span><span class='tstring_end'>'</span></span>
|
487
493
|
<span class='kw'>end</span>
|
488
|
-
<span class='id identifier
|
494
|
+
<span class='id identifier rubyid_content'>content</span> <span class='symbol'>:thanks</span> <span class='kw'>do</span>
|
489
495
|
<span class='id identifier rubyid_para'>para</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Thank you and see you tomorrow.</span><span class='tstring_end'>'</span></span>
|
490
496
|
<span class='kw'>end</span>
|
491
|
-
<span class='id identifier
|
497
|
+
<span class='id identifier rubyid_content'>content</span> <span class='symbol'>:middle</span><span class='comma'>,</span> <span class='label'>before:</span> <span class='symbol'>:thanks</span> <span class='kw'>do</span>
|
492
498
|
<span class='id identifier rubyid_para'>para</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>This paragraph is inserted between the others.</span><span class='tstring_end'>'</span></span>
|
493
499
|
<span class='kw'>end</span>
|
500
|
+
<span class='id identifier rubyid_content'>content</span> <span class='symbol'>:thanks</span> <span class='kw'>do</span>
|
501
|
+
<span class='id identifier rubyid_para'>para</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Thank you and see you tonight.</span><span class='tstring_end'>'</span></span> <span class='comment'># this overwrites "Thank you and see you tomorrow."
|
502
|
+
</span> <span class='kw'>end</span>
|
503
|
+
<span class='id identifier rubyid_content'>content</span> <span class='symbol'>:first</span><span class='comma'>,</span> <span class='label'>before:</span> <span class='symbol'>:main</span> <span class='kw'>do</span>
|
504
|
+
<span class='id identifier rubyid_para'>para</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>This appears first.</span><span class='tstring_end'>'</span></span>
|
505
|
+
<span class='kw'>end</span>
|
494
506
|
<span class='kw'>end</span>
|
495
507
|
</code></pre>
|
496
508
|
|
497
|
-
<p>
|
509
|
+
<p>This results in: - This appears first. - Welcome to my basic component. - This paragraph is inserted between the others. - Thank you and see you tonight.</p>
|
510
|
+
|
511
|
+
<p>As you see, overusing this feature can lead to messy code as it becomes unclear what happens in what order. For this reason, this feature should only be used to decouple the content of your abstract components for allowing surgical overrides in subclasses.</p>
|
512
|
+
|
513
|
+
<p>It is a good convention to always have one content block named <code>:main</code>, as you might want to refer to it in subclasses.</p>
|
514
|
+
|
515
|
+
<h5 id="label-Nesting+content+blocks-2C+calling+a+content+block+from+another">Nesting content blocks, calling a content block from another</h5>
|
516
|
+
|
517
|
+
<p>In some situations, such as in forms, it can be useful to nest content blocks. This will also allow subclasses to override a wrapper while keeping the content, and vice versa. To make this possible, you can also use the <code>content</code> keyword inside a content block. Note that unlike the call in <code>setup</code>, this call will render a content block instead of defining it. This happens inside the request context and the content block must be defined inside the current component.</p>
|
518
|
+
|
519
|
+
<p>Note that you cannot call another component’s content block this way.</p>
|
520
|
+
|
521
|
+
<p>Here is an example on how to use this feature, e.g. to create a bootstrap card that can be overridden with precision:</p>
|
522
|
+
|
523
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Components::Bootstrap::Card
|
524
|
+
</span><span class='id identifier rubyid_setup'>setup</span> <span class='kw'>do</span>
|
525
|
+
<span class='id identifier rubyid_content'>content</span> <span class='label'>hidden:</span> <span class='kw'>true</span> <span class='kw'>do</span> <span class='comment'># hidden: true will cause `render` to skip this content block. You can still use it in the nested fashion.
|
526
|
+
</span> <span class='id identifier rubyid_div'>div</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>I am the default content for the card</span><span class='tstring_end'>'</span></span>
|
527
|
+
<span class='kw'>end</span>
|
528
|
+
|
529
|
+
<span class='id identifier rubyid_content'>content</span> <span class='symbol'>:card</span> <span class='kw'>do</span>
|
530
|
+
<span class='id identifier rubyid_div'>div</span> <span class='label'>class:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>card card-body</span><span class='tstring_end'>'</span></span> <span class='kw'>do</span>
|
531
|
+
<span class='id identifier rubyid_content'>content</span> <span class='symbol'>:main</span>
|
532
|
+
<span class='kw'>end</span>
|
533
|
+
<span class='kw'>end</span>
|
534
|
+
<span class='kw'>end</span>
|
535
|
+
</code></pre>
|
536
|
+
|
537
|
+
<p>The output is:</p>
|
538
|
+
|
539
|
+
<pre class="code ruby"><code class="ruby"><div class="card card-body"><div>I am the default content for the card</div></div>
|
540
|
+
</code></pre>
|
541
|
+
|
542
|
+
<p>So when you subclass this component, you can forget about the card and just overwrite <code>:main</code> as follows:</p>
|
543
|
+
|
544
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Components::Hello::HelloCard < Components::Bootstrap::Card
|
545
|
+
</span><span class='id identifier rubyid_setup'>setup</span> <span class='kw'>do</span>
|
546
|
+
<span class='id identifier rubyid_content'>content</span> <span class='kw'>do</span> <span class='comment'># hidden is still true because the old :main content block specified that already.
|
547
|
+
</span> <span class='id identifier rubyid_h1'>h1</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Hello</span><span class='tstring_end'>'</span></span>
|
548
|
+
<span class='id identifier rubyid_para'>para</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Welcome to my site.</span><span class='tstring_end'>'</span></span>
|
549
|
+
<span class='kw'>end</span>
|
550
|
+
<span class='kw'>end</span>
|
551
|
+
</code></pre>
|
552
|
+
|
553
|
+
<p>The output is:</p>
|
554
|
+
|
555
|
+
<pre class="code ruby"><code class="ruby"><div class="card card-body"><h1>Hello</h1><p>Welcome to my site.</p></div>
|
556
|
+
</code></pre>
|
498
557
|
|
499
558
|
<h4 id="label-Redirecting+away+-2F+Intercepting+rendering">Redirecting away / Intercepting rendering</h4>
|
500
559
|
|
501
|
-
<p>Immediately before the <code>content</code> block(s) are evaluated, another
|
560
|
+
<p>Immediately before the <code>content</code> block(s) are evaluated, another chain of blocks is evaluated if present: <code>before_render</code>. If on of these blocks creates a reponse body in the Rails controller, the subsequent <code>before_render</code> blocks and all <code>content</code> blocks are skipped.</p>
|
502
561
|
|
503
562
|
<p>This is useful for redirecting. Here is an example of a component that provides a restaurant’s lunch menu, but redirects to the menu overview page instead if it’s not lunch time:</p>
|
504
563
|
|
@@ -520,6 +579,8 @@
|
|
520
579
|
<span class='kw'>end</span>
|
521
580
|
</code></pre>
|
522
581
|
|
582
|
+
<p>Similarly to <code>content</code>, the <code>before_render</code> method also accepts a name, defaulting to <code>:main</code>, as well as a <code>before:</code> keyword. This allows you to selectively extend and/or override <code>before_render</code> blocks in subclasses.</p>
|
583
|
+
|
523
584
|
<h2 id="label-Standalone">Standalone</h2>
|
524
585
|
|
525
586
|
<p>As stated earlier, Compony can generate routes to your components. This is achieved by using the standalone DSL inside the setup block. The first step is calling the method <code>standalone</code> with a path. Inside this block, you will then specify which HTTP verbs (e.g. GET, PATCH etc.) the component should listen to. As soon as both are specified, Compony will generate an appropriate route.</p>
|
@@ -657,7 +718,7 @@
|
|
657
718
|
<span class='id identifier rubyid_standalone'>standalone</span> <span class='kw'>do</span>
|
658
719
|
<span class='id identifier rubyid_layout'>layout</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dark</span><span class='tstring_end'>'</span></span>
|
659
720
|
<span class='kw'>end</span>
|
660
|
-
<span class='id identifier
|
721
|
+
<span class='id identifier rubyid_content'>content</span> <span class='symbol'>:below</span> <span class='kw'>do</span>
|
661
722
|
<span class='id identifier rubyid_para'>para</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>This will appear below "Test".</span><span class='tstring_end'>'</span></span>
|
662
723
|
<span class='kw'>end</span>
|
663
724
|
<span class='kw'>end</span>
|
@@ -1397,7 +1458,7 @@ my_button = Compony.button(:index, :users, enabled: -> { |controller| control
|
|
1397
1458
|
|
1398
1459
|
<p>This component follows the resourceful lifecycle, explained in above under “Resourceful”. <code>load_data</code> is set to create a new record and <code>store_data</code> attempts to create it. Parameters are validated in <code>assign_attributes</code> using a Schemacop schema that is generated from the form. The schema corresponds to Rail’s typical strong parameter structure for forms. For example, a user’s New component would look for a parameter <code>user</code> holding a hash of attributes (e.g. <code>user[first_name]=Tom</code>).</p>
|
1399
1460
|
|
1400
|
-
<p>In case you overwrite <code>store_data</code>, make sure to set <code>@
|
1461
|
+
<p>In case you overwrite <code>store_data</code>, make sure to set <code>@create_succeeded</code> to true if storing was successful (and to set it to false otherwise).</p>
|
1401
1462
|
|
1402
1463
|
<p>The following DSL calls are implemented to allow for convenient overrides of default logic:</p>
|
1403
1464
|
<ul><li>
|
@@ -1525,10 +1586,6 @@ my_button = Compony.button(:index, :users, enabled: -> { |controller| control
|
|
1525
1586
|
<ul><li>
|
1526
1587
|
<p>The API is not yet as consistent as I’d like it. Examples:</p>
|
1527
1588
|
</li><li>
|
1528
|
-
<p><code>content</code> replaces the content and <code>add_content</code> inserts some, but for actions the insertion is called <code>action</code>.</p>
|
1529
|
-
</li><li>
|
1530
|
-
<p>Every DSL call, in particular nested ones, should be able to insert and/or override a precise call in the parent class. Override behavior should be made consistent across the entire Compony DSL. For instance, it makes no sense that <code>add_content</code> uses an index while <code>action</code> uses <code>before</code> with a keyword.</p>
|
1531
|
-
</li><li>
|
1532
1589
|
<p>Instead of <code>skip_...</code> methods, <code>remove_...</code> should be implemented. This allows yet another level of classes to re-add properties. Skipping should be kept for options given via the constructor.</p>
|
1533
1590
|
</li><li>
|
1534
1591
|
<p>Change resourceful hooks as follows:</p>
|
@@ -1555,7 +1612,7 @@ my_button = Compony.button(:index, :users, enabled: -> { |controller| control
|
|
1555
1612
|
</div></div>
|
1556
1613
|
|
1557
1614
|
<div id="footer">
|
1558
|
-
Generated on Wed
|
1615
|
+
Generated on Wed May 29 15:52:59 2024 by
|
1559
1616
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1560
1617
|
0.9.34 (ruby-3.2.2).
|
1561
1618
|
</div>
|