tramway 0.1.3 → 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 +4 -4
- data/README.md +43 -11
- data/app/components/tailwinds/navbar/button_component.html.haml +2 -1
- data/app/components/tailwinds/navbar/button_component.rb +18 -4
- data/lib/tramway/engine.rb +8 -0
- data/lib/tramway/helpers/tailwind_helpers.rb +21 -0
- data/lib/tramway/version.rb +1 -1
- data/lib/tramway.rb +0 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eedc7b84e9ad80ba5af66fc619af0aea5f24c17e4512e194a6069036ed00f646
|
4
|
+
data.tar.gz: 3e4ac83ede95f1c90e4346f4723551f224efb8921ce1a8802d4977198623441a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43325b31d7a7ca934f39160066dd39653767efd04589e735b1cc2cfaf8ed09c087b9e846816bb97131c11d39e6309d0ef7f9925810159acdb05e3ad77f595aef
|
7
|
+
data.tar.gz: b3da39f4acde834c8897e2ff2853a0c7cfe7cd83d04c0817c30017801010e16d03d5249bb87dd2f98b08b166f1ed594499c71b90fbf1f799b92979363706ab7f
|
data/README.md
CHANGED
@@ -1,28 +1,60 @@
|
|
1
1
|
# Tramway
|
2
|
-
|
3
|
-
|
4
|
-
## Usage
|
5
|
-
How to use my plugin.
|
2
|
+
Unite Ruby on Rails brilliance. Streamline development with Tramway.
|
6
3
|
|
7
4
|
## Installation
|
8
5
|
Add this line to your application's Gemfile:
|
9
6
|
|
10
7
|
```ruby
|
11
8
|
gem "tramway"
|
9
|
+
gem "view_component"
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Tailwind components
|
15
|
+
|
16
|
+
Tramway use [Tailwind](https://tailwindcss.com/) by default. All UI helpers implemented with [ViewComponent](https://github.com/viewcomponent/view_component).
|
17
|
+
|
18
|
+
### Navbar
|
19
|
+
|
20
|
+
#### tailwind_link_to
|
21
|
+
|
22
|
+
Tramway provides `tailwind_link_to` method, that uses `link_to`
|
23
|
+
|
24
|
+
```haml
|
25
|
+
= tailwind_link_to "/users/sign_in" do
|
26
|
+
Sign In
|
12
27
|
```
|
13
28
|
|
14
|
-
|
15
|
-
|
16
|
-
|
29
|
+
OR
|
30
|
+
|
31
|
+
```haml
|
32
|
+
= tailwind_link_to 'Sign In', "/users/sign_in"
|
33
|
+
```
|
34
|
+
|
35
|
+
will render [this](https://play.tailwindcss.com/RT3Vvauu78)
|
36
|
+
|
37
|
+
```haml
|
38
|
+
= tailwind_link_to "/users/sign_out", method: :delete, confirm: 'Wanna quit?' do
|
39
|
+
Sign Out
|
17
40
|
```
|
18
41
|
|
19
|
-
|
20
|
-
|
21
|
-
|
42
|
+
OR
|
43
|
+
|
44
|
+
```
|
45
|
+
= tailwind_link_to 'Sign Out', "/users/sign_out", method: :delete, confirm: 'Wanna quit?'
|
22
46
|
```
|
23
47
|
|
48
|
+
will render [this](https://play.tailwindcss.com/7qPmG4ltEU))
|
49
|
+
|
24
50
|
## Contributing
|
25
|
-
|
51
|
+
|
52
|
+
Install [lefthook](https://github.com/evilmartians/lefthook)
|
53
|
+
|
54
|
+
```
|
55
|
+
bundle
|
56
|
+
lefthook install
|
57
|
+
```
|
26
58
|
|
27
59
|
## License
|
28
60
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1 +1,2 @@
|
|
1
|
-
=
|
1
|
+
= link_to @href, class: @style, **@options do
|
2
|
+
= content
|
@@ -2,12 +2,26 @@
|
|
2
2
|
|
3
3
|
module Tailwinds
|
4
4
|
module Navbar
|
5
|
-
# Render button styled with Tailwind
|
5
|
+
# Render button styled with Tailwind using button_to or link_to methods
|
6
6
|
#
|
7
7
|
class ButtonComponent < TailwindComponent
|
8
|
-
def initialize(
|
9
|
-
@href = href
|
10
|
-
@
|
8
|
+
def initialize(**options)
|
9
|
+
@href = options[:href]
|
10
|
+
@style = 'text-white hover:bg-red-300 px-4 py-2 rounded'
|
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
|
11
25
|
end
|
12
26
|
end
|
13
27
|
end
|
data/lib/tramway/engine.rb
CHANGED
@@ -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
|
data/lib/tramway/version.rb
CHANGED
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: 0.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-
|
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:
|