tramway 0.6 → 0.6.0.1

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: ff761d41cd4748bf3d7e1451825da24764f69077b842e92f7be6baf0f14dff55
4
- data.tar.gz: d9c3b25519ab3eb4dfe9c7d2e26d8dffb339a2743b6c5c494495bd4c5b71fc6c
3
+ metadata.gz: a7d9322ff7e374d37c137d366bec17c0728b350eccf87b146655d7704f1e560d
4
+ data.tar.gz: 045e0e118d1269095a241ce783ffb08bc282b8e885570341ad57878e4e0e1ac4
5
5
  SHA512:
6
- metadata.gz: bb0c9c5121dc9a8213a0011c07265b2c42a486218966725df559c31f48b1f1e0cbbb50dc7fd10ddaac13f00a14d55ae57be42e121a1c1d44b1560822425f54af
7
- data.tar.gz: 4488ab5046c8fee6150ee80459df3859f0a2d8b62948cfb91af93052dce2f0788aa067dde8261c9df0708ad31c853c522adc65c91c907cc71b4418c17bfc4244
6
+ metadata.gz: 4d4594294bf08a6822a7b4a4d0bb8d777fdaed41fe0024d3fa29a5741c4c46c63ea921ea7c1742888502c42b5195e7198a23e4a80e8dc4216557e40da1e20953
7
+ data.tar.gz: e2e6f019d9e2b19e8fa32f6d3740c2a32473b9e070845b04756e20e53eb2abb9f51b37dd2aa721bbad98a557e90f55eb32054ed36f1a014056be4dfa8d3018a9
data/README.md CHANGED
@@ -133,13 +133,30 @@ Tramway Entity supports several options that are used in different features.
133
133
  ```ruby
134
134
  Tramway.configure do |config|
135
135
  config.entities = [
136
- { name: :user, route: { namespace: :admin } }, # `admin_users_path` link in the Tramway Navbar
137
- { name: :podcast, route: { route_method: :shows } }, # `shows_path` link in the Tramway Navbar
138
- { name: :episodes, route: { namespace: :podcasts, route_method: :episodes } }, # `podcasts_episodes_path` link in the Tramway Navbar
136
+ {
137
+ name: :user,
138
+ route: { namespace: :admin }
139
+ }, # `/admin/users` link in the Tramway Navbar
140
+ {
141
+ name: :episodes,
142
+ route: {
143
+ namespace: :podcasts,
144
+ route_method: :episodes
145
+ }
146
+ }, # `/podcasts/episodes` link in the Tramway Navbar
139
147
  ]
140
148
  end
141
149
  ```
142
150
 
151
+ **route_helper**
152
+
153
+ To get routes Tramway generated just Tramway::Engine.
154
+
155
+ ```ruby
156
+ Tramway::Engine.routes.url_helpers.users_path => '/admin/users'
157
+ Tramway::Engine.routes.url_helpers.podcasts_episodes_path => '/podcasts/episodes'
158
+ ```
159
+
143
160
  ### Tramway Decorators
144
161
 
145
162
  Tramway provides convenient decorators for your objects. **NOTE:** This is not the decorator pattern in its usual representation.
