tramway 3.0.4 → 3.0.4.1
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 +4 -4
- data/app/components/tramway/table/content_cells.rb +26 -0
- data/app/components/tramway/table/header_component.html.haml +2 -1
- data/app/components/tramway/table/header_component.rb +8 -2
- data/app/components/tramway/table/row_component.rb +2 -16
- data/lib/tramway/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cfd16d191c35f49e31f08328da1a8992ab6f1f08182c8b919355d54ff9951074
|
|
4
|
+
data.tar.gz: d1f8dfe3c21273a746a13750ee89c575cb9c0a065aca4aff0b93010613a381dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f90c814812cd3714bc1f4492ae243a9278dfd49e0cb4d8796597a548fd0c18d9eceab36e4cae21d28f4807dc036f088efe91f555d8623a7c28066422ee6c0b0d
|
|
7
|
+
data.tar.gz: b77c7144dd9fa87c805b4427a7d22f43011dba7da7cdc53eb494aeac47a15b6601bb06f076a2195347f0a22d1a62ec0293eba04ca29c472b81caa62f625229ac
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tramway
|
|
4
|
+
module Table
|
|
5
|
+
# Helpers for extracting and normalizing visible table content cells from HTML fragments.
|
|
6
|
+
module ContentCells
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def visible_cells_from(content)
|
|
10
|
+
fragment = Nokogiri::HTML.fragment(content)
|
|
11
|
+
parsed_cells = fragment.xpath(
|
|
12
|
+
'./*[@class and contains(concat(" ", normalize-space(@class), " "), " div-table-cell ")]'
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
parsed_cells.each { |cell| remove_hidden_class!(cell) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def remove_hidden_class!(node)
|
|
19
|
+
classes = node['class'].to_s.split
|
|
20
|
+
return if classes.empty?
|
|
21
|
+
|
|
22
|
+
node['class'] = classes.reject { |class_name| class_name == 'hidden' }.join(' ')
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
- parsed_cells = headers.any? ? nil : visible_cells_from(content)
|
|
2
|
+
%div{ class: "#{header_row_classes} md:grid-cols-#{columns_count(parsed_cells: parsed_cells)}", aria: { label: "Table Header" }, role: "row" }
|
|
2
3
|
- if headers.any?
|
|
3
4
|
- headers.each do |header|
|
|
4
5
|
.div-table-cell{ class: header_cell_classes }
|
|
@@ -4,11 +4,17 @@ module Tramway
|
|
|
4
4
|
module Table
|
|
5
5
|
# Component for rendering a header in a table
|
|
6
6
|
class HeaderComponent < Tramway::BaseComponent
|
|
7
|
+
include ContentCells
|
|
8
|
+
|
|
7
9
|
option :headers, optional: true, default: -> { [] }
|
|
8
10
|
option :columns, optional: true, default: -> { 3 }
|
|
9
11
|
|
|
10
|
-
def columns_count
|
|
11
|
-
headers.
|
|
12
|
+
def columns_count(content = nil, parsed_cells: nil)
|
|
13
|
+
return headers.size if headers.present?
|
|
14
|
+
return parsed_cells.size if parsed_cells
|
|
15
|
+
return visible_cells_from(content).size if content.present?
|
|
16
|
+
|
|
17
|
+
columns
|
|
12
18
|
end
|
|
13
19
|
|
|
14
20
|
def header_row_classes
|
|
@@ -4,6 +4,8 @@ module Tramway
|
|
|
4
4
|
module Table
|
|
5
5
|
# Component for rendering a row in a table
|
|
6
6
|
class RowComponent < Tramway::BaseComponent
|
|
7
|
+
include ContentCells
|
|
8
|
+
|
|
7
9
|
option :cells, optional: true, default: -> { [] }
|
|
8
10
|
option :href, optional: true
|
|
9
11
|
option :preview, optional: true, default: -> { true }
|
|
@@ -58,22 +60,6 @@ module Tramway
|
|
|
58
60
|
|
|
59
61
|
private
|
|
60
62
|
|
|
61
|
-
def visible_cells_from(content)
|
|
62
|
-
fragment = Nokogiri::HTML.fragment(content)
|
|
63
|
-
parsed_cells = fragment.xpath(
|
|
64
|
-
'./*[@class and contains(concat(" ", normalize-space(@class), " "), " div-table-cell ")]'
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
parsed_cells.each { |cell| remove_hidden_class!(cell) }
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def remove_hidden_class!(node)
|
|
71
|
-
classes = node['class'].to_s.split
|
|
72
|
-
return if classes.empty?
|
|
73
|
-
|
|
74
|
-
node['class'] = classes.reject { |class_name| class_name == 'hidden' }.join(' ')
|
|
75
|
-
end
|
|
76
|
-
|
|
77
63
|
def ensure_view_context_accessor
|
|
78
64
|
return if view_context.respond_to?(:tramway_inside_cell=)
|
|
79
65
|
|
data/lib/tramway/version.rb
CHANGED
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: 3.0.4
|
|
4
|
+
version: 3.0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kalashnikovisme
|
|
@@ -230,6 +230,7 @@ files:
|
|
|
230
230
|
- app/components/tramway/pagination/prev_page_component.rb
|
|
231
231
|
- app/components/tramway/table/cell_component.html.haml
|
|
232
232
|
- app/components/tramway/table/cell_component.rb
|
|
233
|
+
- app/components/tramway/table/content_cells.rb
|
|
233
234
|
- app/components/tramway/table/header_component.html.haml
|
|
234
235
|
- app/components/tramway/table/header_component.rb
|
|
235
236
|
- app/components/tramway/table/row/preview_component.html.haml
|