tramway 0.1.3.1 → 0.1.4

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: 0c47949a76aef2c3d5dc7e663bb34012b3450fbbe6f699e4ca7e9d0d98a9613f
4
- data.tar.gz: 1bbed346affab3a710234b4848af549200ae94cb1f3d05f97b3c7bd3acd63dcf
3
+ metadata.gz: eedc7b84e9ad80ba5af66fc619af0aea5f24c17e4512e194a6069036ed00f646
4
+ data.tar.gz: 3e4ac83ede95f1c90e4346f4723551f224efb8921ce1a8802d4977198623441a
5
5
  SHA512:
6
- metadata.gz: 7119b80a25ff0a302a3b8fd36b10877ce9f256952faf784d88097e7c0862e770f88eb948e909efc6a431ce273817f3847e17296211946bdfd95113984770658b
7
- data.tar.gz: 8fc6359c32257287ee3ae2383dfb502d6ed8415a15c1b6e977bbfed087cf4f1352316a2afb2db4657930a3ff4f75cc114a973b1b00bf5ef8c82db18dea833b14
6
+ metadata.gz: 43325b31d7a7ca934f39160066dd39653767efd04589e735b1cc2cfaf8ed09c087b9e846816bb97131c11d39e6309d0ef7f9925810159acdb05e3ad77f595aef
7
+ data.tar.gz: b3da39f4acde834c8897e2ff2853a0c7cfe7cd83d04c0817c30017801010e16d03d5249bb87dd2f98b08b166f1ed594499c71b90fbf1f799b92979363706ab7f
data/README.md CHANGED
@@ -17,23 +17,35 @@ Tramway use [Tailwind](https://tailwindcss.com/) by default. All UI helpers impl
17
17
 
18
18
  ### Navbar
19
19
 
20
- #### Button
20
+ #### tailwind_link_to
21
21
 
22
- Tramway provides `Tailwinds::Navbar::ButtonComponent`, that uses `button_to` or `link_to`
22
+ Tramway provides `tailwind_link_to` method, that uses `link_to`
23
23
 
24
24
  ```haml
25
- = render(Tailwinds::Navbar::ButtonComponent.new(href: "/users/sign_in")) do
25
+ = tailwind_link_to "/users/sign_in" do
26
26
  Sign In
27
27
  ```
28
28
 
29
+ OR
30
+
31
+ ```haml
32
+ = tailwind_link_to 'Sign In', "/users/sign_in"
33
+ ```
34
+
29
35
  will render [this](https://play.tailwindcss.com/RT3Vvauu78)
30
36
 
31
37
  ```haml
32
- = render(Tailwinds::Navbar::ButtonComponent.new(action: "/users/sign_out", method: :delete)) do
38
+ = tailwind_link_to "/users/sign_out", method: :delete, confirm: 'Wanna quit?' do
33
39
  Sign Out
34
40
  ```
35
41
 
36
- will render [this](https://play.tailwindcss.com/pJ8450tV21)
42
+ OR
43
+
44
+ ```
45
+ = tailwind_link_to 'Sign Out', "/users/sign_out", method: :delete, confirm: 'Wanna quit?'
46
+ ```
47
+
48
+ will render [this](https://play.tailwindcss.com/7qPmG4ltEU))
37
49
 
38
50
  ## Contributing
39
51
 
@@ -1,6 +1,2 @@
1
- - if @action.present?
2
- = button_to @action, class: @style, **@options do
3
- = content
4
- - else
5
- = link_to @href, class: @style, **@options do
6
- = content
1
+ = link_to @href, class: @style, **@options do
2
+ = content
@@ -6,14 +6,22 @@ module Tailwinds
6
6
  #
7
7
  class ButtonComponent < TailwindComponent
8
8
  def initialize(**options)
9
- if options[:action].present?
10
- @action = options[:action]
11
- else
12
- @href = options[:href]
13
- end
14
-
9
+ @href = options[:href]
15
10
  @style = 'text-white hover:bg-red-300 px-4 py-2 rounded'
16
- @options = options.except(:action, :href)
11
+ @options = prepare(options:)
12
+ end
13
+
14
+ private
15
+
16
+ def prepare(options:)
17
+ options.reduce({}) do |hash, (key, value)|
18
+ case key
19
+ when :method, :confirm
20
+ hash.deep_merge data: { "turbo_#{key}".to_sym => value }
21
+ else
22
+ hash.merge key => value
23
+ end
24
+ end
17
25
  end
18
26
  end
19
27
  end
@@ -5,5 +5,13 @@ module Tramway
5
5
  #
6
6
  class Engine < ::Rails::Engine
7
7
  isolate_namespace Tramway
8
+
9
+ initializer 'tramway.load_helpers' do
10
+ ActiveSupport.on_load(:action_view) do
11
+ require 'tramway/helpers/tailwind_helpers'
12
+
13
+ ActionView::Base.include Tramway::Helpers::TailwindHelpers
14
+ end
15
+ end
8
16
  end
9
17
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway
4
+ module Helpers
5
+ # ActionView helpers for tailwind
6
+ #
7
+ module TailwindHelpers
8
+ def tailwind_link_to(text_or_url, url = nil, **options, &block)
9
+ raise 'You can not provide argument and code block in the same time' if url.present? && block_given?
10
+
11
+ if url.present?
12
+ options.merge! href: url
13
+ render(Tailwinds::Navbar::ButtonComponent.new(**options)) { text_or_url }
14
+ else
15
+ options.merge! href: text_or_url
16
+ render(Tailwinds::Navbar::ButtonComponent.new(**options), &block)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.1.3.1'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/tramway.rb CHANGED
@@ -7,5 +7,4 @@ require 'view_component/engine'
7
7
 
8
8
  # Core module for the whole gem
9
9
  module Tramway
10
- # Your code goes here...
11
10
  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.1.3.1
4
+ version: 0.1.4
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-06-04 00:00:00.000000000 Z
12
+ date: 2023-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml-rails
@@ -85,6 +85,7 @@ files:
85
85
  - lib/tasks/tramway_tasks.rake
86
86
  - lib/tramway.rb
87
87
  - lib/tramway/engine.rb
88
+ - lib/tramway/helpers/tailwind_helpers.rb
88
89
  - lib/tramway/version.rb
89
90
  homepage: https://github.com/purple-magic/tramway
90
91
  licenses: