tramway 0.3.1.1 → 0.3.2
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/README.md +26 -1
- data/app/components/tailwind_component.rb +8 -0
- data/app/components/tailwinds/form/builder.rb +25 -8
- data/app/components/tailwinds/form/file_field_component.html.haml +1 -1
- data/app/components/tailwinds/form/file_field_component.rb +0 -5
- data/app/components/tailwinds/form/select_component.html.haml +4 -0
- data/app/components/tailwinds/form/select_component.rb +10 -0
- data/app/components/tailwinds/form/text_field_component.html.haml +1 -1
- data/app/components/tailwinds/form/text_field_component.rb +0 -5
- data/lib/tramway/base_decorator.rb +3 -0
- data/lib/tramway/base_form.rb +2 -0
- data/lib/tramway/decorators/collection_decorator.rb +1 -1
- data/lib/tramway/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc95797d7be71f61b7a8350b3ef71905d41c8281d3a134feefc4e8477b910b44
|
|
4
|
+
data.tar.gz: 9fc4aa0e0bbec968e96620532082142b3ad48ab701e97ab52c2bd05a8236c047
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef921bd83394ebde2404a8e5e1b7332af573713553ed73676850955ff8e32f9fc93cdddfa0124658ad40c096557fcd60ed420a55d252f5e5c3fb40ea34cae19e
|
|
7
|
+
data.tar.gz: d0a2b72e6e35ea9a297a9af346e794cf1833e8b5922c2e09d98a5f8f06a2d283db49b33753510535a0594365b072aff666712ee50a0b2c9d6036aa530ab52e38
|
data/README.md
CHANGED
|
@@ -81,7 +81,7 @@ class UserDecorator < Tramway::BaseDecorator
|
|
|
81
81
|
end
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
#### Decorate single object
|
|
84
|
+
#### Decorate a single object
|
|
85
85
|
|
|
86
86
|
You can use the same method to decorate a single object either
|
|
87
87
|
|
|
@@ -91,6 +91,20 @@ def show
|
|
|
91
91
|
end
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
#### Decorate a collection of objects
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
def index
|
|
98
|
+
@users = tramway_decorate User.all
|
|
99
|
+
end
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
def index
|
|
104
|
+
@posts = tramway_decorate user.posts
|
|
105
|
+
end
|
|
106
|
+
```
|
|
107
|
+
|
|
94
108
|
#### Decorate with a specific decorator
|
|
95
109
|
|
|
96
110
|
You can implement a specific decorator and ask Tramway to decorate with it
|
|
@@ -101,6 +115,15 @@ def show
|
|
|
101
115
|
end
|
|
102
116
|
```
|
|
103
117
|
|
|
118
|
+
#### Decorate nil
|
|
119
|
+
|
|
120
|
+
Tramway Decorator does not decorate nil objects
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
user = nil
|
|
124
|
+
UserDecorator.decorate user # => nil
|
|
125
|
+
```
|
|
126
|
+
|
|
104
127
|
### Tramway Form
|
|
105
128
|
|
|
106
129
|
Tramway provides **convenient** form objects for Rails applications. List properties you want to change and the rules in Form classes. No controllers overloading.
|
|
@@ -325,6 +348,7 @@ Tramway provides `tramway_form_for` helper that renders Tailwind-styled forms by
|
|
|
325
348
|
= tramway_form_for User.new do |f|
|
|
326
349
|
= f.text_field :text
|
|
327
350
|
= f.password_field :password
|
|
351
|
+
= f.select :role, [:admin, :user]
|
|
328
352
|
= f.file_field :file
|
|
329
353
|
= f.submit "Create User"
|
|
330
354
|
```
|
|
@@ -335,6 +359,7 @@ Available form helpers:
|
|
|
335
359
|
* text_field
|
|
336
360
|
* password_field
|
|
337
361
|
* file_field
|
|
362
|
+
* select
|
|
338
363
|
* submit
|
|
339
364
|
|
|
340
365
|
## Contributing
|
|
@@ -4,4 +4,12 @@ require 'view_component'
|
|
|
4
4
|
|
|
5
5
|
# Base TailwindComponent. Contains base features for all tailwind components
|
|
6
6
|
class TailwindComponent < ViewComponent::Base
|
|
7
|
+
extend Dry::Initializer[undefined: false]
|
|
8
|
+
|
|
9
|
+
option :template
|
|
10
|
+
option :attribute
|
|
11
|
+
option :object_name
|
|
12
|
+
option :options
|
|
13
|
+
option :label
|
|
14
|
+
option :for
|
|
7
15
|
end
|
|
@@ -3,21 +3,22 @@
|
|
|
3
3
|
module Tailwinds
|
|
4
4
|
module Form
|
|
5
5
|
# Provides Tailwind-styled forms
|
|
6
|
+
# :reek:InstanceVariableAssumption
|
|
6
7
|
class Builder < Tramway::Views::FormBuilder
|
|
7
8
|
def text_field(attribute, **options, &)
|
|
8
|
-
|
|
9
|
-
render(Tailwinds::Form::TextFieldComponent.new(input, attribute, object_name:, **options), &)
|
|
9
|
+
render(Tailwinds::Form::TextFieldComponent.new(**default_options(attribute, options)), &)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def password_field(attribute, **options, &)
|
|
13
|
-
|
|
14
|
-
render(Tailwinds::Form::TextFieldComponent.new(input, attribute, object_name:, **options), &)
|
|
13
|
+
render(Tailwinds::Form::TextFieldComponent.new(**default_options(attribute, options)), &)
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def file_field(attribute, **options, &)
|
|
18
|
-
|
|
17
|
+
render(Tailwinds::Form::FileFieldComponent.new(**default_options(attribute, options)), &)
|
|
18
|
+
end
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
def select(attribute, collection, **options, &)
|
|
21
|
+
render(Tailwinds::Form::SelectComponent.new(**default_options(attribute, options).merge(collection:)), &)
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def submit(action, **options, &)
|
|
@@ -26,8 +27,24 @@ module Tailwinds
|
|
|
26
27
|
|
|
27
28
|
private
|
|
28
29
|
|
|
29
|
-
def
|
|
30
|
-
|
|
30
|
+
def default_options(attribute, options)
|
|
31
|
+
{
|
|
32
|
+
template: @template,
|
|
33
|
+
attribute:,
|
|
34
|
+
object_name:,
|
|
35
|
+
label: label(attribute, options),
|
|
36
|
+
for: for_id(attribute),
|
|
37
|
+
options:
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# :reek:UtilityFunction
|
|
42
|
+
def label(attribute, options)
|
|
43
|
+
options[:label] || attribute.to_s.humanize
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def for_id(attribute)
|
|
47
|
+
"#{object_name}_#{attribute}"
|
|
31
48
|
end
|
|
32
49
|
end
|
|
33
50
|
end
|
|
@@ -4,11 +4,6 @@ module Tailwinds
|
|
|
4
4
|
module Form
|
|
5
5
|
# Tailwind-styled file_field input
|
|
6
6
|
class FileFieldComponent < TailwindComponent
|
|
7
|
-
def initialize(input, attribute, object_name: nil, **options)
|
|
8
|
-
@label = options[:label] || attribute.to_s.capitalize
|
|
9
|
-
@for = "#{object_name}_#{attribute}"
|
|
10
|
-
@input = input
|
|
11
|
-
end
|
|
12
7
|
end
|
|
13
8
|
end
|
|
14
9
|
end
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
.mb-4
|
|
2
|
+
%label.block.text-gray-700.text-sm.font-bold.mb-2{ for: @for }
|
|
3
|
+
= @label
|
|
4
|
+
= @template.select @object_name, @attribute, @collection, {}, @options.merge(class: 'bg-white border border-gray-300 text-gray-700 py-2 px-2 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent')
|
|
@@ -4,11 +4,6 @@ module Tailwinds
|
|
|
4
4
|
module Form
|
|
5
5
|
# Tailwind-styled text field
|
|
6
6
|
class TextFieldComponent < TailwindComponent
|
|
7
|
-
def initialize(input, attribute, object_name: nil, **options)
|
|
8
|
-
@label = options[:label] || attribute.to_s.humanize
|
|
9
|
-
@for = "#{object_name}_#{attribute}"
|
|
10
|
-
@input = input
|
|
11
|
-
end
|
|
12
7
|
end
|
|
13
8
|
end
|
|
14
9
|
end
|
|
@@ -17,7 +17,10 @@ module Tramway
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
class << self
|
|
20
|
+
# :reek:NilCheck { enabled: false } because checking for nil is not a type-checking issue but business logic
|
|
20
21
|
def decorate(object_or_array)
|
|
22
|
+
return if object_or_array.nil?
|
|
23
|
+
|
|
21
24
|
if Tramway::Decorators::CollectionDecorators.collection?(object_or_array)
|
|
22
25
|
Tramway::Decorators::CollectionDecorators.decorate_collection(
|
|
23
26
|
collection: object_or_array,
|
data/lib/tramway/base_form.rb
CHANGED
data/lib/tramway/version.rb
CHANGED
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.3.
|
|
4
|
+
version: 0.3.2
|
|
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:
|
|
12
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: dry-struct
|
|
@@ -96,6 +96,8 @@ files:
|
|
|
96
96
|
- app/components/tailwinds/form/builder.rb
|
|
97
97
|
- app/components/tailwinds/form/file_field_component.html.haml
|
|
98
98
|
- app/components/tailwinds/form/file_field_component.rb
|
|
99
|
+
- app/components/tailwinds/form/select_component.html.haml
|
|
100
|
+
- app/components/tailwinds/form/select_component.rb
|
|
99
101
|
- app/components/tailwinds/form/submit_button_component.html.haml
|
|
100
102
|
- app/components/tailwinds/form/submit_button_component.rb
|
|
101
103
|
- app/components/tailwinds/form/text_field_component.html.haml
|