superview 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/superview/components/table_component.rb +78 -0
- data/lib/superview/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 185e73cab73c23d8de233721cde393cb453868e1cf3a6f5ef8b322b9b613ff32
|
4
|
+
data.tar.gz: 6bca9e94731ecd625cf20f904f0cac42fe969ac63ac72913de75f6a176f18a1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4dfdc42e1697576ac22f8af14c0d6f75be71b198b19a5c6e3097c895db0eb114401af25cf30c39e3615999f4bb41907bde50bc70e22aa6520c1c9805a8eb230
|
7
|
+
data.tar.gz: d00f990562345a341b69ac4c86ef72bf0deef57defbe4dcdfdfa0b9759079f8e43f57005d59c8058cec368fefa886090814517de823efc2dd7b94b84601dd896
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Superview::Components
|
2
|
+
# Renders an HTML table for a collection. Each item is passed into the
|
3
|
+
# collection of the table.
|
4
|
+
#
|
5
|
+
# ```ruby
|
6
|
+
# render TableComponent.new(items: @posts) do |table|
|
7
|
+
# # This is how you'd usually render a table.
|
8
|
+
# table.column("Title") { show(_1, :title) }
|
9
|
+
#
|
10
|
+
# # If you need to render HTML in the title, add a `column` argument
|
11
|
+
# # to the block and call `title` or `item` on it.
|
12
|
+
# table.column do |column|
|
13
|
+
# # Titles might not always be text, so we need to handle rendering
|
14
|
+
# # Phlex markup within.
|
15
|
+
# column.title do
|
16
|
+
# link_to(user_blogs_path(@current_user)) { "Blogs" }
|
17
|
+
# end
|
18
|
+
# column.item { show(_1.blog, :title) }
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
# ```
|
22
|
+
class TableComponent < ApplicationComponent
|
23
|
+
include Phlex::DeferredRender
|
24
|
+
|
25
|
+
class Column
|
26
|
+
attr_accessor :title_template, :item_template
|
27
|
+
|
28
|
+
def title(&block)
|
29
|
+
@title_template = block
|
30
|
+
end
|
31
|
+
|
32
|
+
def item(&block)
|
33
|
+
@item_template = block
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.build(title:, &block)
|
37
|
+
new.tap do |column|
|
38
|
+
column.title { title }
|
39
|
+
column.item(&block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(items: [])
|
45
|
+
@items = items
|
46
|
+
@columns = []
|
47
|
+
end
|
48
|
+
|
49
|
+
def template(&)
|
50
|
+
table do
|
51
|
+
thead do
|
52
|
+
tr do
|
53
|
+
@columns.each do |column|
|
54
|
+
th(&column.title_template)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
tbody do
|
59
|
+
@items.each do |item|
|
60
|
+
tr do
|
61
|
+
@columns.each do |column|
|
62
|
+
td { column.item_template.call(item) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def column(title = nil, &block)
|
71
|
+
@columns << if title
|
72
|
+
Column.build(title: title, &block)
|
73
|
+
else
|
74
|
+
Column.new.tap(&block)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/superview/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex-rails
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/superview.rb
|
57
57
|
- lib/superview/actions.rb
|
58
58
|
- lib/superview/assignable.rb
|
59
|
+
- lib/superview/components/table_component.rb
|
59
60
|
- lib/superview/helpers/links.rb
|
60
61
|
- lib/superview/helpers/turbo.rb
|
61
62
|
- lib/superview/helpers/turbo/meta_tags.rb
|