Skip to content

Commit

Permalink
Added Stylesheet Component
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jan 16, 2024
1 parent a65598f commit 99958c2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
15 changes: 0 additions & 15 deletions lib/live_view_native/stylesheet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ defmodule LiveViewNative.Stylesheet do
|> inspect(limit: :infinity, charlists: :as_list, printable_limit: :infinity, pretty: pretty)
end

def embed_stylesheet(var!(assigns)) do
sheet =
__MODULE__
|> LiveViewNative.Stylesheet.file_path()
|> File.read!()

var!(assigns) = Map.put(var!(assigns), :sheet, sheet)

~LVN"""
<Style><%= @sheet %></Style>
"""
# Phoenix.HTML.raw("<Style>#{sheet}</Style>")
# LiveViewNative.Component.sigil_LVN("<Style>{@sheet}</Style>", [])
end

def __native_opts__ do
%{format: unquote(format)}
Expand All @@ -61,7 +47,6 @@ defmodule LiveViewNative.Stylesheet do
end
end


def filename(module) do
format = module.__native_opts__()[:format]

Expand Down
28 changes: 28 additions & 0 deletions lib/live_view_native/stylesheet/component.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule LiveViewNative.Stylesheet.Component do
@moduledoc """
Component functions for stylesheets
"""
import LiveViewNative.Component, only: [sigil_LVN: 2]

@doc """
Embed the stylesheet within a template
Take a module as an attribute value:
```heex
<.embed_stylsheet module={MyAppWeb.HomeSheet} />
```
"""
def embed_stylesheet(%{module: module} = assigns) do
sheet =
module
|> LiveViewNative.Stylesheet.file_path()
|> File.read!()

assigns = Map.put(assigns, :sheet, sheet)

~LVN"""
<Style><%= @sheet %></Style>
"""
end
end

0 comments on commit 99958c2

Please sign in to comment.