tramway 0.5.2.1 → 0.5.3

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: 7bd63f1711a60db98ddc871375d48d7d3e6eaae3d67626dc038146e42395b3e6
4
- data.tar.gz: ce50bc57610979a11cbc11feb52958b1a76ff85a7e530a28f872d85973f00e7a
3
+ metadata.gz: c116b7002a5f382a5b2d54704e425d6a7e2e1a5208cb2eb1f0cd060bf5852718
4
+ data.tar.gz: 6a183fa879258d651afcd2479265854139dcc8e5da69f9684a331f859274de64
5
5
  SHA512:
6
- metadata.gz: e3faa9546ca344e73c22cfa4d751375efadcde87dc28a1767ff47954ca014258ea6d6dd065bdc58c8e6abc76d7bffd739e2116c3a306cb1733c20b44a80e39a9
7
- data.tar.gz: 1f5cc72ffc449a10248be0b997392a9b17ef61bc37b0198ac9a5283963ad40e4428ddc586410b9faf9a04a5f209e96f21747ca2a8649a060ca0ea63250b453e4
6
+ metadata.gz: 7765e1c762c50ba2cb543ef79f155f6649cd5c5ac0ee38aa530f9472f0a7024ca489473ac0cf597a30a8fa2c99ce2ed8fde0d62fa34198a7903e3c90e8edfc92
7
+ data.tar.gz: d136698275286b8188609c2883756a9e338ca6c6faf118166f1374f443ae68ac7ed99849811703f6bf2f70e71d5aaadaec1433d4bec41e70568e27fea015edf1
data/README.md CHANGED
@@ -26,7 +26,7 @@ gem "view_component"
26
26
  OR
27
27
 
28
28
  ```shell
29
- bundle add tramway view_component
29
+ bundle add tramway view_component kaminari view_component
30
30
  ```
31
31
 
32
32
  ## Getting Started
@@ -225,7 +225,7 @@ Tramway provides **convenient** form objects for Rails applications. List proper
225
225
  class UserForm < Tramway::BaseForm
226
226
  properties :email, :password, :first_name, :last_name, :phone
227
227
 
228
- normalizes :email, ->(value) { value.strip.downcase }
228
+ normalizes :email, with: ->(value) { value.strip.downcase }
229
229
  end
