slotify 0.0.0
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 +7 -0
- data/README.md +150 -0
- data/lib/slotify/version.rb +3 -0
- data/lib/slotify.rb +3 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 905eaee14b280c6b59fed9887ab8ecf8e1796ca341296debf5c532bbb83ccd5f
|
4
|
+
data.tar.gz: a260b0e8f3eda211a58f48ac5389ebebc84935888fcf6355a00145338005f33f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a4b87a2792a032cde484a793dea94025f091a1bfa2464938437dda769ada354b788193aa896831da5d10e1506d8ada25e6a41287cfd9ff539eda3447c88a7f0
|
7
|
+
data.tar.gz: 714fcfd6cfa44f24c7c562f72edaf5833e8b25048d5de639b753f9359c97c7fa0586abb478200ea1a4c5700dbf8774b7e7623a25697084cf8674dc487b9a23e6
|
data/README.md
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
<img src=".github/assets/slotify_wordmark.svg" width="140">
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
#### _A superpowered slot system for Rails partials._
|
6
|
+
|
7
|
+
----------
|
8
|
+
|
9
|
+
## Overview
|
10
|
+
|
11
|
+
Slotify adds a lightweight (but powerful!) slot system for providing content to partials when rendering them.
|
12
|
+
|
13
|
+
Slots are defined using a `strict locals`-style magic comment at the top of the partial.
|
14
|
+
Slot content is accessed via 'regular' local variables within the template.
|
15
|
+
|
16
|
+
```erb
|
17
|
+
<!-- views/_my_partial_.html.erb -->
|
18
|
+
|
19
|
+
<%# slots: (title: "Example title", items: nil, link:) -%>
|
20
|
+
|
21
|
+
<div>
|
22
|
+
<h1><%= title %></h1>
|
23
|
+
|
24
|
+
<% if items.any? %>
|
25
|
+
<ul>
|
26
|
+
<%= items.each do |item| %>
|
27
|
+
<li <%= item.options %>>
|
28
|
+
<%= item %>
|
29
|
+
</li>
|
30
|
+
<% end%>
|
31
|
+
</ul>
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
<p>
|
35
|
+
Example link: <%= partial.link_to link, class: "example-link" %>
|
36
|
+
</p>
|
37
|
+
</div>
|
38
|
+
```
|
39
|
+
|
40
|
+
Content can then be provided to slots when rendering the partial:
|
41
|
+
|
42
|
+
```erb
|
43
|
+
<%= render "my_partial", do |partial| %>
|
44
|
+
<%= partial.with_title do %>
|
45
|
+
This is a title
|
46
|
+
<% end %>
|
47
|
+
|
48
|
+
<%= partial.with_item "Item 1" %>
|
49
|
+
<%= partial.with_item "Item 2", class: "text-green-700" %>
|
50
|
+
|
51
|
+
<% partial.with_link "example.com", "https://example.com", target: "_blank" %>
|
52
|
+
<% end %>
|
53
|
+
```
|
54
|
+
|
55
|
+
Slots defined with singular names can only be called with content once whereas slots defined with plural names can be called multiple times.
|
56
|
+
|
57
|
+
### Requirements
|
58
|
+
|
59
|
+
* `Rails 8.0+`
|
60
|
+
* `Ruby 3.1+`
|
61
|
+
|
62
|
+
## Usage
|
63
|
+
|
64
|
+
🚧 Work in progress! 🚧
|
65
|
+
|
66
|
+
### Defining slots
|
67
|
+
|
68
|
+
Slots are defined using a `strict locals`-style magic comment at the top of the partial template.
|
69
|
+
|
70
|
+
```erb
|
71
|
+
<%# slots: (title: "Example title", lists: nil, quotes: nil, website_link:) -%>
|
72
|
+
```
|
73
|
+
|
74
|
+
* Singular slots can only accept one entry, plural slots can accept many.
|
75
|
+
* Slots can be required (no default value) or optional.
|
76
|
+
* Optional slots can additionaly specify default content as needed.
|
77
|
+
|
78
|
+
### A more complete example
|
79
|
+
|
80
|
+
```erb
|
81
|
+
<!-- views/_example.html.erb -->
|
82
|
+
|
83
|
+
<%# locals: (id:) -%>
|
84
|
+
<%# slots: (title: "Example title", lists: nil, quotes: nil, website_link:) -%>
|
85
|
+
|
86
|
+
<%= tag.section id: do %>
|
87
|
+
<h1 class="example-title">
|
88
|
+
<%= title %>
|
89
|
+
</h1>
|
90
|
+
|
91
|
+
<p>Example link: <%= partial.link_to website_link, data: {controller: "external-link"} %></p>
|
92
|
+
|
93
|
+
<%= render lists, title: "Default title" %>
|
94
|
+
|
95
|
+
<% if quotes.any? %>
|
96
|
+
<h3>Quotes</h3>
|
97
|
+
<% quotes.each do |quote| %>
|
98
|
+
<blockquote <%= quote.options.except(:citation) %>>
|
99
|
+
<%= quote %>
|
100
|
+
<%== "— #{tag.cite(quote.options.citation)}" if quote.options.citation.present? %>
|
101
|
+
</blockquote>
|
102
|
+
<% end %>
|
103
|
+
<% end %>
|
104
|
+
<% end %>
|
105
|
+
```
|
106
|
+
|
107
|
+
```erb
|
108
|
+
<!-- views/_list.html.erb -->
|
109
|
+
|
110
|
+
<%# locals: (title:) -%>
|
111
|
+
<%# slots: (items: nil) -%>
|
112
|
+
|
113
|
+
<h3><%= title %></h3>
|
114
|
+
|
115
|
+
<% if items.any? %>
|
116
|
+
<%= tag.ul class: "list" do %>
|
117
|
+
<%= partial.li items, class: "list-item" %>
|
118
|
+
<% end %>
|
119
|
+
<% end %>
|
120
|
+
```
|
121
|
+
|
122
|
+
```erb
|
123
|
+
<!-- views/slotify.html.erb -->
|
124
|
+
|
125
|
+
<%= render "example", id: "slotify-example" do |partial| %>
|
126
|
+
<% partial.with_subtitle do %>
|
127
|
+
This is the <%= tag.em "subtitle" %>
|
128
|
+
<% end %>
|
129
|
+
|
130
|
+
<% partial.with_website_link "example.com", "https://example.com", target: "_blank", data: {controller: "preview-link"} %>
|
131
|
+
|
132
|
+
<% partial.with_list do |list| %>
|
133
|
+
<% list.with_item "first thing" %>
|
134
|
+
<% list.with_item "second thing", class: "text-green-700" %>
|
135
|
+
<% list.with_item "third thing" %>
|
136
|
+
<% end %>
|
137
|
+
|
138
|
+
<% partial.with_quote citation: "A. Person", class: "text-lg" do %>
|
139
|
+
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
|
140
|
+
<% end %>
|
141
|
+
|
142
|
+
<% partial.with_quote do %>
|
143
|
+
<p>Non quos explicabo eius hic quaerat laboriosam incidunt numquam.</p>
|
144
|
+
<% end %>
|
145
|
+
<% end %>
|
146
|
+
```
|
147
|
+
|
148
|
+
## Credits
|
149
|
+
|
150
|
+
Slotify was heavily influenced by (and borrows some code from) the excellent [nice_partials gem](https://github.com/bullet-train-co/nice_partials). It provides similar functionality to Slotify so if you are not convinced by what you see here then go check it out!
|
data/lib/slotify.rb
ADDED
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slotify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Perkins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/slotify.rb
|
21
|
+
- lib/slotify/version.rb
|
22
|
+
homepage:
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.1.0
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.3.3
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A superpowered slot system for Rails partials.
|
45
|
+
test_files: []
|