Mikoblocks is a minimal library to programmatically generate html.
Project description
Mikoblocks is a minimal library to programmatically generate html. It is unopinionated and outputs pure html code and due to a small simple syntax the programming is much easier and clearer to type compared to html. It allows assembling of component "blocks" which can nest further components within, allowing complex reusable pieces to be shared across pages and projects.
const { Block } = import('mikoblocks');
class MikoblocksExamplePage extends Block {
constructor() {
super();
this.raw('<!doctype html>');
let html = this.tag('html');
let head = html.tag('head');
let body = html.tag('body');
body.tag('div', { id: "content", class: "example-class" }).raw("Hello World!");
}
}
let page = new MikoblocksExamplePage();
console.log(page.toHtml());
Installation
npm install mikoblocks
Uses
Mikoblocks can be used as a prebuild process to output static html pages and it can also be run on the server dynamically to generate html at runtime.
- Programmatically generate your entire website from one script. Define components for header, footer, menus, buttons whatever you like and combine them all to output your entire page.
- Use mikoblocks on the server to dynamically generate pages with common shared elements.
Guide
Mikoblocks elegantly only uses 4 functions.
Block
A block is a beginning structure of a mikoblock, on it's own it has no output but can hold a list of sub-blocks. This is what empowers it over dom programming in that a block be be an element akin to an object or a list of elements akin to a list.
Tag
A tag is any xml tag that has a paired closing tag. You define the tag name and any attributes on the block itself.
Void
A void is any xml block that doesn't have a closing tag. You define the tag name and any attributes on the block itself.
Raw
Raw outputs text, it can hold text representations of further html or be the text between the opening and closing of an html block.
Outputs
Any mikoblock can use the .toHtml() function to output text based html of itself and all nested blocks. That's it, pretty simple huh?
toHtml()
Outputs the block into html text including all nested blocks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mikoblocks-0.1.2.tar.gz
.
File metadata
- Download URL: mikoblocks-0.1.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b16adbd31081c2f31561e69b6478047c95f3ff59189c3da657a9250947657b |
|
MD5 | a49d2ec923cd63660bc552222ff53987 |
|
BLAKE2b-256 | 63715fb7ed8a08ea1864f1b7db3f099fea6d8fb325c10651aa16cf1c96a3f735 |
File details
Details for the file mikoblocks-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: mikoblocks-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b18c8a0770184a24f8a1322133c58a7977d79dddd518dca3418d1a3ca19c118c |
|
MD5 | 860d7425025b70be7453a9190ddb0dc0 |
|
BLAKE2b-256 | 23de479b90558dd649547ef68c2015d407df1da34779a1a3a1ee00b1c5516dea |