tramway 0.1.3.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -12
- data/app/components/tailwinds/nav/item_component.html.haml +3 -0
- data/app/components/tailwinds/nav/item_component.rb +28 -0
- data/app/components/tailwinds/navbar_component.html.haml +15 -0
- data/app/components/tailwinds/navbar_component.rb +13 -0
- data/lib/tramway/engine.rb +8 -0
- data/lib/tramway/helpers/navbar_helper.rb +24 -0
- data/lib/tramway/navbar.rb +48 -0
- data/lib/tramway/version.rb +1 -1
- data/lib/tramway.rb +0 -1
- metadata +8 -4
- data/app/components/tailwinds/navbar/button_component.html.haml +0 -6
- data/app/components/tailwinds/navbar/button_component.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 711582391b4cec7b6f8c8808a9d20a1c9695825e94e292073fe85e15d066f11c
|
4
|
+
data.tar.gz: 178c09a9c02feaf8f02094849cbe9fd8756a6f1806419eee369bb1ae0df023b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d37dcea2ec474996c0a261b0b9d7e3619337f0fc3443f75608633c4c4c1ed08be7a367d79ce8b4c7db33695cfaa18e4052458f78ebbff3d13bc89e9e319418
|
7
|
+
data.tar.gz: 0a10282ff924f4adfd5c892852ed0943a23f3374c1ded44c59344854cdd43034549cd39a2eafd2b8e4af6d5dd60abd06c2cb247ab1a2e70f01b8bc8aba3076f0
|
data/README.md
CHANGED
@@ -17,23 +17,55 @@ Tramway use [Tailwind](https://tailwindcss.com/) by default. All UI helpers impl
|
|
17
17
|
|
18
18
|
### Navbar
|
19
19
|
|
20
|
-
|
20
|
+
Tramway provides DSL for rendering Tailwind Navgiation bar.
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
```ruby
|
23
|
+
tramway_navbar title: 'Purple Magic' do |nav|
|
24
|
+
nav.left do
|
25
|
+
nav.item 'Users', '/users'
|
26
|
+
nav.item 'Podcasts', '/podcasts'
|
27
|
+
end
|
28
|
+
|
29
|
+
nav.right do
|
30
|
+
nav.item 'Sign out', '/users/sessions', method: :delete, confirm: 'Wanna quit?'
|
31
|
+
end
|
32
|
+
end
|
27
33
|
```
|
28
34
|
|
29
|
-
will render [this](https://play.tailwindcss.com/
|
35
|
+
will render [this](https://play.tailwindcss.com/UZPTCudFw5)
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
```
|
37
|
+
#### nav.left and nav.right
|
38
|
+
|
39
|
+
Tramway navbar provides `left` and `right` methods that puts items to left and right part of navbar.
|
35
40
|
|
36
|
-
|
41
|
+
#### nav.item
|
42
|
+
|
43
|
+
Item in navigation is rendered `li a` inside navbar `ul` tag on the left or right sides. `nav.item` uses the same approach as `link_to` method with syntax sugar.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
tramway_navbar title: 'Purple Magic' do |nav|
|
47
|
+
nav.left do
|
48
|
+
nav.item 'Users', '/users'
|
49
|
+
|
50
|
+
# NOTE you can achieve the same with
|
51
|
+
|
52
|
+
nav.item '/users' do
|
53
|
+
'Users'
|
54
|
+
end
|
55
|
+
|
56
|
+
# NOTE nav.item supports turbo-method and turbo-confirm attributes
|
57
|
+
|
58
|
+
nav.item 'Delete user', '/users/destroy', method: :delete, confirm: 'Are you sure?'
|
59
|
+
|
60
|
+
# will render this
|
61
|
+
# <li>
|
62
|
+
# <a data-turbo-method="delete" data-turbo-confirm="Are you sure?" href="/users/sign_out" class="text-white hover:bg-red-300 px-4 py-2 rounded">
|
63
|
+
# Sign out
|
64
|
+
# </a>
|
65
|
+
# </li>
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
37
69
|
|
38
70
|
## Contributing
|
39
71
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tailwinds
|
4
|
+
module Nav
|
5
|
+
# Render button styled with Tailwind using button_to or link_to methods
|
6
|
+
#
|
7
|
+
class ItemComponent < TailwindComponent
|
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
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%nav.bg-red-500.py-4.px-8.flex.justify-between.items-center
|
2
|
+
- if @title.present? || @left_items.present?
|
3
|
+
.flex
|
4
|
+
- if @title.present?
|
5
|
+
.text-xl.text-white.font-bold
|
6
|
+
= @title
|
7
|
+
- if @left_items.present?
|
8
|
+
%ul.flex.items-center.space-x-4
|
9
|
+
- @left_items.each do |item|
|
10
|
+
= item
|
11
|
+
|
12
|
+
- if @right_items.present?
|
13
|
+
%ul.flex.items-center.space-x-4
|
14
|
+
- @right_items.each do |item|
|
15
|
+
= item
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tailwinds
|
4
|
+
# Navbar class main class
|
5
|
+
#
|
6
|
+
class NavbarComponent < TailwindComponent
|
7
|
+
def initialize(**options)
|
8
|
+
@title = options[:title]
|
9
|
+
@left_items = options[:left_items]
|
10
|
+
@right_items = options[:right_items]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
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/navbar_helper'
|
12
|
+
|
13
|
+
ActionView::Base.include Tramway::Helpers::NavbarHelper
|
14
|
+
end
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tramway/navbar'
|
4
|
+
|
5
|
+
module Tramway
|
6
|
+
module Helpers
|
7
|
+
# Providing navbar helpers for ActionView
|
8
|
+
#
|
9
|
+
module NavbarHelper
|
10
|
+
def tramway_navbar(**options)
|
11
|
+
if block_given?
|
12
|
+
@navbar = Tramway::Navbar.new self
|
13
|
+
|
14
|
+
yield @navbar
|
15
|
+
|
16
|
+
options[:left_items] = @navbar.items[:left]
|
17
|
+
options[:right_items] = @navbar.items[:right]
|
18
|
+
end
|
19
|
+
|
20
|
+
render(Tailwinds::NavbarComponent.new(**options))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tramway
|
4
|
+
# Navbar class for Tramway navbars
|
5
|
+
#
|
6
|
+
class Navbar
|
7
|
+
attr_reader :items
|
8
|
+
|
9
|
+
def initialize(context)
|
10
|
+
@items = {}
|
11
|
+
@context = context
|
12
|
+
end
|
13
|
+
|
14
|
+
def left
|
15
|
+
return unless block_given?
|
16
|
+
|
17
|
+
@items[:left] = []
|
18
|
+
|
19
|
+
@filling = :left
|
20
|
+
|
21
|
+
yield self
|
22
|
+
end
|
23
|
+
|
24
|
+
def right
|
25
|
+
return unless block_given?
|
26
|
+
|
27
|
+
@items[:right] = []
|
28
|
+
|
29
|
+
@filling = :right
|
30
|
+
|
31
|
+
yield self
|
32
|
+
end
|
33
|
+
|
34
|
+
def item(text_or_url, url = nil, **options, &block)
|
35
|
+
raise 'You can not provide argument and code block in the same time' if url.present? && block_given?
|
36
|
+
|
37
|
+
rendered_item = if url.present?
|
38
|
+
options.merge! href: url
|
39
|
+
@context.render(Tailwinds::Nav::ItemComponent.new(**options)) { text_or_url }
|
40
|
+
else
|
41
|
+
options.merge! href: text_or_url
|
42
|
+
@context.render(Tailwinds::Nav::ItemComponent.new(**options), &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
@items[@filling] << rendered_item
|
46
|
+
end
|
47
|
+
end
|
48
|
+
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.5
|
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-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: haml-rails
|
@@ -79,12 +79,16 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- app/components/tailwind_component.html.haml
|
81
81
|
- app/components/tailwind_component.rb
|
82
|
-
- app/components/tailwinds/
|
83
|
-
- app/components/tailwinds/
|
82
|
+
- app/components/tailwinds/nav/item_component.html.haml
|
83
|
+
- app/components/tailwinds/nav/item_component.rb
|
84
|
+
- app/components/tailwinds/navbar_component.html.haml
|
85
|
+
- app/components/tailwinds/navbar_component.rb
|
84
86
|
- config/routes.rb
|
85
87
|
- lib/tasks/tramway_tasks.rake
|
86
88
|
- lib/tramway.rb
|
87
89
|
- lib/tramway/engine.rb
|
90
|
+
- lib/tramway/helpers/navbar_helper.rb
|
91
|
+
- lib/tramway/navbar.rb
|
88
92
|
- lib/tramway/version.rb
|
89
93
|
homepage: https://github.com/purple-magic/tramway
|
90
94
|
licenses:
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tailwinds
|
4
|
-
module Navbar
|
5
|
-
# Render button styled with Tailwind using button_to or link_to methods
|
6
|
-
#
|
7
|
-
class ButtonComponent < TailwindComponent
|
8
|
-
def initialize(**options)
|
9
|
-
if options[:action].present?
|
10
|
-
@action = options[:action]
|
11
|
-
else
|
12
|
-
@href = options[:href]
|
13
|
-
end
|
14
|
-
|
15
|
-
@style = 'text-white hover:bg-red-300 px-4 py-2 rounded'
|
16
|
-
@options = options.except(:action, :href)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|