tramway 0.4.4 → 0.4.5

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: b43fe918fc6610c50f4ed68ddc2487d295084f931fe77cfcdc5bdb82cc518007
4
- data.tar.gz: 1e72ed61a083e7ba35daf01137678e3858f081cb46148acb16b1c2b7999de207
3
+ metadata.gz: 54d135e0a0a71941eecdbbbf042963727d6b0e13e7a024f1c86f22d099d76feb
4
+ data.tar.gz: fa8e45c0a89c065df62d580e368b1e73a43a4abd06c9e542d8b8a8706dba24c0
5
5
  SHA512:
6
- metadata.gz: 86065ebdaf2fe77f1d7599723a42189fa1ac3e49e8de52fd6b94d28911e4060ee9edc5b2f4501a38fc8d1697456c80bd9d8ff9a40ea924154b82303ac728e67e
7
- data.tar.gz: bf80442224d4659ca1258258418e1f42490caf20924ea22e6fa6be26ea08e2d567b381fc5a842ef53f9aa2e40537ea1946270d369e256d74989acf14b50dd267
6
+ metadata.gz: 2b2b51bb24ca9c973ccd2cc3a925c102a2bedc1c1c1daa43c5be00d4563cc6491a521796a00f7cd80c8019718709e41d683c6f69819cd96172af0a5756f9ef29
7
+ data.tar.gz: 5db00c69d1d90c75d924d30a6989d087affbe2b2de546d774bfb58b732efce5b5a6615bd6801cdcfdd55d9f0c088c34fa2f7223793cd4d0e8c268dd10334a25e
@@ -30,7 +30,7 @@ module Tailwinds
30
30
  render(Tailwinds::Form::SelectComponent.new(
31
31
  input: input(:select),
32
32
  value: options[:selected] || object.public_send(attribute),
33
- collection:,
33
+ collection: explicitly_add_blank_option(collection, options),
34
34
  **default_options(attribute, options)
35
35
  ), &)
36
36
  end
@@ -53,20 +53,32 @@ module Tailwinds
53
53
  def default_options(attribute, options)
54
54
  {
55
55
  attribute:,
56
- label: label(attribute, options),
56
+ label: label_build(attribute, options),
57
57
  for: for_id(attribute),
58
58
  options:
59
59
  }
60
60
  end
61
61
 
62
62
  # :reek:UtilityFunction
63
- def label(attribute, options)
64
- options[:label] || attribute.to_s.humanize
63
+ def label_build(attribute, options)
64
+ options[:label].presence || attribute.to_s.humanize
65
65
  end
66
66
 
67
67
  def for_id(attribute)
68
68
  "#{object_name}_#{attribute}"
69
69
  end
70
+
71
+ # REMOVE IT. WE MUST UNDERSTAND WHY INCLUDE_BLANK DOES NOT WORK
72
+ # :reek:UtilityFunction
73
+ def explicitly_add_blank_option(collection, options)
74
+ if options[:include_blank]
75
+ collection = collection.to_a if collection.is_a? Hash
76
+
77
+ collection.unshift([nil, ''])
78
+ else
79
+ collection
80
+ end
81
+ end
70
82
  end
71
83
  end
72
84
  end
@@ -1,4 +1,5 @@
1
1
  .mb-4
2
- %label.inline-block.bg-blue-500.hover:bg-blue-700.text-white.font-bold.py-2.px-4.rounded.cursor-pointer.mt-4{ for: @for }
3
- = @label
2
+ - if @label
3
+ %label.inline-block.bg-blue-500.hover:bg-blue-700.text-white.font-bold.py-2.px-4.rounded.cursor-pointer.mt-4{ for: @for }
4
+ = @label
4
5
  = @input
@@ -1,4 +1,5 @@
1
1
  .mb-4
2
- %label.block.text-gray-700.text-sm.font-bold.mb-2{ for: @for }
3
- = @label
2
+ - if @label
3
+ %label.block.text-gray-700.text-sm.font-bold.mb-2{ for: @for }
4
+ = @label
4
5
  = @input.call(@attribute, @collection, { selected: @value }, @options.merge(class: 'bg-white border border-gray-300 text-gray-700 py-2 px-2 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent'))
@@ -1,4 +1,5 @@
1
1
  .mb-4
2
- %label.block.text-gray-700.text-sm.font-bold.mb-2{ for: @for }
3
- = @label
2
+ - if @label
3
+ %label.block.text-gray-700.text-sm.font-bold.mb-2{ for: @for }
4
+ = @label
4
5
  = @input.call @attribute, **@options.merge(class: 'w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:border-red-500'), value: @value
