├── pulp_web ├── .gitignore ├── package.json ├── assets.js ├── package-lock.json ├── events.js ├── types.js └── pulp.js ├── .gitignore ├── examples ├── with_npm │ ├── .gitignore │ ├── go.mod │ ├── README.md │ ├── run.sh │ ├── web │ │ ├── index.js │ │ ├── package.json │ │ ├── index.html │ │ ├── package-lock.json │ │ └── bundle.js │ ├── build │ │ └── main.go │ ├── main.go │ └── go.sum └── with_bundle │ ├── web │ ├── index.js │ ├── index.html │ └── pulp.js │ ├── run.sh │ ├── go.mod │ ├── build │ └── main.go │ ├── main.go │ └── go.sum ├── bundle.sh ├── cmd ├── run │ └── main.go └── gen │ ├── main.go │ └── replace.go ├── go.mod ├── LICENSE ├── todo.md ├── socket.go ├── lexer.go ├── gen.go ├── dynamic_test.go ├── parser.go ├── go.sum ├── dynamic.go ├── pulp.go └── README.md /pulp_web/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | pulp.bundle.js -------------------------------------------------------------------------------- /examples/with_npm/.gitignore: -------------------------------------------------------------------------------- 1 | web/node_modules/ -------------------------------------------------------------------------------- /bundle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | 3 | browserify pulp_web/pulp.js > pulp.bundle.js -------------------------------------------------------------------------------- /cmd/run/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | // TODO 5 | } 6 | -------------------------------------------------------------------------------- /examples/with_bundle/web/index.js: -------------------------------------------------------------------------------- 1 | const socket = new Pulp.PulpSocket("mount", "/socket", { debug: true }) -------------------------------------------------------------------------------- /examples/with_bundle/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | 3 | gen -in main.go -out build/main.go && go run build/main.go 4 | -------------------------------------------------------------------------------- /examples/with_npm/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/maltecl/pulp/examples/npm 2 | 3 | go 1.16 4 | 5 | require github.com/maltecl/pulp v0.0.3 6 | -------------------------------------------------------------------------------- /examples/with_bundle/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/maltecl/pulp/examples/npm 2 | 3 | go 1.16 4 | 5 | require github.com/maltecl/pulp v0.0.3 6 | -------------------------------------------------------------------------------- /examples/with_npm/README.md: -------------------------------------------------------------------------------- 1 | # With npm 2 | 3 | 4 | Make sure to install the npm dependency before running `run.sh`: 5 | ```sh 6 | cd web && npm i 7 | ``` -------------------------------------------------------------------------------- /examples/with_npm/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | 3 | browserify web/index.js > web/bundle.js && gen -in main.go -out build/main.go && go run build/main.go 4 | -------------------------------------------------------------------------------- /examples/with_npm/web/index.js: -------------------------------------------------------------------------------- 1 | const { PulpSocket, events } = require("pulp_web") 2 | 3 | 4 | const socket = new PulpSocket("mount", "/socket", { debug: false }) -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/maltecl/pulp 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/google/go-cmp v0.5.6 7 | github.com/gorilla/websocket v1.4.2 8 | github.com/kr/pretty v0.2.1 9 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c 10 | golang.org/x/tools v0.1.5 11 | ) 12 | -------------------------------------------------------------------------------- /pulp_web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pulp_web", 3 | "version": "0.0.2", 4 | "description": "", 5 | "main": "pulp.js", 6 | "scripts": {}, 7 | "author": "malte.l", 8 | "license": "ISC", 9 | "dependencies": { 10 | "morphdom": "2.6.1" 11 | } 12 | } -------------------------------------------------------------------------------- /examples/with_npm/web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with_npm", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "dependencies": { 10 | "pulp_web": "0.0.2" 11 | }, 12 | "author": "malte.l", 13 | "license": "ISC" 14 | } 15 | -------------------------------------------------------------------------------- /pulp_web/assets.js: -------------------------------------------------------------------------------- 1 | class Assets { 2 | 3 | constructor(obj) { 4 | this.cache = obj 5 | } 6 | 7 | 8 | patch(patches) { 9 | let newAssets = {...this.cache } 10 | 11 | for (const key in patches) { 12 | if (patches[key] === null) { // this element should be deleted 13 | delete newAssets[key] 14 | } else { // new or old element. overwrite it 15 | newAssets[key] = patches[key] 16 | } 17 | } 18 | 19 | return new Assets(newAssets) 20 | } 21 | 22 | } 23 | 24 | 25 | module.exports = { Assets } -------------------------------------------------------------------------------- /examples/with_npm/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 |