Skip to content

Commit

Permalink
JSDocument Release 1.0.36
Browse files Browse the repository at this point in the history
  • Loading branch information
ADev531 committed Sep 4, 2023
0 parents commit f9023f1
Show file tree
Hide file tree
Showing 12 changed files with 590 additions and 0 deletions.
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# jsdocument
JSDocument!<br>
<br>
An Library for create page from node.js.<br>
<br>
how to use:<br>
var JSDocument = require('jsdocument') // Load Library<br>
var document = new JSDocument.JSDocument() // New Page!<br>
<br>
You created page, but it not running for now.<br>
<br>
-- before 1.0.3<br>
<code>
document.setresponsehandler(function() {<br>
document.SendDocument() // sends document to client<br>
}, '/')<br>
</code>
-- 1.0.3 ~~<br>
<code>
JSDocument.Server.SetResponseHandler('/' , function(){ // '/' means address<br>
return [document.GetRawHTML(), "html"] // returns raw html and type to server
}) // '/' - path, function() - handler<br>
</code>
<br>
Server is now Running!<br>
.....<br>
but empty?<br>

# Objects - jsdocument
<br>
No, you can create objects!<br>
<br>
<code>
new JSDocument.JSObjects.JSTitleObject() // creates new title object<br>
new JSDocument.JSObjects.JSScriptObject() // creates new script object<br>
new JSDocument.JSObjects.JSLinkObject(href, rel) // creates new link object (for linking css)<br>
new JSDocument.JSObjects.JSObject() // creates new div object<br>
new JSDocument.JSObjects.JSStyleObject() // creates new html-tag css object<br>
new JSDocument.JSObjects.JSVideoObject() // creates new HTML5 video tag<br>
... // and more!<br>
</code>
<br>
<code>
document.AddObject(Object) // adds object on body tag<br>
document.AddHeaderObject(Object) // adds object on head tag, use on title tag or script tag.<br>
</code>
<br>
Options:<br>
<code>
object.Attributes // < div (here) ><br>
object.ObjectType // Always 'JSDocument'<br>
object.SetType(new type) // Changes Type (ex: new JSDocument.JSObjects.JSObject().SetType("h1"))<br>
object.Text // innerHTML<br>
object.Type // HTML Object Type<br>
object.id // HTML element id<br>
object.class // HTML Class name<br>
object.AddObject(other object) // adds object on object<br>
</code>
<br>
Wait, you want use favicon and css?<br>

# Favicon and CSS - jsdocument
<br>
CSS -<br>
<code>
JSDocument.UseCSS(document object, css name (ex. 'index.css'), Server Object(on 1.0.3 ~))<br>
</code>
<br>
Favicon -<br>
<code>
JSDocument.UseIcon(document object, favicon name (ex. 'favicon.ico'), Server Object(on 1.0.3 ~))<br>
</code>
<br>
but, like JSVideoObject, some object needs file.

# Add Refrence - jsdocument
Simple!
<code>
JSDocument.AddRef(document object, file name, Server Object(on 1.0.33 ~))) // not supported on 1.0.3 ~ 1.0.32.
</code>
and now you can use that file.

# Simpler Page - jsdocument

<code>
new JSDocument.JSPage(server object)<br>
</code>
Same as JSDocument.JSDocument, but little diffrents.<br>
first, you need to use JSPage.GetJSDocumentObject() in addref, useicon, usecss.<br>
next, you can use JSPage.Deploy( address ).<br>
three, not uses JSTitleObject from JSObjects, it uses JSPage.SetTitle(title)!<br>
<br>
originally, JSDocument used express.js and on older version JSDocument better than JSPage (but older version not haves JSPage).<br>
<br>
# All-in-one Hello World example - jsdocument
<br>
<a href="https://github.com/ADev531/jsdocument-all-in-one-example">All-In-one</a>
14 changes: 14 additions & 0 deletions addref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var fs = require('fs')
var objects = require('./objects')

