Skip to content

Commit d6fba2c

Browse files
committed
Play with fun stuff in markdown engine
Could support custom elements and live view in the future
1 parent 0140121 commit d6fba2c

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

apps/components_guide_web/lib/components_guide_web/live/fake_search.ex

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@ defmodule ComponentsGuideWeb.FakeSearchLive do
55

66
def render(assigns) do
77
~L"""
8-
<p>UUID: <%= @uuid %></p>
9-
10-
<form phx-change="suggest" phx-submit="search">
11-
<label>
12-
Search:
13-
<input name="q" value="<%= @query %>">
14-
</label>
15-
</form>
16-
17-
<p><%= Enum.count(@filtered_items) %></p>
18-
19-
<ul>
20-
<%= for item <- @filtered_items do %>
21-
<li><%= item["body"] %></li>
22-
<% end %>
23-
</ul>
8+
<div class="bg-white text-black">
9+
<p>UUID: <%= @uuid %></p>
10+
11+
<form phx-change="suggest" phx-submit="search">
12+
<label>
13+
Search:
14+
<input name="q" value="<%= @query %>" class="border">
15+
</label>
16+
</form>
17+
18+
<p><%= Enum.count(@filtered_items) %></p>
19+
20+
<ul>
21+
<%= for item <- @filtered_items do %>
22+
<li><%= item["body"] %></li>
23+
<% end %>
24+
</ul>
25+
</div>
2426
"""
2527
end
2628

2729
defp new_uuid do
2830
Ecto.UUID.generate()
2931
end
3032

31-
def mount(%{}, _session, socket) do
33+
def mount(_, _session, socket) do
3234
#if connected?(socket), do: :timer.send_interval(5000, self(), :update)
3335

3436
items = FakeSearch.list()

apps/components_guide_web/lib/components_guide_web/template_engines/markdown_engine.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ defmodule ComponentsGuideWeb.TemplateEngines.MarkdownEngine do
77

88
def compile(path, _name) do
99
IO.puts("compile #{path}")
10-
path
10+
html = path
1111
|> File.read!()
1212
|> Earmark.as_html!(%Earmark.Options{code_class_prefix: "language-", smartypants: false})
13-
|> EEx.compile_string(engine: Phoenix.HTML.Engine, file: path, line: 1)
13+
14+
# regex = ~r{<live-([\w-]+)>(.+)</live-([\w-]+)>}
15+
regex = ~r{<live-([\w-]+)>([^<]+)</live-([^>]+)>}
16+
# regex = ~r{<live-([\w-]+)>}
17+
18+
html = Regex.replace(regex, html, fn whole, name, content -> name end)
19+
# html = Regex.replace(regex, html, fn whole, name, content -> "<div><%= live_render(@conn, ComponentsGuideWeb.FakeSearchLive, session: %{}) %></div>" end)
20+
21+
html |> EEx.compile_string(engine: Phoenix.HTML.Engine, file: path, line: 1)
22+
# html |> EEx.compile_string(engine: Phoenix.LiveView.Engine, file: path, line: 1)
1423
end
1524
end

0 commit comments

Comments
 (0)