tramway 0.1.4 → 0.1.5

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: eedc7b84e9ad80ba5af66fc619af0aea5f24c17e4512e194a6069036ed00f646
4
- data.tar.gz: 3e4ac83ede95f1c90e4346f4723551f224efb8921ce1a8802d4977198623441a
3
+ metadata.gz: 711582391b4cec7b6f8c8808a9d20a1c9695825e94e292073fe85e15d066f11c
4
+ data.tar.gz: 178c09a9c02feaf8f02094849cbe9fd8756a6f1806419eee369bb1ae0df023b2
5
5
  SHA512:
6
- metadata.gz: 43325b31d7a7ca934f39160066dd39653767efd04589e735b1cc2cfaf8ed09c087b9e846816bb97131c11d39e6309d0ef7f9925810159acdb05e3ad77f595aef
7
- data.tar.gz: b3da39f4acde834c8897e2ff2853a0c7cfe7cd83d04c0817c30017801010e16d03d5249bb87dd2f98b08b166f1ed594499c71b90fbf1f799b92979363706ab7f
6
+ metadata.gz: 63d37dcea2ec474996c0a261b0b9d7e3619337f0fc3443f75608633c4c4c1ed08be7a367d79ce8b4c7db33695cfaa18e4052458f78ebbff3d13bc89e9e319418
7
+ data.tar.gz: 0a10282ff924f4adfd5c892852ed0943a23f3374c1ded44c59344854cdd43034549cd39a2eafd2b8e4af6d5dd60abd06c2cb247ab1a2e70f01b8bc8aba3076f0
data/README.md CHANGED
@@ -17,35 +17,55 @@ Tramway use [Tailwind](https://tailwindcss.com/) by default. All UI helpers impl
17
17
 
18
18
  ### Navbar
19
19
 
20
- #### tailwind_link_to
20
+ Tramway provides DSL for rendering Tailwind Navgiation bar.
21
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
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
- OR
35
+ will render [this](https://play.tailwindcss.com/UZPTCudFw5)
30
36
 
31
- ```haml
32
- = tailwind_link_to 'Sign In', "/users/sign_in"
33
- ```
37
+ #### nav.left and nav.right
34
38
 
35
- will render [this](https://play.tailwindcss.com/RT3Vvauu78)
39
+ Tramway navbar provides `left` and `right` methods that puts items to left and right part of navbar.
36
40
 
37
- ```haml
38
- = tailwind_link_to "/users/sign_out", method: :delete, confirm: 'Wanna quit?' do
39
- Sign Out
40
- ```
41
+ #### nav.item
41
42
 
42
- OR
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.
43
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
44
68
  ```
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))
49
69
 
50
70
  ## Contributing
51
71
 
@@ -0,0 +1,3 @@
1
+ %li
2
+ = link_to @href, class: @style, **@options do
3
+ = content
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tailwinds
4
- module Navbar
4
+ module Nav
5
5
  # Render button styled with Tailwind using button_to or link_to methods
6
6
  #
7
- class ButtonComponent < TailwindComponent
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.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
@@ -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/tailwind_helpers'
11
+ require 'tramway/helpers/navbar_helper'
12
12
 
13
- ActionView::Base.include Tramway::Helpers::TailwindHelpers
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  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.4
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-15 00:00:00.000000000 Z
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,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/navbar/button_component.html.haml
83
- - app/components/tailwinds/navbar/button_component.rb
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/tailwind_helpers.rb
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,2 +0,0 @@
1
- = link_to @href, class: @style, **@options do
2
- = content
@@ -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