tramway 1.0.2 → 1.0.2.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 581bdfc4cccc870402d66738f53acc44cb84782ea875afa0abbe6a6d4adb7717
|
|
4
|
+
data.tar.gz: 236f05a1f96eed1f559b7d9aabe0aae2bb01e58588f54d124ccc879a4ca6fc0f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b1a3f26325a610c59c58781046848ed3457969f5e9f1a0715a35915474549933186b089bd1a0238d16535140f844b891167deaeb7247601a972616c3514eed0
|
|
7
|
+
data.tar.gz: f5f1fe2b2d30bc74be63fd1e0b22f36468bd10e60c7910005db112c713bd397f9fc4bfe7783731da73749cf3333fea449674c01c9899d680c3f88e234047facf
|
data/README.md
CHANGED
|
@@ -244,7 +244,7 @@ class UserDecorator < Tramway::BaseDecorator
|
|
|
244
244
|
|
|
245
245
|
# you can provide representations with ViewComponent to avoid implementing views with Rails Helpers
|
|
246
246
|
def posts_table
|
|
247
|
-
|
|
247
|
+
component 'table', object.posts
|
|
248
248
|
end
|
|
249
249
|
end
|
|
250
250
|
```
|
|
@@ -306,6 +306,32 @@ object-level `show_header_content` method on its decorator. The method
|
|
|
306
306
|
can return any rendered content and has full access to the decorated
|
|
307
307
|
object's helpers and attributes.
|
|
308
308
|
|
|
309
|
+
#### Use `view_context` in show and index pages
|
|
310
|
+
|
|
311
|
+
Some helpers—such as `button_to` with non-`GET` methods—need access to the
|
|
312
|
+
live request context to include CSRF tokens. Pass the Rails `view_context`
|
|
313
|
+
into your decorated objects so their render calls execute inside the
|
|
314
|
+
current request.
|
|
315
|
+
|
|
316
|
+
```ruby
|
|
317
|
+
def show
|
|
318
|
+
@project = tramway_decorate(Project.find(params[:id])).with(view_context:)
|
|
319
|
+
end
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
For index pages, decorate each record with the current context before
|
|
323
|
+
rendering headers or per-row components:
|
|
324
|
+
|
|
325
|
+
```ruby
|
|
326
|
+
def index
|
|
327
|
+
@projects = tramway_decorate(Project.all).map { |project| project.with(view_context:) }
|
|
328
|
+
end
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Passing the context this way ensures `show_header_content` and
|
|
332
|
+
`index_header_content` blocks can safely call helpers that require the
|
|
333
|
+
session-bound authenticity token.
|
|
334
|
+
|
|
309
335
|
#### Decorate a single object
|
|
310
336
|
|
|
311
337
|
You can use the same method to decorate a single object either
|
|
@@ -316,6 +342,11 @@ def show
|
|
|
316
342
|
end
|
|
317
343
|
```
|
|
318
344
|
|
|
345
|
+
All objects returned from `tramway_decorate` respond to
|
|
346
|
+
`with(view_context:)`, so you can attach the current Rails `view_context`
|
|
347
|
+
when you need decorator-rendered content to use helpers that rely on the
|
|
348
|
+
active request (such as CSRF tokens).
|
|
349
|
+
|
|
319
350
|
#### Decorate a collection of objects
|
|
320
351
|
|
|
321
352
|
```ruby
|
|
@@ -698,11 +729,14 @@ attributes, so you can pass things like `id`, `data` attributes, or additional c
|
|
|
698
729
|
utility (e.g. a class that starts with `w-`), the component automatically appends `w-full` to keep the table responsive. This
|
|
699
730
|
allows you to extend the default styling without losing the sensible defaults provided by the component.
|
|
700
731
|
|
|
732
|
+
Use the optional `href:` argument on `tramway_row` to turn an entire row into a link. Linked rows gain pointer and hover styles
|
|
733
|
+
(`cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700`) to indicate interactivity.
|
|
734
|
+
|
|
701
735
|
```erb
|
|
702
736
|
<%= tramway_table class: 'max-w-3xl border border-gray-200', data: { controller: 'table' } do %>
|
|
703
737
|
<%= tramway_header', headers: ['Name', 'Email'] %>
|
|
704
738
|
|
|
705
|
-
<%= tramway_row do %>
|
|
739
|
+
<%= tramway_row href: user_path(user) do %>
|
|
706
740
|
<%= tramway_cell do %>
|
|
707
741
|
<%= user.name %>
|
|
708
742
|
<% end %>
|
|
@@ -738,8 +772,14 @@ component applies.
|
|
|
738
772
|
Tramway ships with helpers for common UI patterns built on top of Tailwind components.
|
|
739
773
|
|
|
740
774
|
* `tramway_button` renders a button-styled form submit by default and accepts `path`, optional `text`, HTTP `method`, and styling
|
|
741
|
-
options such as `color`, `type`, and `size`.
|
|
742
|
-
|
|
775
|
+
options such as `color`, `type`, and `size`. It uses Rails' `button_to` helper by default (or when `link: false` is passed),
|
|
776
|
+
and switches to `link_to` when you set `link: true`.
|
|
777
|
+
|
|
778
|
+
```erb
|
|
779
|
+
<%= tramway_button path: user_path(user), text: 'Open profile', link: true %>
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
All additional keyword arguments are forwarded to the underlying component as HTML attributes.
|
|
743
783
|
|
|
744
784
|
The `type` option maps semantic intent to Tailwind color families. The full set of supported values is:
|
|
745
785
|
|
|
@@ -971,7 +1011,6 @@ end
|
|
|
971
1011
|
* [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)
|
|
972
1012
|
* [Decorating associations in Rails with Tramway](https://kalashnikovisme.medium.com/decorating-associations-in-rails-with-tramway-b46a28392f9e)
|
|
973
1013
|
* [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)
|
|
974
|
-
*
|
|
975
1014
|
|
|
976
1015
|
## Contributing
|
|
977
1016
|
|
|
@@ -23,7 +23,10 @@ module Tramway
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def show
|
|
26
|
-
@entity = tramway_decorate
|
|
26
|
+
@entity = tramway_decorate(
|
|
27
|
+
model_class.find(params[:id]),
|
|
28
|
+
namespace: entity.namespace
|
|
29
|
+
).with(view_context:)
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
private
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
- @show_header_content = @entity.show_header_content
|
|
2
|
-
|
|
3
1
|
= tramway_container do
|
|
4
|
-
|
|
5
2
|
.flex.justify-between.items-center
|
|
6
3
|
%h1.text-4xl.font-bold.mb-4
|
|
7
4
|
= @entity.title
|
|
8
5
|
|
|
9
6
|
.flex.justify-end.mt-2
|
|
10
|
-
- if @show_header_content.present?
|
|
11
|
-
|
|
12
|
-
= @show_header_content.call(@entity)
|
|
13
|
-
- else
|
|
14
|
-
= @show_header_content
|
|
7
|
+
- if @entity.show_header_content.present?
|
|
8
|
+
= @entity.show_header_content
|
|
15
9
|
|
|
16
10
|
- if @entity.show_attributes.empty?
|
|
17
11
|
%p.text-center.mt-10
|
|
18
12
|
You should fill object-level method `show_attributes` inside your
|
|
19
13
|
= @entity.class.name
|
|
14
|
+
|
|
20
15
|
= tramway_table class: 'mt-4' do
|
|
21
16
|
- @entity.show_attributes.each do |attribute|
|
|
22
17
|
= tramway_row do
|
|
@@ -18,12 +18,18 @@ module Tramway
|
|
|
18
18
|
include Tramway::Helpers::DecorateHelper
|
|
19
19
|
include Tramway::Helpers::ComponentHelper
|
|
20
20
|
|
|
21
|
-
attr_reader :object
|
|
21
|
+
attr_reader :object, :view_context
|
|
22
22
|
|
|
23
23
|
def initialize(object)
|
|
24
24
|
@object = object
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def with(view_context:)
|
|
28
|
+
@view_context = view_context
|
|
29
|
+
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
27
33
|
class << self
|
|
28
34
|
include Tramway::Helpers::ComponentHelper
|
|
29
35
|
include Tramway::Utils::Render
|
data/lib/tramway/utils/render.rb
CHANGED
data/lib/tramway/version.rb
CHANGED