Skip to content

Commit

Permalink
clean up example, use flake-parts
Browse files Browse the repository at this point in the history
  • Loading branch information
buntec committed Feb 29, 2024
1 parent f6d8029 commit 9ab8582
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 84 deletions.
43 changes: 22 additions & 21 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -1,24 1,25 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>ff4s-example</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>

<head>
<meta charset="UTF-8">
<title>ff4s-example</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>

<body>
<div id="app"></div>
<script type="text/javascript">
var process = {
env: {
'CATS_EFFECT_TRACING_MODE': 'NONE',
'FF4S_DEBUG': 'TRUE',
}
};
var ff4s_state;
</script>
<script type="text/javascript" src="target/scala-2.13/examples-fastopt/main.js"></script>
</body>

<body>
<div id="app"></div>
<script type="text/javascript">
var process = {
env: {
CATS_EFFECT_TRACING_MODE: "NONE",
FF4S_DEBUG: "TRUE",
},
};
var ff4s_state;
</script>
<script
type="text/javascript"
src="target/scala-3.3.1/examples-fastopt/main.js"
></script>
</body>
</html>
22 changes: 12 additions & 10 deletions examples/src/main/scala/examples/example1/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,7 @@ class App[F[_]: Async] extends ff4s.App[F, State, Action] {
import html._ // nice syntax for html tags, attributes etc.

// Define some classes for easy re-use.
val paragraphCls = "max-w-3xl my-2"
val linkCls = "text-pink-500"
val subHeadingCls = "text-center text-2xl mt-4 mb-2"
val buttonCls =
Expand All @@ -50,12 51,13 @@ class App[F[_]: Async] extends ff4s.App[F, State, Action] {
val welcome =
h1( // All common html tags are available thanks to scala-dom-types.
cls := "m-4 text-4xl", // Some tailwindcss utility classes.
"Hello from ff4s 👋" // Strings are valid child nodes, of course.
"Hello 👋" // Strings are valid child nodes, of course.
)

val intro = div(
cls := "m-4 text-center",
p(
cls := paragraphCls,
"ff4s lets you write web front-ends in a purely functional style using ",
a(
cls := linkCls,
Expand All @@ -76,16 78,16 @@ class App[F[_]: Async] extends ff4s.App[F, State, Action] {
href := "https://github.com/raquo/scala-dom-types",
"Scala DOM Types"
),
". Rendering is based on the ",
" project. Rendering is efficient thanks to the ",
a(
cls := linkCls,
href := "https://github.com/snabbdom/snabbdom",
href := "https://github.com/buntec/scala-js-snabbdom",
"Snabbdom"
),
" virtual DOM."
" virtual DOM library."
),
p(
cls := "mt-4",
cls := paragraphCls,
"This is a minimal SPA built with ff4s. Please check out the ",
a(cls := linkCls, href := "https://github.com/buntec/ff4s", "code"),
" to see how it all works."
Expand All @@ -100,10 102,10 @@ class App[F[_]: Async] extends ff4s.App[F, State, Action] {
cls := "m-4",
h2(
cls := subHeadingCls,
"A simple counter"
"A counter"
),
p(
s"The counter stands at ${state.counter}. Click the buttons to increment or decrement the counter."
s"The counter stands at ${state.counter}. Click the buttons to increment or decrement."
),
div(
cls := "flex flex-row justify-center",
Expand Down Expand Up @@ -250,8 252,8 @@ class App[F[_]: Async] extends ff4s.App[F, State, Action] {
// separate import for SVG tags and attributes.
// Note the curly braces defining a new scope.
// Html syntax can still be accessed through fully-qualified names.
import svg.{svg => svgTag, _}
svgTag(
import svg.{svg => _, _}
svg.svg(
height := "100",
width := "100",
circle(
Expand Down Expand Up @@ -325,7 327,7 @@ class App[F[_]: Async] extends ff4s.App[F, State, Action] {
}

override val view = div(
cls := "p-4 flex flex-col items-center bg-no-repeat h-full bg-gradient-to-tr from-gray-200 to-sky-300 text-gray-800 font-light",
cls := "p-4 flex flex-col items-center bg-no-repeat h-full bg-gradient-to-tr from-gray-200 to-sky-300 text-gray-700 font-light",
welcome,
magicAlert,
intro,
Expand Down
37 changes: 37 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 33 additions & 38 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,48 1,43 @@
{
inputs = {
devenv.url = "github:cachix/devenv";
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
devenv.url = "github:cachix/devenv";
};

nixConfig = {
extra-trusted-public-keys =
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
outputs = { self, nixpkgs, devenv, systems, flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {

imports = [ inputs.devenv.flakeModule ];

systems = nixpkgs.lib.systems.flakeExposed;

perSystem = { config, self', inputs', pkgs, system, ... }: {

devenv.shells.default = {

outputs = { self, nixpkgs, devenv, systems, ... }@inputs:
let forEachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = forEachSystem (system: {
devenv-up = self.devShells.${system}.default.config.procfileScript;
});

devShells = forEachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [{
packages = with pkgs; [ nodePackages.live-server ];

languages = {
java.enable = true;
java.jdk.package = pkgs.jdk;
scala.enable = true;
nix.enable = true;
};

scripts.watch-examples.exec = ''
sbt '~examples/fastLinkJS'
'';

scripts.serve-examples.exec = ''
live-server ./examples/ --port=8080 --entry-file=index.html
'';

}];
packages = with pkgs; [ nodePackages.live-server ];

languages = {
java.enable = true;
java.jdk.package = pkgs.jdk;
scala.enable = true;
nix.enable = true;
};
});

scripts.watch-examples.exec = ''
sbt '~examples/fastLinkJS'
'';

scripts.serve-examples.exec = ''
live-server ./examples/ --port=8080 --entry-file=index.html
'';

};

};

};
}

31 changes: 16 additions & 15 deletions todo-mvc/index.html
Original file line number Diff line number Diff line change
@@ -1,18 1,19 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>todo-mvc</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/index.css"
/>
</head>

<head>
<meta charset="UTF-8">
<title>todo-mvc</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/index.css" />
</head>

<body>
<div id="app"></div>
<script type="text/javascript">
var process = {env: {'CATS_EFFECT_TRACING_MODE': 'NONE'}};
</script>
<script type="text/javascript" src="target/scala-2.13/todomvc-fastopt/main.js"></script>
</body>

<body>
<div id="app"></div>
<script
type="text/javascript"
src="target/scala-2.13/todomvc-fastopt/main.js"
></script>
</body>
</html>

0 comments on commit 9ab8582

Please sign in to comment.