Skip to content

Commit

Permalink
fix: hide Erlang target on JS
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Aug 10, 2024
1 parent c95b621 commit f3bd058
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions e2e/web_application/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand All @@ -8,7 +8,7 @@

<!-- Uncomment this if you add the TailwindCSS integration -->
<!-- <link rel="stylesheet" href="/priv/static/stylesheet_render.css"> -->
<script type="module" src="/priv/static/stylesheet_render.mjs"></script>
<script type="module" src="/priv/static/web_application.mjs"></script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
Expand Down
26 changes: 18 additions & 8 deletions sketch/src/sketch.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,32 @@ pub fn class(styles: List(style.Style)) -> Class {
style.class(styles)
}

@target(javascript)
/// Render the content in the cache in proper CSS stylesheet.
pub fn render(cache: Cache) {
case cache {
BeamCache(cache:) -> cache.render(cache)
JsCache(cache:) -> style.render(cache)
}
let assert JsCache(cache:) = cache
style.render(cache)
}

@target(erlang)
pub fn render(cache: Cache) {
let assert BeamCache(cache:) = cache
cache.render(cache)
}

@target(javascript)
/// Convert a `Class` to its proper class name, to use it anywhere in your
/// application. It can have the form `class1` or `class1 class2` in case of
/// classes composition.
pub fn class_name(class: Class, cache: Cache) -> #(Cache, String) {
case cache {
JsCache(c) -> style.class_name(class, c) |> pair.map_first(JsCache)
BeamCache(c) -> cache.class_name(class, c) |> pair.map_first(BeamCache)
}
let assert JsCache(c) = cache
style.class_name(class, c) |> pair.map_first(JsCache)
}

@target(erlang)
pub fn class_name(class: Class, cache: Cache) -> #(Cache, String) {
let assert BeamCache(c) = cache
cache.class_name(class, c) |> pair.map_first(BeamCache)
}

/// Strategy for the Cache. Two strategies are available as of now: ephemeral
Expand Down

0 comments on commit f3bd058

Please sign in to comment.