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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e8751e6e662061508bb687b258c13f3dcb40460344959595a66c998608e38af
4
- data.tar.gz: 66076bba6be9af35c2e787bf43e8e6cb00877bd5f5b53cf4b70ce37a09f78c2b
3
+ metadata.gz: afc672cadc5513d98dce14491b39bc240f08019a61bd19ff795ca9ee2cd4cefd
4
+ data.tar.gz: 10d6bb6bb570855763921365260899b1da88c36a7e0eb102b784331d6e4c2021
5
5
  SHA512:
6
- metadata.gz: aec595653662af5dfe38f8d402dd799d8da2ad77ba8c3e032aba22c56020467f9b4ee1f701a07e7477ecbd34ff7725c32fac18a6a359513e064dbbdc567d703c
7
- data.tar.gz: 5e1799a4d4290ac7bf5e9bd8c1fe524119eb4449ffe0ddeccb3ecf934343160672572c22e834f76a7bebe522d4ca226aa08ce8336ba1f56f88dc53fe692eba72
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 components
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,4 @@
1
+ .mb-4
2
+ %label.inline-block.bg-blue-500.hover:bg-blue-700.text-white.font-bold.py-2.px-4.rounded.cursor-pointer.mt-4{ for: @for }
3
+ = @label
4
+ = @input
@@ -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,4 @@
1
+ .flex.items-center.justify-between
2
+ %button.bg-red-500.hover:bg-red-700.text-white.font-bold.py-2.px-4.rounded.focus:outline-none.focus:shadow-outline{ type: :submit, name: :commit, **@options }
3
+ = @text
4
+ = @content
@@ -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,4 @@
1
+ .mb-4
2
+ %label.block.text-gray-700.text-sm.font-bold.mb-2{ for: @for }
3
+ = @label
4
+ = @input
@@ -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
@@ -65,7 +65,7 @@ module Tramway
65
65
 
66
66
  def __submit(params)
67
67
  self.class.properties.each do |attribute|
68
- public_send("#{attribute}=", params[attribute])
68
+ public_send("#{attribute}=", params[attribute]) if params.keys.include? attribute.to_s
69
69
  end
70
70
  end
71
71
 
@@ -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
 
@@ -4,7 +4,7 @@ require 'tramway/navbar'
4
4
 
5
5
  module Tramway
6
6
  module Helpers
7
- # Providing navbar helpers for ActionView
7
+ # Provides navbar helpers for ActionView
8
8
  module NavbarHelper
9
9
  def tramway_navbar(**options)
10
10
  initialize_navbar
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.3'
4
+ VERSION = '0.3.1.1'
5
5
  end
@@ -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
@@ -6,6 +6,7 @@ require 'tramway/engine'
6
6
  require 'tramway/base_decorator'
7
7
  require 'tramway/base_form'
8
8
  require 'tramway/config'
9
+ require 'tramway/views/form_builder'
9
10
  require 'view_component/compiler'
10
11
  require 'view_component/engine'
11
12
 
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.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-09-04 00:00:00.000000000 Z
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: