tramway 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -19
- data/app/components/tailwinds/nav/item_component.html.haml +3 -0
- data/app/components/tailwinds/{navbar/button_component.rb → nav/item_component.rb} +2 -2
- data/app/components/tailwinds/navbar_component.html.haml +15 -0
- data/app/components/tailwinds/navbar_component.rb +36 -0
- data/lib/tramway/engine.rb +2 -2
- data/lib/tramway/helpers/navbar_helper.rb +24 -0
- data/lib/tramway/navbar.rb +48 -0
- data/lib/tramway/version.rb +1 -1
- metadata +8 -5
- data/app/components/tailwinds/navbar/button_component.html.haml +0 -2
- data/lib/tramway/helpers/tailwind_helpers.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5d6641dda4dedcf7e4d1a4e0638690e21b5f72fbfdccca6c40fa423eec9e3f8
|
4
|
+
data.tar.gz: c0e4e0955c58b253c5aac6198302b6c11f3393f42d5edfd4fc317dd7b1a7894b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b1fd87395239845d1eeb4e901e44063e1487bdd83f226a247746dc1bc4fc555cfba4c8357345486dd31e5f5e8c0b5be59e2831e599a87d9c10632b221ad64e
|
7
|
+
data.tar.gz: eb6e88f325e65e1c49094a197a58419c11c71a5c24f78a5132167798ea4bff644c0a6d98320b073d16cea1b8baa258fa2300583474e95223e0f4ba09e9152327
|
data/README.md
CHANGED
@@ -17,35 +17,66 @@ 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', background: { color: :red, intensity: 500 } 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
|
-
|
35
|
+
will render [this](https://play.tailwindcss.com/UZPTCudFw5)
|
30
36
|
|
31
|
-
|
32
|
-
= tailwind_link_to 'Sign In', "/users/sign_in"
|
33
|
-
```
|
37
|
+
#### tramway_navbar
|
34
38
|
|
35
|
-
|
39
|
+
This helper provides several options. Here is YAML view of `tramway_navbar` options structure
|
36
40
|
|
37
|
-
```
|
38
|
-
|
39
|
-
|
41
|
+
```yaml
|
42
|
+
title: String that will be added to the left side of the navbar
|
43
|
+
background:
|
44
|
+
color: Css-color. Supports all named CSS colors and HEX colors
|
45
|
+
intensity: Color intensity. Range: **100..950**. Used by Tailwind. Not supported in case of using HEX color in the background.color
|
40
46
|
```
|
41
47
|
|
42
|
-
|
48
|
+
#### nav.left and nav.right
|
43
49
|
|
44
|
-
|
45
|
-
= tailwind_link_to 'Sign Out', "/users/sign_out", method: :delete, confirm: 'Wanna quit?'
|
46
|
-
```
|
50
|
+
Tramway navbar provides `left` and `right` methods that puts items to left and right part of navbar.
|
47
51
|
|
48
|
-
|
52
|
+
#### nav.item
|
53
|
+
|
54
|
+
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.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
tramway_navbar title: 'Purple Magic' do |nav|
|
58
|
+
nav.left do
|
59
|
+
nav.item 'Users', '/users'
|
60
|
+
|
61
|
+
# NOTE you can achieve the same with
|
62
|
+
|
63
|
+
nav.item '/users' do
|
64
|
+
'Users'
|
65
|
+
end
|
66
|
+
|
67
|
+
# NOTE nav.item supports turbo-method and turbo-confirm attributes
|
68
|
+
|
69
|
+
nav.item 'Delete user', '/users/destroy', method: :delete, confirm: 'Are you sure?'
|
70
|
+
|
71
|
+
# will render this
|
72
|
+
# <li>
|
73
|
+
# <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">
|
74
|
+
# Sign out
|
75
|
+
# </a>
|
76
|
+
# </li>
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
49
80
|
|
50
81
|
## Contributing
|
51
82
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Tailwinds
|
4
|
-
module
|
4
|
+
module Nav
|
5
5
|
# Render button styled with Tailwind using button_to or link_to methods
|
6
6
|
#
|
7
|
-
class
|
7
|
+
class ItemComponent < TailwindComponent
|
8
8
|
def initialize(**options)
|
9
9
|
@href = options[:href]
|
10
10
|
@style = 'text-white hover:bg-red-300 px-4 py-2 rounded'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%nav.py-4.px-8.flex.justify-between.items-center{ class: "bg-#{@color}" }
|
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,36 @@
|
|
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
|
+
@color = background(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
CSS_COLORS = %i[aqua black blue fuchsia gray green lime maroon navy olive orange purple red
|
17
|
+
silver teal white yellow].freeze
|
18
|
+
MIN_INTENSITY = 100
|
19
|
+
MAX_INTENSITY = 950
|
20
|
+
|
21
|
+
def background(options)
|
22
|
+
color = options.dig(:background, :color) || :purple
|
23
|
+
intensity = options.dig(:background, :intensity) || 700
|
24
|
+
|
25
|
+
unless (MIN_INTENSITY..MAX_INTENSITY).cover?(intensity)
|
26
|
+
raise "Navigation Background Color intensity should be between #{MIN_INTENSITY} and #{MAX_INTENSITY}"
|
27
|
+
end
|
28
|
+
|
29
|
+
if color.in? CSS_COLORS
|
30
|
+
"#{color}-#{intensity}"
|
31
|
+
else
|
32
|
+
"[#{color}]"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/tramway/engine.rb
CHANGED
@@ -8,9 +8,9 @@ module Tramway
|
|
8
8
|
|
9
9
|
initializer 'tramway.load_helpers' do
|
10
10
|
ActiveSupport.on_load(:action_view) do
|
11
|
-
require 'tramway/helpers/
|
11
|
+
require 'tramway/helpers/navbar_helper'
|
12
12
|
|
13
|
-
ActionView::Base.include Tramway::Helpers::
|
13
|
+
ActionView::Base.include Tramway::Helpers::NavbarHelper
|
14
14
|
end
|
15
15
|
end
|
16
16
|
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
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.6
|
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-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: haml-rails
|
@@ -79,13 +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
|
88
|
-
- lib/tramway/helpers/
|
90
|
+
- lib/tramway/helpers/navbar_helper.rb
|
91
|
+
- lib/tramway/navbar.rb
|
89
92
|
- lib/tramway/version.rb
|
90
93
|
homepage: https://github.com/purple-magic/tramway
|
91
94
|
licenses:
|
@@ -1,21 +0,0 @@
|
|
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
|