Docs
You can use the Ejs and the Razor syntax with your pages, components and templates freely. Examples:
Ejs
<%for(const i of [1,2,3]){%>
<p>I am number: <%=i%>, and safe write is <%: i %></p>
<%}%>
Razor @for(const i of [1,2,3]){
<p>I am number: @i, and safe write is @:i</p>
}
After you create a template, you can use it by adding a template set to a page.
To set a placeholder at you're model, you do it like that:
<&placeholder_name />
Then you can insert data to the placeholder.
You can insert data like the example with the model, OR with a short tag like that:
<@head /> <script src="myscript.js"></script>
<@placeholder_name /> data that go in the templates
<@body /> <p>this is my data of the body tag</p>
<div>More Data</div>
You can create Components to make you're codding easier.
To call a component start the tag with 'comp:' + component_name
The components is html (file) with variables.
If you want to create variables, you doing that like that: '*' + 'the variable name'
<link rel="stylesheet" href="/files/*path.css" />
So, if I will insert css tag (the components file name 'css')
<comp:css path="bootstrap/bootstrap.min"/>
It will compile to:
<link rel="stylesheet" href="/files/bootstrap/bootstrap.min.css" />
<&Reader/>
The reader is the way to get the inside elements inside of the components
My Box component
<div>
<p>*title</p>
<div class="main-in-box"><&reader/><div>
</dive>
<Box title="My new box">
<p>This is inside the box</p>
</Box>
It will compile to:
<div>
<p>My new box</p>
<div class="main-in-box">
<p>This is inside the box</p>
<div>
</dive>
You can add a dynamic script corse all components and templates
data-template
<%let response = :myData:%>
@response
sample-page
@{&myData: 'Hey ' + Request.query.name}
The compiled page script will be:
<%let response = 'Hey ' + Request.query.name%>
@response
You can create custom libs or use public libs and use them across all of your websites
Libs example:
function test(){
write('test me');
}
exports.test = test;
In this example we exporting the "test" method.
Page or other lib import:
Libs:
<button><%module.TestPrint.test()%></button>
Global
Basic Methods
uuidv4(): string // create unique id
Logs
console.log(...info)
console.error(...info)
console.warn(...info)
console.info(...info)
Request & Response
Request: {
query: Object,
url: String (Pathname),
body: Object,
cookies: Object,
method: String
}
Response: {
code: Number (response status codes - 200, 404, 500 ...),
contentType: String ('html' / 'json' ...),
setCookie(name, info, {maxAge: Number(milliseconds), httpOnly: boolean}),
clearCookie(name),
setHeader(name, value: string | number | string[]),
sendFile(Buffer, contentType)
}
Global packages
You can learn more at
got in github. ReadHttp = got.get, PostHttp = got.post. ReadHttp(url, options)
PostHttp(url, options)
FormData //npm package: form-data
Email Sending
You can send up to 50 anonymous email a day from '
[email protected]' and unlimited email from your own service.
'email' filed can be array of emails
async sendAnonymousEmail(email, subject, body, isText = false): {error, info}
class EmailService {
constructor({?service, ?host, port = 465}, user, pass, ?{secure = true, defaultAlias = user, tls = {rejectUnauthorized: true}})
async sendHTML(email, subject, htmlMessage): {error, info}
async sendText(email, subject, textMessage): {error, info}
}
service - "Gmail" | "Outlook365" | "Yahoo" | "Yandex" | "AOL"
... you need 'host' or 'service'
Response Data
SetResponse(info)
write(info)
safeWrite(info)
sendBuffer(Buffer)
Redirect(path)
JS Template Function
- wTemp(template): void // write to the page
- eTemp(template): string // same as 'wTemp' only return string instead of writing to the page
If you want to use template that write to the page in js you can use 'wTemp' method.
For example:
wTemp `the user name is: ${userName}, have a nice day`;
This will output same as this:
the user name is: <%=userName%>, have a nice day
You can use safe output with ':'. You can use '::' to escape that
For example:
wTemp `the user name is: :${userName}, have a nice day`;
This will output same as this:
the user name is: <%:userName%>, have a nice day
Database methods
DB = {
async Insert(table, values): id
async InsertMany(table, values[]): id[]
async Select(table, where, ?{limit = 80, types}): any[]
async SelectAllById(table, ids, ?{where, limit, types}): any[]
async SelectOne(table, where, ?types): any[]
async SelectById(table, id, ?types): any[]
async Search(table, {where, query, attribute}, ?{limit, types}): any[]
async UpdateById(table, id, values, where): void
async UpdateAllById(table, ids_value, where): void
async UpdateAll(table, values, where): void
async DeleteById(table, id, where): void
async DeleteAll(table, where): void
async DeleteAllById(table, ids, where): void
}
Explanation
info = can be text or object
types = attributes to get
attribute = the name of the attribute, you want to search in
where = object of values that in the item
values = Object of values, example {name: 'myName' ...}
ids = array of id
ids_value = object of id, value -> {[key: id]: values}
**you don't need to create table to add values to it
**every item in the database have this attributes:
- id: unique id of the item
- create: date of creation in milliseconds
- update: date of update in milliseconds
Where Conditions - not a value - {attribute: {$not: value}}
- not one of the array values - {attribute: {$notIn: [...values]}}
- one of the array values - {attribute: {$in: [...values]}}
- greater than - {attribute: {$gt: number}}
- greater than or equals - {attribute: {$gte: number}}
- less than - {attribute: {$lt: number}}
- less than or equals - {attribute: {$gte: number}}
- attribute exits - {attribute: {$exists: boolean}}
- or for attribute - {attribute: {$or: [equals, {$not: value}...]}}
- and for attribute - {attribute: {$and: [{$gt: number}, {$not: value}...]}}
or in global - {$or: [{attribute: {$not: 9}}, {lt: 5}]}
Update Values Actions You can use all that in one update
- set a value - {$set: Map}
- Add a number - {$add: Map}
- remove a attributes - {$remove: [...string] | string}
You can also use {$type: 'set' | 'add', ...values} instead. The default value of $type is 'set'.
Connecting to SQL database
template = JS template function
For example:
execute`update files set name = ${nameValue} where id = ${idValue}`
MSSQLServer (global class)
class MSSQLServer {
constructor(server, database, user, password, ?{ encrypt = true, useUTC = true, trustServerCertificate = false, ...
others })
async execute(template)
/*example response
{
recordsets: [ [ [Object], [Object]] ],
recordset: [
{ id: 1, filename: "file1"},
{ id: 2, filename: "file2" }
],
output: {},
rowsAffected: [ 2 ]
}*/
async insert(template): number
async affected(template): number
async select(template): any[]
}
PostgresSQL (global class)
class PostgresServer {
constructor(server, database, user, password, ?{ parseInputDatesAsUTC = true, ...
others })
async execute(template)
/*example response
{
command: 'INSERT',
rowCount: 1,
oid: 0,
rows: [ {id: 2, filename: 'file2'}],
fields: [
...
{
name: 'id',
tableID: 253147,
columnID: 1,
dataTypeID: 23,
dataTypeSize: 4,
dataTypeModifier: -1,
format: 'text'
},
{
name: 'filename',
tableID: 253147,
columnID: 2,
dataTypeID: 25,
dataTypeSize: -1,
dataTypeModifier: -1,
format: 'text'
} ],
RowCtor: null,
rowAsArray: false
}*/
async insert(template): number
async affected(template): number
async select(template): any[]
}
You can make a API call with custom parameters on https://fp.w-on.uk/api/MY_PAGE_ID
OR to https://fp.w-on.uk/api/MY_WEBSITE_ID/MY_PAGE_ID To make sure the request page is one of your website's pages
MY_PAGE_ID = The page you want to make the api call in
GET - Request parameters {
mathod: String,
path: String
}
POST - Request parameters {
mathod: String,
path: String,
body: Object, // the main body of page on POST method
query: Object,
headers: String[]
}
The online editor is code mirror, you have a couple of available shortcut you can use:
Control-Q = Full Screen
Control-S = Save