@@ -0,0 +1,3 @@
1
+ %li
2
+ = button_to @href, method: @method, class: @style, **@options do
3
+ = content
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rules/turbo_html_attributes_rules'
4
+
5
+ module Tailwinds
6
+ module Nav
7
+ module Item
8
+ # Render button styled with Tailwind using button_to methods
9
+ #
10
+ class ButtonComponent < TailwindComponent
11
+ def initialize(**options)
12
+ @href = options[:href]
13
+ @method = options[:method]
14
+ @style = 'text-white hover:bg-red-300 px-4 py-2 rounded'
15
+ @options = options.except(:href, :method)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rules/turbo_html_attributes_rules'
4
+
5
+ module Tailwinds
6
+ module Nav
7
+ module Item
8
+ # Render button styled with Tailwind using link_to methods
9
+ #
10
+ class LinkComponent < TailwindComponent
11
+ def initialize(**options)
12
+ @href = options[:href]
13
+ @style = 'text-white hover:bg-red-300 px-4 py-2 rounded'
14
+ @options = Rules::TurboHtmlAttributesRules.prepare_turbo_html_attributes(options:)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -37,9 +37,9 @@ module Tramway
37
37
  raise 'You cannot provide an argument and a code block at the same time' if provided_url_and_block?(url, &block)
38
38
 
39
39
  rendered_item = if url.present?
40
- render_ignoring_block(text_or_url, url, options)
40
+ render_ignoring_block(text_or_url, url, **options)
41
41
  else
42
- render_using_block(text_or_url, options, &block)
42
+ render_using_block(text_or_url, **options, &block)
43
43
  end
44
44
 
45
45
  @items[@filling] << rendered_item
@@ -69,16 +69,24 @@ module Tramway
69
69
  @filling = nil
70
70
  end
71
71
 
72
- def render_ignoring_block(text_or_url, url, options)
72
+ def render_ignoring_block(text_or_url, url, method: nil, **options)
73
73
  options.merge!(href: url)
74
74
 
75
- context.render(Tailwinds::Nav::ItemComponent.new(**options)) { text_or_url }
75
+ if method.present? && method.to_sym != :get
76
+ context.render(Tailwinds::Nav::Item::ButtonComponent.new(method:, **options)) { text_or_url }
77
+ else
78
+ context.render(Tailwinds::Nav::Item::LinkComponent.new(method:, **options)) { text_or_url }
79
+ end
76
80
  end
77
81
 
78
- def render_using_block(text_or_url, options, &block)
82
+ def render_using_block(text_or_url, method: nil, **options, &block)
79
83
  options.merge!(href: text_or_url)
80
84
 
81
- context.render(Tailwinds::Nav::ItemComponent.new(**options), &block)
85
+ if method.present? && method.to_sym != :get
86
+ context.render(Tailwinds::Nav::Item::ButtonComponent.new(method:, **options), &block)
87
+ else
88
+ context.render(Tailwinds::Nav::Item::LinkComponent.new(method:, **options), &block)
89
+ end
82
90
  end
83
91
  end
84
92
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.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.4.4
4
+ version: 0.4.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: 2024-04-07 00:00:00.000000000 Z
12
+ date: 2024-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-struct
@@ -102,8 +102,10 @@ files:
102
102
  - app/components/tailwinds/form/submit_button_component.rb
103
103
  - app/components/tailwinds/form/text_field_component.html.haml
104
104
  - app/components/tailwinds/form/text_field_component.rb
105
- - app/components/tailwinds/nav/item_component.html.haml
106
- - app/components/tailwinds/nav/item_component.rb
105
+ - app/components/tailwinds/nav/item/button_component.html.haml
106
+ - app/components/tailwinds/nav/item/button_component.rb
107
+ - app/components/tailwinds/nav/item/link_component.html.haml
108
+ - app/components/tailwinds/nav/item/link_component.rb
107
109
  - app/components/tailwinds/navbar_component.html.haml
108
110
  - app/components/tailwinds/navbar_component.rb
109
111
  - app/views/kaminari/_first_page.html.haml
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rules/turbo_html_attributes_rules'
4
-
5
- module Tailwinds
6
- module Nav
7
- # Render button styled with Tailwind using button_to or link_to methods
8
- #
9
- class ItemComponent < TailwindComponent
10
- def initialize(**options)
11
- @href = options[:href]
12
- @style = 'text-white hover:bg-red-300 px-4 py-2 rounded'
13
- @options = Rules::TurboHtmlAttributesRules.prepare_turbo_html_attributes(options:)
14
- end
15
- end
16
- end
17
- end