230
230
  ```
231
231
 
@@ -13,6 +13,14 @@ module Tailwinds
13
13
  ), &)
14
14
  end
15
15
 
16
+ def text_area(attribute, **options, &)
17
+ render(Tailwinds::Form::TextAreaComponent.new(
18
+ input: input(:text_area),
19
+ value: get_value(attribute, options),
20
+ **default_options(attribute, options)
21
+ ), &)
22
+ end
23
+
16
24
  def password_field(attribute, **options, &)
17
25
  render(Tailwinds::Form::TextFieldComponent.new(
18
26
  input: input(:password_field),
@@ -2,4 +2,4 @@
2
2
  - if @label
3
3
  = component('tailwinds/form/label', for: @for) do
4
4
  = @label
5
- = @input.call(@attribute, @collection, { selected: @value }, @options.merge(class: 'bg-white border border-gray-300 text-gray-700 py-2.5 px-2 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent'))
5
+ = @input.call(@attribute, @collection, { selected: @value }, @options.merge(class: 'bg-white border border-gray-300 text-gray-700 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent py-2 px-3'))
@@ -1,4 +1,4 @@
1
1
  .flex.items-center.justify-between
2
- %button.bg-red-500.hover:bg-red-700.text-white.font-bold.py-2.px-4.rounded.focus:outline-none.focus:shadow-outline.cursor-pointer{ type: :submit, name: :commit, **@options }
2
+ %button.bg-red-500.hover:bg-red-700.text-white.font-bold.py-2.px-4.rounded.focus:outline-none.focus:shadow-outline.cursor-pointer.dark:text-white{ type: :submit, name: :commit, **@options }
3
3
  = @text
4
4
  = @content
@@ -0,0 +1,5 @@
1
+ .mb-4
2
+ - if @label
3
+ = component('tailwinds/form/label', for: @for) do
4
+ = @label
5
+ = @input.call @attribute, **@options.merge(class: 'w-full bg-white px-3 py-2 border border-gray-300 rounded focus:outline-none focus:border-red-500 dark:placeholder-gray-400'), value: @value
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tailwinds
4
+ module Form
5
+ # Tailwind-styled text field
6
+ class TextAreaComponent < TailwindComponent
7
+ end
8
+ end
9
+ end
@@ -8,7 +8,7 @@ module Tailwinds
8
8
  def style
9
9
  @style ||= [
10
10
  'text-white', 'hover:bg-gray-300', 'hover:text-gray-800', 'px-4', 'py-2', 'rounded', 'whitespace-nowrap',
11
- 'dark:hover:bg-gray-700', 'dark:hover:text-gray-400'
11
+ 'dark:hover:bg-gray-700', 'dark:hover:text-gray-400', 'dark:text-white'
12
12
  ].join(' ')
13
13
  end
14
14
  end
@@ -4,7 +4,7 @@
4
4
  .flex.items-center
5
5
  - if @title[:text].present?
6
6
  = link_to @title[:link] do
7
- .text-xl.text-white.font-bold
7
+ .text-xl.text-white.font-bold.dark:text-white
8
8
  = @title[:text]
9
9
  - if @left_items.present?
10
10
  %ul.block.flex.flex-row.items-center.space-x-4.ml-4
@@ -1,27 +1,15 @@
1
1
  - if cells.any?
2
- -# desktop view
3
- = row_tag class: desktop_row_classes(cells.count) do
2
+ = row_tag class: desktop_row_classes(cells.count), **options do
4
3
  - cells.each do |(_, value)|
5
4
  .div-table-cell.px-6.py-4.font-medium.text-gray-900.whitespace-nowrap.dark:text-white.text-xs.sm:text-base
6
5
  = value
7
6
 
8
- -# mobile view
9
- .div-table-row.xl:hidden.border-b.dark:bg-gray-800.dark:border-gray-700.mb-2{ "data-action" => "click->preview#toggle", "data-controller" => "preview", "data-items" => cells.to_json }
10
- .w-full.p-4.bg-purple-100.text-gray-700.dark:bg-gray-700.dark:text-gray-400
11
- = cells.values.first
12
-
13
- .flex.overflow-x-auto.whitespace-nowrap
14
- - cells.each_with_index do |(_, value), index|
15
- - next if index == 0
16
-
17
- .text-gray-900.dark:text-white.p-4.text-xs.sm:text-base.inline-block.w-auto
18
- = value
19
7
  - else
20
- - cells = Nokogiri::HTML.fragment(content).children.css('div')
8
+ - cells = Nokogiri::HTML.fragment(content).xpath('./*[@class and contains(concat(" ", normalize-space(@class), " "), " div-table-cell ")]')
21
9
 
22
10
  - if href.present?
23
- = tag.a href:, class: [desktop_row_classes(cells.count), link_row_classes].join(' ') do
11
+ = tag.a href:, class: [desktop_row_classes(cells.count), link_row_classes].join(' '), **options do
24
12
  = content
25
13
  - else
26
- = tag.div class: desktop_row_classes(cells.count) do
14
+ = tag.div class: desktop_row_classes(cells.count), **options do
27
15
  = content
@@ -6,6 +6,7 @@ module Tailwinds
6
6
  class RowComponent < Tramway::Component::Base
7
7
  option :cells, optional: true, default: -> { [] }
8
8
  option :href, optional: true
9
+ option :options, optional: true, default: -> { {} }
9
10
 
10
11
  def row_tag(**options, &)
11
12
  if href.present?
@@ -1,4 +1,4 @@
1
1
  = helpers.component 'tailwinds/table/row/preview'
2
2
 
3
- .div-table.w-full.text-left.rtl:text-right.text-gray-500.dark:text-gray-400.mt-4
3
+ .div-table.w-full.text-left.rtl:text-right.text-gray-500.dark:text-gray-400.mt-4{ **options }
4
4
  = content
@@ -3,5 +3,6 @@
3
3
  module Tailwinds
4
4
  # Table component for rendering a table
5
5
  class TableComponent < Tramway::Component::Base
6
+ option :options, optional: true, default: -> { {} }
6
7
  end
7
8
  end
@@ -11,7 +11,7 @@ module Tramway
11
11
  include Rails.application.routes.url_helpers
12
12
 
13
13
  def index
14
- @entities = model_class.page(params[:page])
14
+ @entities = model_class.order(id: :desc).page(params[:page])
15
15
  end
16
16
 
17
17
  private
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'tramway/helpers/component_helper'
4
+ require 'kaminari/helpers/tag'
4
5
 
5
6
  module Tramway
6
7
  # Main helper module for Tramway entities pages
@@ -4,12 +4,14 @@
4
4
  .mt-8.w-full
5
5
  - content_for :title, page_title
6
6
 
7
- .flex.justify-between.items-center.md:mt-4.mt-2
7
+ .flex.justify-between.items-center
8
8
  %h1.font-bold.text-4xl.dark:text-white
9
9
  = content_for(:title)
10
10
 
11
11
  - if Tramway.config.pagination[:enabled]
12
- = paginate @entities
12
+ = paginate @entities, custom_path_method: "#{@model_class.model_name.plural}_path"
13
+ .flex.justify-end.mt-2
14
+ = decorator.constantize.index_header_content.call(@entities) if decorator.constantize.index_header_content.present?
13
15
 
14
16
  - if list_attributes.empty?
15
17
  %p.text-center.mt-10
@@ -21,5 +23,6 @@
21
23
  - @entities.each do |item|
22
24
  = render 'tramway/entities/entity', entity: item
23
25
 
24
- .flex.mt-4
25
- = paginate @entities
26
+ - if Tramway.config.pagination[:enabled]
27
+ .flex.mt-4
28
+ = paginate @entities, custom_path_method: "#{@model_class.model_name.plural}_path"
@@ -23,7 +23,11 @@ module.exports = {
23
23
  'flex',
24
24
  'bg-purple-700',
25
25
  'px-6',
26
+ 'px-3',
27
+ 'px-4',
26
28
  'py-4',
29
+ 'py-2',
30
+ 'mb-2',
27
31
  'dark:placeholder-gray-400',
28
32
  'dark:text-white',
29
33
  'dark:bg-gray-800',
@@ -41,6 +45,11 @@ module.exports = {
41
45
  'hover:bg-gray-100',
42
46
  'hover:bg-gray-300',
43
47
  'hover:text-gray-800',
48
+ 'mt-8',
49
+ 'justify-between',
50
+ 'space-x-1',
51
+ 'justify-end',
52
+ 'mt-2',
44
53
  // pagination
45
54
  'bg-white', 'rounded-md', 'hover:bg-purple-100', 'dark:text-white', 'dark:bg-gray-800', 'dark:hover:bg-gray-700',
46
55
  // multiselect styles
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kaminari
4
+ module Helpers
5
+ # Monkey patch for Kaminari::Helpers::Tag to support :custom_path_method
6
+ # :reek:InstanceVariableAssumption { enabled: false }
7
+ class Tag
8
+ def page_url_for(page)
9
+ custom_path_method = @options[:custom_path_method]
10
+
11
+ if custom_path_method.present?
12
+ Tramway::Engine.routes.url_helpers.public_send(
13
+ custom_path_method,
14
+ @params.except(:controller, :action).merge(page: page)
15
+ )
16
+ else
17
+ params = params_for(page)
18
+ @template.url_for params.merge(only_path: true)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,6 +4,7 @@ require 'tramway/decorators/name_builder'
4
4
  require 'tramway/decorators/association'
5
5
  require 'tramway/decorators/collection_decorator'
6
6
  require 'tramway/helpers/decorate_helper'
7
+ require 'tramway/helpers/component_helper'
7
8
  require 'tramway/utils/render'
8
9
  require 'tramway/duck_typing'
9
10
 
@@ -15,6 +16,7 @@ module Tramway
15
16
  include Tramway::Utils::Render
16
17
  include Tramway::DuckTyping::ActiveRecordCompatibility
17
18
  include Tramway::Helpers::DecorateHelper
19
+ include Tramway::Helpers::ComponentHelper
18
20
 
19
21
  attr_reader :object
20
22
 
@@ -23,6 +25,9 @@ module Tramway
23
25
  end
24
26
 
25
27
  class << self
28
+ include Tramway::Helpers::ComponentHelper
29
+ include Tramway::Utils::Render
30
+
26
31
  # :reek:NilCheck { enabled: false } because checking for nil is not a type-checking issue but business logic
27
32
  def decorate(object_or_array)
28
33
  return if object_or_array.nil?
@@ -47,6 +52,10 @@ module Tramway
47
52
  []
48
53
  end
49
54
 
55
+ def index_header_content
56
+ nil
57
+ end
58
+
50
59
  include Tramway::Decorators::AssociationClassMethods
51
60
  end
52
61
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.5.2.1'
4
+ VERSION = '0.5.3'
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.5.2.1
4
+ version: 0.5.3
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: 2025-02-18 00:00:00.000000000 Z
12
+ date: 2025-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anyway_config
@@ -162,6 +162,8 @@ files:
162
162
  - app/components/tailwinds/form/select_component.rb
163
163
  - app/components/tailwinds/form/submit_button_component.html.haml
164
164
  - app/components/tailwinds/form/submit_button_component.rb
165
+ - app/components/tailwinds/form/text_area_component.html.haml
166
+ - app/components/tailwinds/form/text_area_component.rb
165
167
  - app/components/tailwinds/form/text_field_component.html.haml
166
168
  - app/components/tailwinds/form/text_field_component.rb
167
169
  - app/components/tailwinds/nav/item/button_component.html.haml
@@ -210,6 +212,7 @@ files:
210
212
  - app/views/tramway/layouts/application.html.haml
211
213
  - config/routes.rb
212
214
  - config/tailwind.config.js
215
+ - lib/kaminari/helpers/tag.rb
213
216
  - lib/rules/turbo_html_attributes_rules.rb
214
217
  - lib/tasks/tramway_tasks.rake
215
218
  - lib/tramway.rb