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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1922614da732feb087d1d3b616b217c6c42f34b7cfc4d93cf77388f49b938d86
4
- data.tar.gz: 9730279b3566ebaf8505048a477eeecf71b815d007ace7ca6b4ef5d1dd1a4683
3
+ metadata.gz: 185e73cab73c23d8de233721cde393cb453868e1cf3a6f5ef8b322b9b613ff32
4
+ data.tar.gz: 6bca9e94731ecd625cf20f904f0cac42fe969ac63ac72913de75f6a176f18a1e
5
5
  SHA512:
6
- metadata.gz: 46eb0606d45d420ff8ed76f63b4c4cb0e92b7a00305afba551feac44ff925f7a0202c7cb1e47a35a9e336ea76af0d8c2ce5fc5b7c2dc136fc43ffd715c23db17
7
- data.tar.gz: a346e31ca903c626d99e2c5f2211569d1e886641cf16101e986c7a5cde5aff6127d345c0447f3ed0ca74dd7e51187814b0487773a3664f5d8bdbeb6caaf84454
6
+ metadata.gz: a4dfdc42e1697576ac22f8af14c0d6f75be71b198b19a5c6e3097c895db0eb114401af25cf30c39e3615999f4bb41907bde50bc70e22aa6520c1c9805a8eb230
7
+ data.tar.gz: d00f990562345a341b69ac4c86ef72bf0deef57defbe4dcdfdfa0b9759079f8e43f57005d59c8058cec368fefa886090814517de823efc2dd7b94b84601dd896
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superview (0.1.1)
4
+ superview (0.1.2)
5
5
  phlex-rails (~> 1.0)
6
6
  zeitwerk (~> 2.0)
7
7
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Superview
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
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.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-27 00:00:00.000000000 Z
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