Skip to content

Commit 2c94326

Browse files
committed
Add list() and other helpful view funcs
1 parent dde543c commit 2c94326

File tree

3 files changed

+85
-25
lines changed

3 files changed

+85
-25
lines changed

apps/components_guide_web/assets/css/app.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ input {
3434
text-shadow: 0.0625em 0.0625em 0.125em rgba(0,0,0,0.25);
3535
}
3636

37+
ul:not([class]) {
38+
@apply list-disc;
39+
}
40+
ul:not([class]) > li > ul:not([class]) {
41+
@apply pl-8;
42+
}
43+
3744
/* @import "./phoenix.css"; */

apps/components_guide_web/lib/components_guide_web/templates/links/index.html.eex

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</section>
1919

2020
<section class="container pt-8 pb-16 text-2xl">
21-
<article class="mb-8 text-orange-700 a{font-bold}">
21+
<%= article class: "text-orange-700" do %>
2222
<h2 class="text-4xl leading-normal font-bold text-orange-800 border-b-4 border-orange-200">SwiftUI</h2>
2323

2424
<h3 class="mt-4 mb-2 text-2xl leading-normal italic">WWDC 2019</h3>
@@ -41,34 +41,41 @@
4141
<li><%= link "SwiftUI by Example: free quick start tutorials for Swift developers", to: "https://www.hackingwithswift.com/quick-start/swiftui" %></li>
4242
<li><%= link "SwiftUI Hub", to: "https://swiftuihub.com/" %></li>
4343
</ul>
44-
</article>
44+
<% end %>
4545

46-
<article class="mb-8 text-red-700 a{font-bold}">
46+
<%= article class: "text-red-700" do %>
4747
<h2 class="text-4xl leading-normal font-bold text-red-800 border-b-4 border-red-200">Combine</h2>
4848

4949
<h3 class="mt-4 mb-2 text-2xl leading-normal italic">WWDC 2019</h3>
50-
<ul class="list-disc nums-tabular">
51-
<li><%= link "415: Modern Swift API Design", to: "https://developer.apple.com/videos/play/wwdc2019/415/" %></li>
52-
<li><%= link "722: Introducing Combine", to: "https://developer.apple.com/videos/play/wwdc2019/722/" %></li>
53-
<li><%= link "721: Combine in Practice", to: "https://developer.apple.com/videos/play/wwdc2019/721/" %></li>
54-
<li><%= link "712: Advances in Networking, Part 1", to: "https://developer.apple.com/videos/play/wwdc2019/712/" %></li>
55-
</ul>
50+
<%= list [
51+
link(span("415: Modern Swift API Design", [:nums_tabular]), to: "https://developer.apple.com/videos/play/wwdc2019/415/"),
52+
link(span("722: Introducing Combine", [:nums_tabular]), to: "https://developer.apple.com/videos/play/wwdc2019/722/"),
53+
link(span("721: Combine in Practice", [:nums_tabular]), to: "https://developer.apple.com/videos/play/wwdc2019/721/"),
54+
link(span("712: Advances in Networking, Part 1", [:nums_tabular]), to: "https://developer.apple.com/videos/play/wwdc2019/712/"),
55+
] %>
5656

5757
<h3 class="mt-6 mb-2 text-2xl leading-normal italic">Articles</h3>
58-
<ul class="list-disc">
59-
<li><%= link "22 short tests of Combine – Part 1: Protocols", to: "https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-1.html" %></li>
60-
<li><%= link "22 short tests of Combine – Part 2: Sharing", to: "https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-2.html" %></li>
61-
</ul>
58+
<%= list [
59+
link("22 short tests of Combine – Part 1: Protocols", to: "https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-1.html"),
60+
link("22 short tests of Combine – Part 2: Sharing", to: "https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-2.html"),
61+
link("22 short tests of Combine – Part 3: Asynchrony", to: "https://www.cocoawithlove.com/blog/twenty-two-short-tests-of-combine-part-3.html"),
62+
] %>
6263