@@ -455,15 +472,19 @@ tramway_navbar title: 'Purple Magic', background: { color: :red, intensity: 500
455
472
  end
456
473
  ```
457
474
 
458
- # Haml example
475
+ # ERB example
459
476
 
460
- ```haml
461
- = tramway_navbar title: 'Purple Magic', background: { color: :red, intensity: 500 } do |nav|
462
- - nav.left do
463
- - nav.item 'Users', '/users'
464
- - nav.item 'Podcasts', '/podcasts'
465
- - nav.right do
466
- - nav.item 'Sign out', '/users/sessions', method: :delete, confirm: 'Wanna quit?'
477
+ ```erb
478
+ <%= tramway_navbar title: 'Purple Magic', background: { color: :red, intensity: 500 } do |nav| %>
479
+ <% nav.left do %>
480
+ <%= nav.item 'Users', '/users' %>
481
+ <%= nav.item 'Podcasts', '/podcasts' %>
482
+ <% end %>
483
+
484
+ <% nav.right do %>
485
+ <%= nav.item 'Sign out', '/users/sessions', method: :delete, confirm: 'Wanna quit?' %>
486
+ <% end %>
487
+ <% end %>
467
488
  ```
468
489
 
469
490
  will render [this](https://play.tailwindcss.com/UZPTCudFw5)
@@ -485,13 +506,16 @@ with_entities: Show Tramway Entities index page links to navbar. Default: true
485
506
 
486
507
  In case you want to hide entity links you can pass `with_entities: false`.
487
508
 
488
- ```haml
489
- - if current_user.present?
490
- = tramway_navbar title: 'WaiWai' do |nav|
491
- - nav.left do
492
- - nav.item 'Board', admin_board_path
493
- - else
494
- = tramway_navbar title: 'WaiWai', with_entities: false
509
+ ```erb
510
+ <% if current_user.present? %>
511
+ <%= tramway_navbar title: 'WaiWai' do |nav| %>
512
+ <% nav.left do %>
513
+ <%= nav.item 'Board', admin_board_path %>
514
+ <% end %>
515
+ <% end %>
516
+ <% else %>
517
+ <%= tramway_navbar title: 'WaiWai', with_entities: false %>
518
+ <% end %>
495
519
  ```
496
520
 
497
521
  #### nav.left and nav.right
@@ -529,31 +553,43 @@ end
529
553
 
530
554
  ### Tramway Table Component
531
555
 
532
- Tramway provides a responsive, tailwind-styled table with light and dark themes.
556
+ Tramway provides a responsive, tailwind-styled table with light and dark themes. Use the `tramway_table`, `tramway_row`, and
557
+ `tramway_cell` helpers to build tables with readable ERB templates while still leveraging the underlying ViewComponent
558
+ implementations.
559
+
560
+ ```erb
561
+ <%= tramway_table do %>
562
+ <%= component 'tailwinds/table/header', headers: ['Column 1', 'Column 2'] %>
533
563
 
534
- ```haml
535
- = component 'tailwinds/table' do
536
- = component 'tailwinds/table/header', headers: ['Column 1', 'Column 2']
537
- = component 'tailwinds/table/row' do
538
- = component 'tailwinds/table/cell' do
564
+ <%= tramway_row do %>
565
+ <%= tramway_cell do %>
539
566
  Something
540
- = component 'tailwinds/table/cell' do
567
+ <% end %>
568
+ <%= tramway_cell do %>
541
569
  Another
570
+ <% end %>
571
+ <% end %>
572
+ <% end %>
542
573
  ```
543
574
 
544
- `Tailwinds::TableComponent` accepts an optional `options` hash that is merged into the outer `.div-table` element. The hash is
545
- forwarded as HTML attributes, so you can pass things like `id`, `data` attributes, or additional classes. If you do not supply
546
- your own width utility (e.g. a class that starts with `w-`), the component automatically appends `w-full` to keep the table
547
- responsive. This allows you to extend the default styling without losing the sensible defaults provided by the component.
575
+ `tramway_table` accepts the same optional `options` hash as `Tailwinds::TableComponent`. The hash is forwarded as HTML
576
+ attributes, so you can pass things like `id`, `data` attributes, or additional classes. If you do not supply your own width
577
+ utility (e.g. a class that starts with `w-`), the component automatically appends `w-full` to keep the table responsive. This
578
+ allows you to extend the default styling without losing the sensible defaults provided by the component.
548
579
 
549
- ```haml
550
- = component 'tailwinds/table', options: { class: 'max-w-3xl border border-gray-200', data: { controller: 'table' } } do
551
- = component 'tailwinds/table/header', headers: ['Name', 'Email']
552
- = component 'tailwinds/table/row' do
553
- = component 'tailwinds/table/cell' do
554
- = user.name
555
- = component 'tailwinds/table/cell' do
556
- = user.email
580
+ ```erb
581
+ <%= tramway_table class: 'max-w-3xl border border-gray-200', data: { controller: 'table' } do %>
582
+ <%= component 'tailwinds/table/header', headers: ['Name', 'Email'] %>
583
+
584
+ <%= tramway_row do %>
585
+ <%= tramway_cell do %>
586
+ <%= user.name %>
587
+ <% end %>
588
+ <%= tramway_cell do %>
589
+ <%= user.email %>
590
+ <% end %>
591
+ <% end %>
592
+ <% end %>
557
593
  ```
558
594
 
559
595
  When you render a header you can either pass the `headers:` array, as in the examples above, or render custom header content in
@@ -561,18 +597,48 @@ the block. `Tailwinds::Table::HeaderComponent` uses the length of the `headers`
561
597
  If you omit the array and provide custom content, pass the `columns:` argument so the component knows how many grid columns to
562
598
  generate.
563
599
 
564
- ```haml
565
- = component 'tailwinds/table/header', columns: 4 do
566
- = component 'tailwinds/table/cell' do
600
+ ```erb
601
+ <%= component 'tailwinds/table/header', columns: 4 do %>
602
+ <%= tramway_cell do %>
567
603
  Custom header cell
568
- = component 'tailwinds/table/cell' do
604
+ <% end %>
605
+ <%= tramway_cell do %>
569
606
  Another header cell
570
- / ...
607
+ <% end %>
608
+ <!-- ... -->
609
+ <% end %>
571
610
  ```
572
611
 
573
612
  With this approach you control the header layout while still benefiting from the default Tailwind grid classes that the header
574
613
  component applies.
575
614
 
615
+ ### Tramway Buttons and Containers
616
+
617
+ Tramway ships with helpers for common UI patterns built on top of Tailwind components.
618
+
619
+ * `tramway_button` renders a button-styled link and accepts `path`, optional `text`, HTTP `method`, and styling options such as
620
+ `color`, `type`, and `size`. All additional keyword arguments are forwarded to the underlying component as HTML attributes.
621
+
622
+ ```erb
623
+ <%= tramway_button path: user_path(user), text: 'View profile', color: :emerald, data: { turbo: false } %>
624
+ ```
625
+
626
+ * `tramway_back_button` renders a standardized "Back" link.
627
+
628
+ ```erb
629
+ <%= tramway_back_button %>
630
+ ```
631
+
632
+ * `tramway_container` wraps content in a responsive, narrow layout container. Pass an `id` if you need to target the container
633
+ with JavaScript or CSS.
634
+
635
+ ```erb
636
+ <%= tramway_container id: 'user-settings' do %>
637
+ <h2 class="text-xl font-semibold">Settings</h2>
638
+ <p class="mt-2 text-gray-600">Update your preferences below.</p>
639
+ <% end %>
640
+ ```
641
+
576
642
  ### Tailwind-styled forms
577
643
 
578
644
  Tramway uses [Tailwind](https://tailwindcss.com/) by default. All UI helpers are implemented with [ViewComponent](https://github.com/viewcomponent/view_component).
@@ -581,15 +647,16 @@ Tramway uses [Tailwind](https://tailwindcss.com/) by default. All UI helpers are
581
647
 
582
648
  Tramway provides `tramway_form_for` helper that renders Tailwind-styled forms by default.
583
649
 
584
- ```ruby
585
- = tramway_form_for @user do |f|
586
- = f.text_field :text
587
- = f.email_field :email
588
- = f.password_field :password
589
- = f.select :role, [:admin, :user]
590
- = f.multiselect :permissions, [['Create User', 'create_user'], ['Update user', 'update_user']]
591
- = f.file_field :file
592
- = f.submit "Create User"
650
+ ```erb
651
+ <%= tramway_form_for @user do |f| %>
652
+ <%= f.text_field :text %>
653
+ <%= f.email_field :email %>
654
+ <%= f.password_field :password %>
655
+ <%= f.select :role, [:admin, :user] %>
656
+ <%= f.multiselect :permissions, [['Create User', 'create_user'], ['Update user', 'update_user']] %>
657
+ <%= f.file_field :file %>
658
+ <%= f.submit 'Create User' %>
659
+ <% end %>
593
660
  ```
594
661
 
595
662
  will render [this](https://play.tailwindcss.com/xho3LfjKkK)
@@ -607,25 +674,27 @@ Available form helpers:
607
674
 
608
675
  1. Sign In Form for `devise` authentication
609
676
 
610
- *app/views/devise/sessions/new.html.haml*
611
- ```haml
612
- = tramway_form_for(resource, as: resource_name, url: session_path(resource_name), class: 'bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4') do |f|
613
- = component 'forms/errors', record: resource
677
+ *app/views/devise/sessions/new.html.erb*
678
+ ```erb
679
+ <%= tramway_form_for(resource, as: resource_name, url: session_path(resource_name), class: 'bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4') do |f| %>
680
+ <%= component 'forms/errors', record: resource %>
614
681
 
615
- = f.text_field :email, placeholder: "Your email"
616
- = f.password_field :password, placeholder: "Your password"
682
+ <%= f.text_field :email, placeholder: 'Your email' %>
683
+ <%= f.password_field :password, placeholder: 'Your password' %>
617
684
 
618
- = f.submit "Sign In"
685
+ <%= f.submit 'Sign In' %>
686
+ <% end %>
619
687
  ```
620
688
 
621
689
  2. Sign In Form for Rails authorization
622
690
 
623
- *app/views/sessions/new.html.haml*
624
- ```haml
625
- = form_with url: login_path, scope: :session, local: true, builder: Tailwinds::Form::Builder do |form|
626
- = form.email_field :email
627
- = form.password_field :password
628
- = form.submit "Log in"
691
+ *app/views/sessions/new.html.erb*
692
+ ```erb
693
+ <%= form_with url: login_path, scope: :session, local: true, builder: Tailwinds::Form::Builder do |form| %>
694
+ <%= form.email_field :email %>
695
+ <%= form.password_field :password %>
696
+ <%= form.submit 'Log in' %>
697
+ <% end %>
629
698
  ```
630
699
 
631
700
  #### Stimulus-based inputs
@@ -636,10 +705,11 @@ Available form helpers:
636
705
 
637
706
  In case you want to use tailwind-styled multiselect this way
638
707
 
639
- ```haml
640
- = tramway_form_for @user do |f|
641
- = f.multiselect :permissions, [['Create User', 'create_user'], ['Update user', 'update_user']]
642
- #- ...
708
+ ```erb
709
+ <%= tramway_form_for @user do |f| %>
710
+ <%= f.multiselect :permissions, [['Create User', 'create_user'], ['Update user', 'update_user']] %>
711
+ <%# ... %>
712
+ <% end %>
643
713
  ```
644
714
 
645
715
  you should add Tramway Multiselect Stimulus controller to your application.
@@ -663,9 +733,10 @@ application.register('multiselect', Multiselect) // register Multiselect control
663
733
 
664
734
  Use Stimulus `change` action with Tramway Multiselect
665
735
 
666
- ```ruby
667
- = tramway_form_for @user do |f|
668
- = f.multiselect :role, data: { action: 'change->user-form#updateForm' } # user-form is your Stimulus controller, updateForm is a method inside user-form Stimulus controller
736
+ ```erb
737
+ <%= tramway_form_for @user do |f| %>
738
+ <%= f.multiselect :role, data: { action: 'change->user-form#updateForm' } %>
739
+ <% end %>
669
740
  ```
670
741
 
671
742
  ### Tailwind-styled pagination for Kaminari
@@ -687,9 +758,9 @@ Tramway.configure do |config|
687
758
  end
688
759
  ```
689
760
 
690
- *app/views/users/index.html.haml*
691
- ```haml
692
- = paginate @users # it will render tailwind-styled pagination buttons by default
761
+ *app/views/users/index.html.erb*
762
+ ```erb
763
+ <%= paginate @users %> <%# it will render tailwind-styled pagination buttons by default %>
693
764
  ```
694
765
 
695
766
  Pagination buttons looks like [this](https://play.tailwindcss.com/mqgDS5l9oY)
@@ -710,11 +781,41 @@ user_2 = tramway_form User.first
710
781
  user_2.object #=> returns pure user object
711
782
  ```
712
783
 
784
+ ## Configuration
785
+
786
+ ### Custom layout
787
+
788
+ In case you wanna use a custom layout:
789
+
790
+ 1. Create a controller
791
+ 2. Set the layout there
792
+ 3. Set this controller as `application_controller` in Tramway initializer
793
+ 4. Reload your server
794
+
795
+ **Example**
796
+
797
+ *app/controllers/admin/application_controller.rb*
798
+ ```ruby
799
+ class Admin::ApplicationController < ApplicationController
800
+ layout 'admin/application'
801
+ end
802
+ ```
803
+
804
+ *config/initializers/tramway.rb*
805
+ ```ruby
806
+ Tramway.configure do |config|
807
+ config.application_controller = 'Admin::ApplicationController'
808
+ end
809
+ ```
810
+
713
811
  ## Articles
714
812
  * [Tramway on Rails](https://kalashnikovisme.medium.com/tramway-on-rails-32158c35ed68)
813
+ * [Tramway is the way to deal with little things for Rails developers](https://medium.com/@kalashnikovisme/tramway-is-the-way-to-deal-with-little-things-for-rails-developers-4f502172a18c)
715
814
  * [Delegating ActiveRecord methods to decorators in Rails](https://kalashnikovisme.medium.com/delegating-activerecord-methods-to-decorators-in-rails-4e4ec1c6b3a6)
716
815
  * [Behave as ActiveRecord. Why do we want objects to be AR lookalikes?](https://kalashnikovisme.medium.com/behave-as-activerecord-why-do-we-want-objects-to-be-ar-lookalikes-d494d692e1d3)
717
816
  * [Decorating associations in Rails with Tramway](https://kalashnikovisme.medium.com/decorating-associations-in-rails-with-tramway-b46a28392f9e)
817
+ * [Easy-to-use Tailwind-styled multi-select built with Stimulus](https://medium.com/@kalashnikovisme/easy-to-use-tailwind-styled-multi-select-built-with-stimulus-b3daa9e307aa)
818
+ *
718
819
 
719
820
  ## Contributing
720
821
 
@@ -17,12 +17,12 @@
17
17
  %p.text-center.mt-10
18
18
  You should fill class-level method `self.list_attributes` inside your
19
19
  = decorator
20
+ - else
21
+ = component 'tailwinds/table' do
22
+ = component 'tailwinds/table/header', headers: list_attributes.map { |attribute| @model_class.human_attribute_name(attribute) }
23
+ - @entities.each do |item|
24
+ = render 'tramway/entities/entity', entity: item
20
25
 
21
- = component 'tailwinds/table' do
22
- = component 'tailwinds/table/header', headers: list_attributes.map { |attribute| @model_class.human_attribute_name(attribute) }
23
- - @entities.each do |item|
24
- = render 'tramway/entities/entity', entity: item
25
-
26
- - if Tramway.config.pagination[:enabled]
27
- .flex.mt-4
28
- = paginate @entities, custom_path_method: "#{@model_class.model_name.plural}_path"
26
+ - if Tramway.config.pagination[:enabled]
27
+ .flex.mt-4
28
+ = paginate @entities, custom_path_method: "#{@model_class.model_name.plural}_path"
@@ -1 +1,2 @@
1
- = render 'tramway/entities/list'
1
+ = tramway_container do
2
+ = render 'tramway/entities/list'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.6'
4
+ VERSION = '0.6.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: 0.6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kalashnikovisme
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-10-25 00:00:00.000000000 Z
12
+ date: 2025-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anyway_config