tramway 0.4.4 → 0.4.5.1

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: ef5809ca8f857fbc319595ce2ada4409120a4a89dc657bf2f7625e9b329d7d47
4
+ data.tar.gz: da8094f83cc2f21d4470afef2311c790a079f9597aee99ebb448ea98cb83df61
5
5
  SHA512:
6
- metadata.gz: 86065ebdaf2fe77f1d7599723a42189fa1ac3e49e8de52fd6b94d28911e4060ee9edc5b2f4501a38fc8d1697456c80bd9d8ff9a40ea924154b82303ac728e67e
7
- data.tar.gz: bf80442224d4659ca1258258418e1f42490caf20924ea22e6fa6be26ea08e2d567b381fc5a842ef53f9aa2e40537ea1946270d369e256d74989acf14b50dd267
6
+ metadata.gz: a8e9018040b8068c41e98f57682d12e3e08ce191ebef5c252185ff8ccacfbd71f75d6935a03e35c883e240ee5b402fd997c934779faf831e112cf46fe5d3c073
7
+ data.tar.gz: e51b2512f9c078a2f094d4fb027c038c097ac7c1a4410da898563abc9eac2c94fa1e84f51e3438576ac9785b2e8ee6999b1b18b8505f1ab9c85be1095e1a7c3c
@@ -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,35 @@ 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
+ # :reek:NilCheck
64
+ def label_build(attribute, options)
65
+ label_option = options[:label]
66
+
67
+ label_option.nil? ? attribute.to_s.humanize : label_option
65
68
  end
66
69
 
67
70
  def for_id(attribute)
68
71
  "#{object_name}_#{attribute}"
69
72
  end
73
+
74
+ # REMOVE IT. WE MUST UNDERSTAND WHY INCLUDE_BLANK DOES NOT WORK
75
+ # :reek:UtilityFunction
76
+ def explicitly_add_blank_option(collection, options)
77
+ if options[:include_blank]
78
+ collection = collection.to_a if collection.is_a? Hash
79
+
80
+ collection.unshift([nil, ''])
81
+ else
82
+ collection
83
+ end
84
+ end
70
85
  end
71
86
  end
72
87
  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.1'
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.1
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