6364
<h3 class="mt-6 mb-2 text-2xl leading-normal italic">Tools and libraries for Combine</h3>
64-
<ul class="list-disc">
65-
<li><%= link "Joe Heck’s in-depth Combine notes", to: "https://heckj.github.io/swiftui-notes/" %></li>
66-
<li><%= link "RxSwift to Combine Cheat Sheet", to: "https://github.com/freak4pc/rxswift-to-combine-cheatsheet" %></li>
67-
<li><%= link "Entwine: Testing tools and utilities for Apple's Combine framework", to: "https://github.com/tcldr/Entwine" %></li>
68-
</ul>
69-
</article>
65+
<%= list [
66+
{
67+
link("Joe Heck’s in-depth notes", to: "https://heckj.github.io/swiftui-notes/"),
68+
[
69+
link("Tests for Publishers & Subscribers", to: "https://github.com/heckj/swiftui-notes/tree/master/UsingCombineTests")
70+
]
71+
},
72+
link("RxSwift to Combine cheat sheet", to: "https://github.com/freak4pc/rxswift-to-combine-cheatsheet"),
73+
link("Entwine: Testing tools and utilities", to: "https://github.com/tcldr/Entwine"),
74+
] %>
75+
76+
<% end %>
7077

71-
<article class="mb-8 text-blue-700 a{font-bold}">
78+
<%= article class: "text-blue-700" do %>
7279
<h2 class="text-4xl leading-normal font-bold text-blue-800 border-b-4 border-blue-200">React</h2>
7380

7481
<h3 class="mt-4 mb-2 text-2xl leading-normal italic">Overreacted by Dan Abramov</h3>
@@ -92,9 +99,9 @@
9299
<li><%= link "Uncontrolled Components", to: "https://reactjs.org/docs/uncontrolled-components.html" %></li>
93100
<li><%= link "Reconciliation", to: "https://reactjs.org/docs/reconciliation.html" %></li>
94101
</ul>
95-
</article>
102+
<% end %>
96103

97-
<article class="mb-8 text-pink-700 a{font-bold}">
104+
<%= article class: "text-pink-700" do %>
98105
<h2 class="text-4xl leading-normal font-bold text-pink-800 border-b-4 border-pink-200">RxJS</h2>
99106

100107
<h3 class="mt-6 mb-2 text-2xl leading-normal italic">Official Docs</h3>
@@ -112,9 +119,9 @@
112119
<li><%= link "Thinking reactive with the SIP principle", to: "https://blog.strongbrew.io/the-sip-principle/" %></li>
113120
<li><%= link "LearnRxJS.io", to: "https://www.learnrxjs.io/" %></li>
114121
</ul>
115-
</article>
122+
<% end %>
116123

117-
<article class="mb-8 text-indigo-700 a{font-bold}">
124+
<%= article class: "text-indigo-700" do %>
118125
<h2 class="text-4xl leading-normal font-bold text-indigo-800 border-b-4 border-indigo-200">TypeScript</h2>
119126

120127
<h3 class="mt-6 mb-2 text-2xl leading-normal italic">Handy references</h3>
@@ -123,6 +130,6 @@
123130
<li><%= link "The TypeScript Handbook", to: "https://www.typescriptlang.org/docs/handbook/basic-types.html" %></li>
124131
<li><%= link "TypeScript Deep Dive", to: "https://basarat.gitbooks.io/typescript/" %></li>
125132
</ul>
126-
</article>
133+
<% end %>
127134
</section>
128135
</div>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
11
defmodule ComponentsGuideWeb.LinksView do
22
use ComponentsGuideWeb, :view
3+
alias Phoenix.HTML.Tag
4+
alias Phoenix.HTML.Link
5+
6+
# def defsection(name, tag_name, attrs) do
7+
# Tag.content_tag(tag_name, "hello", attrs)
8+
# end
9+
10+
def article(attrs \\ [], do: block) do
11+
# %{class: class} = Enum.into(attrs, %{class: ""})
12+
class = Keyword.get(attrs, :class, "")
13+
14+
Tag.content_tag :article, class: "mt-8 mb-24 #{class} a{font-bold}" do
15+
block
16+
end
17+
end
18+
19+
def span(content, options) when is_list(options) do
20+
content_tag(:span, content, Enum.reduce(options, [class: ""], &span_option/2))
21+
end
22+
23+
defp span_option(:nums_tabular, tag_options) do
24+
Keyword.update!(tag_options, :class, fn class ->
25+
class <> " nums-tabular"
26+
end)
27+
end
28+
29+
defp list_item({{:safe, content}, nested_items}) when is_list(nested_items) do
30+
content_tag(:li) do
31+
[
32+
{:safe, content},
33+
list(nested_items)
34+
]
35+
end
36+
end
37+
38+
defp list_item({:safe, content}) do
39+
content_tag(:li, {:safe, content})
40+
end
41+
42+
def list(items) when is_list(items) do
43+
content_tag(:ul, Enum.map(items, &list_item/1))
44+
end
45+
46+
def nums_tabular(content) do
47+
content_tag(:span, content, class: "nums-tabular")
48+
end
349
end

0 commit comments

Comments
 (0)