function AddRef(document, refname, server) {
if (fs.existsSync(refname)) {

server.SetResponseHandler(`/${refname}`, function() {
var d = fs.readFileSync(`${process.cwd()}/${iconpath}`, 'UTF8')
return [d, "default"];
})
}
}

module.exports = AddRef
115 changes: 115 additions & 0 deletions documentmanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const objects = require('./objects')
const server = require('./server')

var header = '<!DOCTYPE HTML>\n \
\ <html lang=\'en\'>\n \
\ <head>\n \
\ <meta charset="utf-8">\n \
\ <meta name="viewport" content="width=device-width, initial-scale=1.0">'

var bodytg = '\
\ </head>\n \
\ <body>\n'

var ending = ' </body>\n \
\ </html>'

const JSDocument = (function() {
var currentrep;
var currentreq;

function JSDocument() {
this.JSObjects = [];
this.JSHeaderObjects = [];
}

function AddObject(Object) {
if (Object.ObjectType != undefined && Object.ObjectType == "JSDocument") {
this.JSObjects.push(Object)
}
}
JSDocument.prototype.AddObject = AddObject;

function AddHeaderObject(Object) {
if (Object.ObjectType != undefined && Object.ObjectType == "JSDocument") {
this.JSHeaderObjects.push(Object)
}
}
JSDocument.prototype.AddHeaderObject = AddHeaderObject;

function GetRawResponse() {
return currentrep
}
JSDocument.prototype.GetRawResponse = GetRawResponse;

function GetRawHTML() {
var document = header;

this.JSHeaderObjects.forEach(function(v, i, array) {
var id = v.id ? ` id="${v.id}"` : ''
var classatrb = v.class ? ` class="${v.class}"` : ''
var tag = `<${v.Type} ${v.Attributes}${id}${classatrb}>${v.Text}</${v.Type}>\n`;
document += tag;
})

document += bodytg

this.JSObjects.forEach(function(v, i, array) {
var id = v.id ? ` id="${v.id}"` : ''
var classatrb = v.class ? ` class="${v.class}"` : ''
var tag = `<${v.Type} ${v.Attributes}${id}${classatrb}>${v.Text}</${v.Type}>\n`;
document += tag;
})

document += ending

return document;
}
JSDocument.prototype.GetRawHTML = GetRawHTML;
return JSDocument
}())

const JSPage = (function() {
function JSPage(server) {
this.document = new JSDocument();
this.server = server;
this.Title = new objects.JSTitleObject();
}

function UseCSS(cssname, usecss) {
usecss(this.document, cssname, this.server);
}
JSPage.prototype.UseCSS = UseCSS;

function AddHeaderObject(obj) {
this.document.AddHeaderObject(obj)
}
JSPage.prototype.AddHeaderObject = AddHeaderObject;

function AddObject(obj) {
this.document.AddObject(obj)
}
JSPage.prototype.AddObject = AddObject;

function SetTitle(txt) {
this.Title.Text = txt;
}
JSPage.prototype.SetTitle = SetTitle;

function GetJSDocumentObject() {
return this.document;
}
JSPage.prototype.GetJSDocumentObject = GetJSDocumentObject;

function Deploy(addr) {
var copy = this.document;
this.server.SetResponseHandler(addr, function() {
return [copy.GetRawHTML(), "html"]
})
}
JSPage.prototype.Deploy = Deploy;

return JSPage;
}())

module.exports = {JSDocument:JSDocument, JSPage:JSPage}
8 changes: 8 additions & 0 deletions libentry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var documentmgr = require('./documentmanager')
var objecttype = require('./objects')
var usecss = require('./usecss')
var seticon = require('./seticon')
var addref = require('./addref')
var server = require('./server')

module.exports = {JSDocument:documentmgr.JSDocument, JSPage:documentmgr.JSPage, JSObjects:objecttype, UseCSS:usecss, UseIcon:seticon, AddRef:addref, Server:server}
Loading

0 comments on commit f9023f1

Please sign in to comment.