tramway 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '084eca40c591bb6705843669a4983d864fda457337341a75ebee213bd43e8b93'
4
- data.tar.gz: a1c3158c7f921668ff8d811606abdeddf9fd4e1aac369d3e8f292e5af93539ca
3
+ metadata.gz: eedc7b84e9ad80ba5af66fc619af0aea5f24c17e4512e194a6069036ed00f646
4
+ data.tar.gz: 3e4ac83ede95f1c90e4346f4723551f224efb8921ce1a8802d4977198623441a
5
5
  SHA512:
6
- metadata.gz: b9b5fcb0b7f8a1d9e9b4cdc0b4f5064aefa8bab4ae306c47f73635fef93f30016a95b7e341459af975131b55200ff8ca42c48d10fa995f80df7aff25e0f74f43
7
- data.tar.gz: 8e1a52e17db4074f041e778a2790181c4b673d555fb384c3bc79c9cf929376fc1dcf24d345a5c571bc20b248fdc1073e67bae3b8c46e5950e89fb3766d83e1cb
6
+ metadata.gz: 43325b31d7a7ca934f39160066dd39653767efd04589e735b1cc2cfaf8ed09c087b9e846816bb97131c11d39e6309d0ef7f9925810159acdb05e3ad77f595aef
7
+ data.tar.gz: b3da39f4acde834c8897e2ff2853a0c7cfe7cd83d04c0817c30017801010e16d03d5249bb87dd2f98b08b166f1ed594499c71b90fbf1f799b92979363706ab7f
data/README.md CHANGED
@@ -1,28 +1,60 @@
1
1
  # Tramway
2
- Short description and motivation.
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
- And then execute:
15
- ```bash
16
- $ bundle
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
- Or install it yourself as:
20
- ```bash
21
- $ gem install tramway
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
- Contribution directions go here.
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
- = button_to @text, @href, class: 'text-white hover:bg-red-300 px-4 py-2 rounded'
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(text:, href:)
9
- @href = href
10
- @text = text
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
@@ -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'
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
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: