1.0.15 • Published 3 years ago

tyche-js v1.0.15

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

IMPORTANT

tyche-js is in an early alpha!

v1.013 is the first partly stable version.

A basic HTML Framework.

Setup

Install

npm i tyche-js

Create Project

npx tyche create

Start DevServer

npx tyche start

Create a page

Create

/components/app.html

Basic HTML

<!app.html->
<h2>Hello world!</h2>

Configure

Add page app in tyche.json.

{
    "frontend": {
        "pages": {
            "app": {
                "index": "app.html"
            }
        }
    }
}

Backend

Configure

Set the backend port to 3000 and add a route to serve page app.

{
    "frontend": {
        "pages": {
            "app": {
                "index": "app.html"
            }
        }
    },
    "backend": {
        "port": 3000,
        "routes": {
            "/": "app"
        }
    }
}

Dynamic Page

Process the page before sending it to the user. tyche.json

{
    "frontend": {...},
    "backend": {
        "routes": {
            "/": {
                "dynamic": true,
                "handler": "handler.js",
                "page": "app"   /*default page (optional)*/
            }
        }
    }
}

Create new file handler.js.

const {TychePage, TycheHTML} = require('tyche-js');

function handle(defaultPage, req) {
    //add your own logic here
    if(isAllowed(req)) return defaultPage;
    else return new TychePage(TycheHTML.of('<h2>Not allowed!</h2>'));
}

module.exports = handle;

Meta

Add Title to page

{
    "frontend": {
        "meta": {
            "title": "Tyche",  /*set default title*/
            "charset": "UTF-8"  /*set default charset*/
        }
        "pages": {
            "app": {
                "meta": {
                    "title": "App"  /*set title for this page.*/
                }
                "index": "app.html"
            }
        }
    },
    backend": {...}
}

Link components

Link app.css in app.html

<!app.html->
<link location="app.css" type="style"/>
<h2>Hello world!</h2>

Link component.html in app.html

<!app.html->
<link location="app.css" type="style"/>
<h2>Hello world!</h2>
<div>
    <link location="component.html"/>
</div>

States

Note: States work only in dynamic pages.

Define state username in app.html

<define name="username"/>
<link location="app.css" type="style"/>
<h2>Hello <username/>!</h2>
<div>
    <link location="component.html"/>
</div>

Set State

Set state username inside handler.js

const {TychePage, TycheHTML} = require('tyche-js');

function handle(defaultPage, req) {
    //add your own logic here
    if(isAllowed(req)) return defaultPage.setProps({"username": getUsername()});
    else return new TychePage(TycheHTML.of('<h2>Not allowed!</h2>'));
}

module.exports = handle;
1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago