rjweb-server
Version:
Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS
45 lines (44 loc) • 1.07 kB
JavaScript
import HTMLBuilder from "./HTMLBuilder";
class HTMLComponent {
/**
* Create a new HTML Component
* @example
* ```
* // component.js
* module.exports = new HTMLComponent((html, options) => html
* .t('p', {}, options.text)
* )
*
* // index.js
* const component = require('./component.js')
* const controller = new Server({ })
*
* controller.path('/', (path) => path
* .http('GET', '/', (http) => http
* .onRequest((ctr) => {
* ctr.printHTML((html) => html
* .t('h1', {}, 'Hello matey!')
* .c(component, { text: 'lol' })
* )
* })
* )
* )
* ```
* @since 6.7.0
*/
constructor(callback) {
this.callback = callback;
}
/**
* Internal Method for Generating HTML Builder
* @since 6.7.0
*/
toBuilder(route, fnArguments, getEvery, getEveryId, options) {
const builder = new HTMLBuilder(route, fnArguments, getEvery, getEveryId);
this.callback(builder, options);
return builder;
}
}
export {
HTMLComponent as default
};