tramway 0.3 → 0.3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/app/components/tailwinds/form/builder.rb +34 -0
- data/app/components/tailwinds/form/file_field_component.html.haml +4 -0
- data/app/components/tailwinds/form/file_field_component.rb +14 -0
- data/app/components/tailwinds/form/submit_button_component.html.haml +4 -0
- data/app/components/tailwinds/form/submit_button_component.rb +14 -0
- data/app/components/tailwinds/form/text_field_component.html.haml +4 -0
- data/app/components/tailwinds/form/text_field_component.rb +14 -0
- data/lib/tramway/base_form.rb +1 -1
- data/lib/tramway/engine.rb +6 -0
- data/lib/tramway/helpers/navbar_helper.rb +1 -1
- data/lib/tramway/helpers/views_helper.rb +12 -0
- data/lib/tramway/version.rb +1 -1
- data/lib/tramway/views/form_builder.rb +16 -0
- data/lib/tramway.rb +1 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afc672cadc5513d98dce14491b39bc240f08019a61bd19ff795ca9ee2cd4cefd
|
4
|
+
data.tar.gz: 10d6bb6bb570855763921365260899b1da88c36a7e0eb102b784331d6e4c2021
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a27d64991c18ad3ef69dd1ef660a9b743e4f5e481bfd46dbd9aea4e56651b576d161f932f9eaf5bb249a5e7bcad1c2f6c5bc13b5ad8e6307c3e032a020216058
|
7
|
+
data.tar.gz: 64cf301904e00cb8c0b9504fc6081f8cecc21262426d309e55d8046d6d26887f06e9d3841e82dcd40a8d53fd4f8e0f9b407e40413bdd38fb2931790c770f6777
|
data/README.md
CHANGED
@@ -7,6 +7,7 @@ Unite Ruby on Rails brilliance. Streamline development with Tramway.
|
|
7
7
|
* [Tramway Decorators](https://github.com/Purple-Magic/tramway#tramway-decorators)
|
8
8
|
* [Tramway Form](https://github.com/Purple-Magic/tramway#tramway-form)
|
9
9
|
* [Tramway Navbar](https://github.com/Purple-Magic/tramway#tramway-navbar)
|
10
|
+
* [Tailwind-styled forms](https://github.com/Purple-Magic/tramway#tailwind-styled-forms)
|
10
11
|
|
11
12
|
## Installation
|
12
13
|
Add this line to your application's Gemfile:
|
@@ -312,10 +313,30 @@ tramway_navbar title: 'Purple Magic' do |nav|
|
|
312
313
|
end
|
313
314
|
```
|
314
315
|
|
315
|
-
### Tailwind
|
316
|
+
### Tailwind-styled forms
|
316
317
|
|
317
318
|
Tramway uses [Tailwind](https://tailwindcss.com/) by default. All UI helpers are implemented with [ViewComponent](https://github.com/viewcomponent/view_component).
|
318
319
|
|
320
|
+
#### tramway_form_for
|
321
|
+
|
322
|
+
Tramway provides `tramway_form_for` helper that renders Tailwind-styled forms by default.
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
= tramway_form_for User.new do |f|
|
326
|
+
= f.text_field :text
|
327
|
+
= f.password_field :password
|
328
|
+
= f.file_field :file
|
329
|
+
= f.submit "Create User"
|
330
|
+
```
|
331
|
+
|
332
|
+
will render [this](https://play.tailwindcss.com/xho3LfjKkK)
|
333
|
+
|
334
|
+
Available form helpers:
|
335
|
+
* text_field
|
336
|
+
* password_field
|
337
|
+
* file_field
|
338
|
+
* submit
|
339
|
+
|
319
340
|
## Contributing
|
320
341
|
|
321
342
|
Install [lefthook](https://github.com/evilmartians/lefthook)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tailwinds
|
4
|
+
module Form
|
5
|
+
# Provides Tailwind-styled forms
|
6
|
+
class Builder < Tramway::Views::FormBuilder
|
7
|
+
def text_field(attribute, **options, &)
|
8
|
+
input = super(attribute, **options.merge(class: text_input_class))
|
9
|
+
render(Tailwinds::Form::TextFieldComponent.new(input, attribute, object_name:, **options), &)
|
10
|
+
end
|
11
|
+
|
12
|
+
def password_field(attribute, **options, &)
|
13
|
+
input = super(attribute, **options.merge(class: text_input_class))
|
14
|
+
render(Tailwinds::Form::TextFieldComponent.new(input, attribute, object_name:, **options), &)
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_field(attribute, **options, &)
|
18
|
+
input = super(attribute, **options.merge(class: :hidden))
|
19
|
+
|
20
|
+
render(Tailwinds::Form::FileFieldComponent.new(input, attribute, object_name:, **options), &)
|
21
|
+
end
|
22
|
+
|
23
|
+
def submit(action, **options, &)
|
24
|
+
render(Tailwinds::Form::SubmitButtonComponent.new(action, **options), &)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def text_input_class
|
30
|
+
'w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:border-red-500'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tailwinds
|
4
|
+
module Form
|
5
|
+
# Tailwind-styled file_field input
|
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
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tailwinds
|
4
|
+
module Form
|
5
|
+
# Tailwind-styled submit button
|
6
|
+
class SubmitButtonComponent < TailwindComponent
|
7
|
+
def initialize(action, **options)
|
8
|
+
@options = options.except :type
|
9
|
+
|
10
|
+
@text = action.is_a?(String) ? action : action.to_s.capitalize
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tailwinds
|
4
|
+
module Form
|
5
|
+
# Tailwind-styled text field
|
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
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/tramway/base_form.rb
CHANGED
data/lib/tramway/engine.rb
CHANGED
@@ -13,6 +13,12 @@ module Tramway
|
|
13
13
|
loaded_class.include Tramway::Helpers::NavbarHelper
|
14
14
|
end
|
15
15
|
|
16
|
+
ActiveSupport.on_load(:action_view) do |loaded_class|
|
17
|
+
require 'tramway/helpers/views_helper'
|
18
|
+
|
19
|
+
loaded_class.include Tramway::Helpers::ViewsHelper
|
20
|
+
end
|
21
|
+
|
16
22
|
ActiveSupport.on_load(:action_controller) do |loaded_class|
|
17
23
|
require 'tramway/helpers/decorate_helper'
|
18
24
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tramway
|
4
|
+
module Helpers
|
5
|
+
# Provides view-oriented helpers for ActionView
|
6
|
+
module ViewsHelper
|
7
|
+
def tramway_form_for(object, *args, **options, &)
|
8
|
+
form_for(object, *args, **options.merge(builder: Tailwinds::Form::Builder), &)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/tramway/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tramway
|
4
|
+
module Views
|
5
|
+
# ActionView Form Builder helps us use ViewComponent as form helpers
|
6
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
7
|
+
attr_reader :template
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def render(component, &)
|
12
|
+
component.render_in(template, &)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/tramway.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:
|
4
|
+
version: 0.3.1.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: 2023-
|
12
|
+
date: 2023-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-struct
|
@@ -93,6 +93,13 @@ files:
|
|
93
93
|
- Rakefile
|
94
94
|
- app/components/tailwind_component.html.haml
|
95
95
|
- app/components/tailwind_component.rb
|
96
|
+
- app/components/tailwinds/form/builder.rb
|
97
|
+
- app/components/tailwinds/form/file_field_component.html.haml
|
98
|
+
- app/components/tailwinds/form/file_field_component.rb
|
99
|
+
- app/components/tailwinds/form/submit_button_component.html.haml
|
100
|
+
- app/components/tailwinds/form/submit_button_component.rb
|
101
|
+
- app/components/tailwinds/form/text_field_component.html.haml
|
102
|
+
- app/components/tailwinds/form/text_field_component.rb
|
96
103
|
- app/components/tailwinds/nav/item_component.html.haml
|
97
104
|
- app/components/tailwinds/nav/item_component.rb
|
98
105
|
- app/components/tailwinds/navbar_component.html.haml
|
@@ -113,9 +120,11 @@ files:
|
|
113
120
|
- lib/tramway/helpers/decorate_helper.rb
|
114
121
|
- lib/tramway/helpers/form_helper.rb
|
115
122
|
- lib/tramway/helpers/navbar_helper.rb
|
123
|
+
- lib/tramway/helpers/views_helper.rb
|
116
124
|
- lib/tramway/navbar.rb
|
117
125
|
- lib/tramway/utils/render.rb
|
118
126
|
- lib/tramway/version.rb
|
127
|
+
- lib/tramway/views/form_builder.rb
|
119
128
|
- lib/types.rb
|
120
129
|
homepage: https://github.com/purple-magic/tramway
|
121
130
|
licenses:
|