Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples directory: LiveView & Nix #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/liveview.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule AppWeb.ExampleLive do
use Phoenix.LiveView

def mount(_params, _session, socket) do
# ...
{:ok, socket}
end

#...

def handle_event("generate_pdf", _params, %{assigns: assigns} = socket) do
# Passing the assigns to the method, so that the liveview render method can populate the template
generate_pdf(assigns)
{:noreply, socket}
end

def generate_pdf(assigns) do
# Assuming you have a stylesheet applied on the root template, you'll need to include this stylesheet
# in the rendered LiveView HTML
style = """
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
<link rel="stylesheet" href='/css/app.css'/>
"""
AppWeb.ExampleLive.render(assigns)
|> Phoenix.HTML.Safe.to_iodata()
|> List.to_string()
|> Kernel.<>(style)
|> PdfGenerator.generate!(page_size: "A4", generator: :chrome, prefer_system_executable: true)
end
end
2 changes: 2 additions & 0 deletions examples/nix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default:
node2nix -i node-packages.json --nodejs-13
17 changes: 17 additions & 0 deletions examples/nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file has been generated by node2nix 1.8.0. Do not edit!

{pkgs ? import <nixpkgs> {
inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-13_x"}:

let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
inherit nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages.nix {
inherit (pkgs) fetchurl fetchgit;
inherit nodeEnv;
}
Loading