<h1 align="center">
<br>𖤐 domonic 𖤐<br>
</h1>
[![PyPI version](https://badge.fury.io/py/domonic.svg)](https://badge.fury.io/py/domonic.svg)
[![Downloads](https://pepy.tech/badge/domonic)](https://pepy.tech/project/domonic)
[![Python version](https://img.shields.io/pypi/pyversions/domonic.svg?style=flat)](https://img.shields.io/pypi/pyversions/domonic.svg?style=flat)
[![Build status](https://travis-ci.com/byteface/domonic.svg?branch=master)](https://travis-ci.com/byteface/domonic.svg?branch=master)
[![Python package](https://github.com/byteface/domonic/actions/workflows/python-package.yml/badge.svg?branch=master)](https://github.com/byteface/domonic/actions/workflows/python-package.yml)
#### A DOM for making HTML with python 3! (and more)
### Install
```bash
python3 -m pip install domonic
# python3 -m pip install domonic --upgrade
```
## Creating HTML with Python 3
```python
from domonic.html import *
print(html(body(h1('Hello, World!'))))
# <html><body><h1>Hello, World!</h1></body></html>
```
or to pretty format and insert the doctype, use an f-string:
```python
mydom = html(body(h1('Hello, World!'), a("somelink", _href="somepage.html")))
print(f"{mydom}")
```
```html
<!DOCTYPE html>
<html>
<body>
<h1>Hello, World!</h1>
<a href="somepage.html">somelink</a>
</body>
</html>
```
### parsing html
Basic useage...
```bash
from domonic import domonic
mydom = domonic.parseString('<somehtml...')
```
To quickly parse a webapge try the window module...
```bash
from domonic.window import window
window.location = "http://www.google.com"
print(window.document.title)
```
Also try the xpath or css selectors on command line...
```bash
domonic -x https://google.com '//a' | uniq | sort
```
### More
- [html](https://domonic.readthedocs.io/_modules/domonic/html.html) : Generate html with python 3 😎
- [dom](https://domonic.readthedocs.io/_modules/domonic/dom.html) : DOM API in python 3 😲
- [javascript](https://domonic.readthedocs.io/_modules/domonic/javascript.html) : js API in python 3 😳 + ([dQuery](https://domonic.readthedocs.io/packages/dQuery.html), [d3](https://domonic.readthedocs.io/packages/d3.html))
- JSON : utils for loading / decorating / transforming
- SVG || mathml || aframe || x3d tags - generators for popular tags
- terminal || cmd : call terminal commands with python3 😱
See the [docs/code](https://domonic.readthedocs.io/) for more features...
or examples in the [repo...](https://github.com/byteface/domonic/tree/master/examples)
### Namespace
Use the tags packaage if you want a namespace. i.e.
```python
import domonic.tags
print(domonic.tags.h1)
# or
import domonic.tags as tags
str(tags.div)
# or
import domonic.tags as html
print(html.span)
```
or just import what you need...
```python
from domonic import div, span, input as myinput, html as root
```
### html attributes
prepend attributes with an underscore ( avoids clashing with python keywords )
```python
test = label(_class='classname', _for="someinput")
print(test)
```
```html
<label class="classname" for="someinput"></label>
```
### rendering DOM objects
domonic is a pure python dom whos tree is composed of objects. i.e
```python
div()
# <domonic.html.div object at 0x106b0e6b0>
```
cast str() on any element to render it without formatting.
```python
el = str(div())
print(el)
# <div></div>
```
There's also a render method that takes 2 parameters, some domonic and an optional output file.
```python
page = div(span('Hello World'))
render(f"{page}", 'index.html') # notice use of f-string to pretty print the html
```
There's a few new rendering options. See DOMConfig.
```python
from domonic.dom import DOMConfig
print(DOMConfig.GLOBAL_AUTOESCAPE) # Default False
print(DOMConfig.RENDER_OPTIONAL_CLOSING_TAGS) # Default True
print(DOMConfig.RENDER_OPTIONAL_CLOSING_SLASH) # Defaults True
print(DOMConfig.SPACE_BEFORE_OPTIONAL_CLOSING_SLASH) # Default False
```
## DOM
DOM manipulation with python.
### createElement
to create your own elements use the DOM API
```python
from domonic.dom import *
site = html()
el = document.createElement('myelement')
site.appendChild(el)
print(site)
# <html><myelement></myelement></html>
```
There's an evolving DOM API. To learn more about the webAPI [click here](https://developer.mozilla.org/en-US/docs/Web/API).
And check the [code/docs](https://domonic.readthedocs.io/) to see what's currently been implemented.
```python
mysite.querySelectorAll('button')
mysite.querySelectorAll("a[rel=nofollow]")
mysite.querySelectorAll("a[href='#services']")
mysite.querySelectorAll("a[href$='technology']")
mysite.querySelectorAll('.fa-twitter')
somelinks = mysite.querySelectorAll("a[href*='twitter']")
for l in somelinks:
print(l.href)
```
To use the DOM either reference your root 'html' node or import the dom modules global 'document'
```python
# access the document via the html tag
mydom = html()
# mydom.getElementbyID...
# or by importing the document global
from domonic.dom import document
# document.createElement...
print(document)
```
### javascript
There is a javascript package that mimics the js API:
```python
from domonic.javascript import Math
print(Math.random())
from domonic.javascript import Array
myArr=Array(1,2,3)
print(myArr.splice(1))
# [2, 3]
from domonic.javascript import URL
url = URL('https://somesite.com/blog/article-one#some-hash')
print(url.protocol) # https
print(url.host) # somesite.com
print(url.pathname) # /blog/article-one
print(url.hash) # #some-hash
# Use Global class to import all the js methods from the global namespace i.e
# from domonic.javascript import Global
# Global.decodeURIComponent(...
# Global.encodeComponent(...
# Global.setInterval(...
# from domonic.javascript import Date, String, Number
# etc..
```
Use setInterval and clearInterval with params
```python
from domonic.javascript import setInterval, clearInterval
x=0
def hi(inc):
global x
x = x+inc
print(x)
test = setInterval(hi, 1000, 2)
import time
time.sleep(5)
clearInterval(test)
print(f"Final value of x:{x}")
```
Or for a single delayed function call use setTimeout, clearTimeout
```python
from domonic.javascript import setTimeout, clearTimeout
timeoutID = setTimeout(hi, 1000)
```
You can call ```()``` on a stringvar to transform it into a Node
```python
from domonic.javascript import String
test = String("Hi there!")
test('div', _style="font-color:red;")
str(test('div', _style="font-color:red;"))
# <div style="font-color:red;">Hi there!</div>
```
a-tags inherit URL:
```python
from domonic.html import *
atag = a(_href="https://somesite.com:8000/blog/article-one#some-hash")
print('href:', atag.href)
# href: https://somesite.com:8000/blog/article-one#some-hash
print('protocol:', atag.protocol)
# protocol: https:
print('port:', atag.port)
# port: 8000
atag.protocol = "http"
atag.port = 8983
print(atag)
# <a href="http://somesite.com:8983/blog/article-one#some-hash">
```
For writing and using regular javascript, load from a src...
```python
script(_src="/docs/5.0/dist/js/bootstrap.bundle.min.js", _integrity="sha384-1234", _crossorigin="anonymous"),
# <script src="/docs/5.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-1234" crossorigin="anonymous"></script>
```
or do inline js by opening triple quotes...
```python
script("""
let itbe = ""
"""),
```
### Styling
Styling is supported. Styles get passed to the style tag on render...
```python
mytag = div("hi", _id="test")
mytag.style.backgroundColor = "black"
mytag.style.fontSize = "12px"
print(mytag)
# <div id="test" style="background-color:black;font-size:12px;">hi</div>
```
To use css use a link tag as you usually would...
```python
link(_href="styles.css", _rel="stylesheet"),
```
or use triple quotes to open style tag...
```python
style("""
.placeholder-img {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
"""),
```
### decorators
use decorators to wrap elements around function results
```python
from domonic.decorators import el
@el(html, True)
@el(body)
@el(div)
def test():
return 'hi!'
print(test())
# <html><body><div>hi!</div></body></html>
# returns pyml objects so call str to render
assert str(test()) == '<html><body><div>hi!</div></body></html>'
```
It returns the tag object by default. You can pass True as a second param to the decorator to return a rendered string instead. Also accepts strings as first param i.e. custom tags.
### data-tags
python doesn't allow hyphens in parameter names. so use variable keyword argument syntax for custom data-tags
```python
div("test", **{"_data-test":"test"} )
# <div data-test="test">test</div>
```
or for example a colon...
```python
t = div( **{"_:test":"something"} )
str(t)
# <div :test="something"></div>
```
### JSON (utils)
decorate any function that returns python objects to return json instead
```python
from domonic.decorators import as_json
import domonic.JSON as JSON
@as_json
def somefunc():
myObj = {"hi":[1,2,3]}
return myObj
print( somefunc() )
# {"hi":[1,2,3]}
print( JSON.is_json(somefunc()) )
# True
```
convert json arrays into html tables...
```python
import domonic.JSON as JSON
# i.e. containting flat json array of dicts... [{"id":"01","name": "some item"},{"id":"02","name": "some other item"}]
json_data = JSON.parse_file('somefile.json')
mytable = JSON.tablify(json_data)
print(mytable)
```
convert json arrays into csv files...
```python
import domonic.JSON as JSON
json_data = JSON.parse_file('somefile.json')
JSON.csvify(json_data, 'data.csv')
```
convert csv files to json...
```python
import domonic.JSON as JSON
json_data =JSON.csv2json("data.csv")
print(json_data)
```
more to come...
### SVG
All tags extend 'Element'. So will have DOM and magic methods available to them. See the [docs](https://domonic.readthedocs.io/).
```python
circ = svg(
circle(_cx="50", _cy="50", _r="40", _stroke="green", **{"_stroke-width": "4"}, _fill="yellow"),
_width="100", _height="100",
)
mysvg = svg()
mysvg.appendChild(circ / 10)
print(mysvg)
```
### Tweening
Tween values with the tween library:
```python
from domonic.lerpy.easing import *
from domonic.lerpy.tween import *
someObj = {'x':0,'y':0,'z':0}
twn = Tween( someObj, { 'x':10, 'y':5, 'z':3 }, 6, Linear.easeIn )
twn.start()
```
### aframe / x3d
3d tags can be used if you import the js
```python
from domonic.html import *
from domonic.xml.aframe import *
from domonic.CDN import *
_scene = scene(
box(_position="-1 0.5 -3", _rotation="0 45 0", _color="#4CC3D9"),
sphere(_position="0 1.25 -5", _radius="1.25", _color="#EF2D5E"),
cylinder(_position="1 0.75 -3", _radius="0.5", _height="1.5", _color="#FFC65D"),
plane(_position="0 0 -4", _rotation="-90 0 0", _width="4", _height="4", _color="#7BC8A4"),
sky(_color="#ECECEC")
)
_webpage = html(head(),body(
script(_src=CDN_JS.AFRAME_1_2), # < NOTICE you need to import aframe to use it
str(_scene)
)
)
render( _webpage, 'hello.html' )
```
### dQuery (NEW)
dQuery uses the º symbol (alt+0).
```python
from domonic.html import *
from domonic.dQuery import º
d = html(head(body(li(_class='things'), div(_id="test"))))
print( º('#test') )
# <div id="test">
print( º('.things') )
# <li class="things">
mydiv = º('<div class="test2"></div>')
# <domonic.dQuery.o object at 0x107d5c9a0>
b = º('#test').append(mydiv)
print(b)
# <div id="test"><div class="test2"></div></div>
```
Only recently started so check to see what's implemented.
### terminal
There is a command line package that can call bash/unix/posix and other apps on the command line:
This package only works on nix systems as it effectively just passes stuff off to subprocess.
```python
from domonic.terminal import *
print(ls())
print(ls("-al"))
print(ls("../"))
print(pwd())
print(mkdir('somedir'))
print(touch('somefile'))
print(git('status'))
for file in ls( "-al" ):
print("Line : ", file)
for f in ls():
try:
print(f)
print(cat(f))
except Exception as e:
pass
for i, l in enumerate(cat('LICENSE.txt')):
print(i,l)
print(man("ls"))
print(echo('test'))
print(df())
print(du())
for thing in du():
print(thing)
print(find('.'))
# print(ping('eventual.technology'))# < TODO - need to strean output
print(cowsay('moo'))
# print(wget('eventual.technology'))
print(date())
print(cal())
```
or just run arbitrary commands...
```python
from domonic.terminal import command
command.run("echo hi")
```
Take a look at the code in 'terminal.py' to see all the commands as there's loads. (Disclaimer: not all tested.)
Windows users can use now use cmd.
```python
from domonic.cmd import *
print(dir())
print(dir("..\\"))
```
### DOCS
[https://domonic.readthedocs.io/](https://domonic.readthedocs.io/)
### CLI
Use the command line interface to help you out.
To view the online the docs:
```python
domonic -h
```
To see the version:
```bash
domonic -v
```
To quickly create a domonic project for prototyping:
```bash
domonic -p myproject
```
To evaluate some domonic pyml:
```bash
domonic -e 'html(head(),body(div()))'
```
To use xpath on a website from the command line:
```bash
domonic -x https://google.com '//a'
```
To use css selectors on a website from the command line:
```bash
domonic -q https://google.com 'a'
```
### EXAMPLE PROJECTS
[Blueberry](https://github.com/byteface/Blueberry/) : A browser based file OS. Working example of how components can work.
[ezcron](https://github.com/byteface/ezcron/) : A cron viewer
[bombdisposer](https://github.com/byteface/bombdisposer/) : A basic game
[htmlx](https://github.com/byteface/htmlx/tree/master/htmlx) : A low dependency lightweight (DOM only) version of domonic
Checkout [the docs](https://domonic.readthedocs.io/) for more examples i.e. generating sitemaps or using domonic with server frameworks like flask, django, sanic, fastapi and others.
There's also several useage examples in the repo so pull and have a look.
### Join-In
Feel free to contribute if you find it useful. (I'd be grateful for help on all fronts)
Email me, message me directly if you like or create a discussion on here. Or join the [discord](https://discord.gg/a9pSZv4V5f).
If there are any methods you want that are missing or not complete yet or you think you can help make it better just update the code and send a pull request. I'll merge and releaese asap.
In the repo there's a requirements-dev.txt which is mostly the libs used in the examples.
requirements.txt are the libs used for packaging just the lib.
See also the CONTRIBUTING.md
### running examples
```bash
. venv/bin/activate
pip install -r requirements-dev.txt
cd examples
python lifecalendar.py
```
### run tests
There are tests used during dev. They are useful as code examples and to see what still needs doing.
See Makefile to run all tests:
```bash
make test # default tests ubuntu. so will fail on window when terminal test runs. comment out locally if that's the case
```
or to test a single function:
```bash
python -m unittest tests.test_javascript.TestCase.test_javascript_array
python -m unittest tests.test_dQuery.TestCase.test_addClass
python -m unittest tests.test_geom.TestCase.test_vec2
python3 -m unittest tests.test_cmd.TestCase.test_cmd_dir # only windows
```
or to test a whole module
```bash
python -m unittest tests.test_html
python -m unittest tests.test_CDN
```
to see coverage
```bash
coverage run -m unittest discover tests/
coverage report
```
or...
```bash
pip install pytest
pytest tests
```
### Disclaimer
There's several more widely supported libraries doing HTML generation, DOM reading/manipulation, terminal wrappers etc. Maybe use one of those for production due to strictness and support.
This is more of a fast prototyping library.
Raw data
{
"_id": null,
"home_page": "https://github.com/byteface/domonic",
"name": "domonic",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "html, generate, templating, dom, vdom, terminal, json, web, template, javascript, DOM, GUI, render, website, apps, html5, framework, SVG, x3d, events, geom",
"author": "@byteface",
"author_email": "byteface@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4d/df/3241c1c91e5375c10f313e7d688f52e9a06c1a6f3277bf26d326db2c5127/domonic-0.9.13.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">\n <br>\ud81a\udd10 domonic \ud81a\udd10<br>\n</h1>\n\n[![PyPI version](https://badge.fury.io/py/domonic.svg)](https://badge.fury.io/py/domonic.svg)\n[![Downloads](https://pepy.tech/badge/domonic)](https://pepy.tech/project/domonic)\n[![Python version](https://img.shields.io/pypi/pyversions/domonic.svg?style=flat)](https://img.shields.io/pypi/pyversions/domonic.svg?style=flat)\n[![Build status](https://travis-ci.com/byteface/domonic.svg?branch=master)](https://travis-ci.com/byteface/domonic.svg?branch=master)\n[![Python package](https://github.com/byteface/domonic/actions/workflows/python-package.yml/badge.svg?branch=master)](https://github.com/byteface/domonic/actions/workflows/python-package.yml)\n\n#### A DOM for making HTML with python 3! (and more)\n\n### Install\n\n```bash\npython3 -m pip install domonic\n# python3 -m pip install domonic --upgrade \n```\n\n## Creating HTML with Python 3\n\n```python\nfrom domonic.html import *\nprint(html(body(h1('Hello, World!'))))\n# <html><body><h1>Hello, World!</h1></body></html>\n```\n\nor to pretty format and insert the doctype, use an f-string:\n\n```python\nmydom = html(body(h1('Hello, World!'), a(\"somelink\", _href=\"somepage.html\")))\nprint(f\"{mydom}\")\n```\n\n```html\n<!DOCTYPE html>\n<html>\n\t<body>\n\t\t<h1>Hello, World!</h1>\n\t\t<a href=\"somepage.html\">somelink</a>\n\t</body>\n</html>\n```\n\n### parsing html\n\nBasic useage...\n\n```bash\nfrom domonic import domonic\nmydom = domonic.parseString('<somehtml...')\n```\n\nTo quickly parse a webapge try the window module...\n\n```bash\nfrom domonic.window import window\nwindow.location = \"http://www.google.com\"\nprint(window.document.title)\n```\n\nAlso try the xpath or css selectors on command line...\n\n```bash\ndomonic -x https://google.com '//a' | uniq | sort\n```\n\n### More\n\n- [html](https://domonic.readthedocs.io/_modules/domonic/html.html) : Generate html with python 3 \ud83d\ude0e\n- [dom](https://domonic.readthedocs.io/_modules/domonic/dom.html) : DOM API in python 3 \ud83d\ude32\n- [javascript](https://domonic.readthedocs.io/_modules/domonic/javascript.html) : js API in python 3 \ud83d\ude33 + ([dQuery](https://domonic.readthedocs.io/packages/dQuery.html), [d3](https://domonic.readthedocs.io/packages/d3.html))\n- JSON : utils for loading / decorating / transforming\n- SVG || mathml || aframe || x3d tags - generators for popular tags\n- terminal || cmd : call terminal commands with python3 \ud83d\ude31\n\nSee the [docs/code](https://domonic.readthedocs.io/) for more features...\n\nor examples in the [repo...](https://github.com/byteface/domonic/tree/master/examples)\n\n\n### Namespace\n\nUse the tags packaage if you want a namespace. i.e.\n\n```python\nimport domonic.tags\nprint(domonic.tags.h1)\n# or\nimport domonic.tags as tags\nstr(tags.div)\n# or \nimport domonic.tags as html\nprint(html.span)\n```\n\nor just import what you need...\n\n```python\nfrom domonic import div, span, input as myinput, html as root\n```\n\n### html attributes\n\nprepend attributes with an underscore ( avoids clashing with python keywords )\n\n```python\ntest = label(_class='classname', _for=\"someinput\")\nprint(test)\n```\n\n```html\n<label class=\"classname\" for=\"someinput\"></label>\n```\n\n### rendering DOM objects\n\ndomonic is a pure python dom whos tree is composed of objects. i.e\n\n```python\ndiv()\n# <domonic.html.div object at 0x106b0e6b0>\n```\n\ncast str() on any element to render it without formatting.\n\n```python\nel = str(div())\nprint(el)\n# <div></div>\n```\n\nThere's also a render method that takes 2 parameters, some domonic and an optional output file.\n\n```python\npage = div(span('Hello World'))\nrender(f\"{page}\", 'index.html') # notice use of f-string to pretty print the html\n```\n\nThere's a few new rendering options. See DOMConfig.\n\n```python\nfrom domonic.dom import DOMConfig\nprint(DOMConfig.GLOBAL_AUTOESCAPE) # Default False\nprint(DOMConfig.RENDER_OPTIONAL_CLOSING_TAGS) # Default True\nprint(DOMConfig.RENDER_OPTIONAL_CLOSING_SLASH) # Defaults True\nprint(DOMConfig.SPACE_BEFORE_OPTIONAL_CLOSING_SLASH) # Default False\n```\n\n## DOM\n\nDOM manipulation with python.\n\n### createElement\n\nto create your own elements use the DOM API\n\n```python\nfrom domonic.dom import *\n\nsite = html()\nel = document.createElement('myelement')\nsite.appendChild(el)\nprint(site)\n# <html><myelement></myelement></html>\n\n```\n\nThere's an evolving DOM API. To learn more about the webAPI [click here](https://developer.mozilla.org/en-US/docs/Web/API).\n\nAnd check the [code/docs](https://domonic.readthedocs.io/) to see what's currently been implemented.\n\n```python\nmysite.querySelectorAll('button') \nmysite.querySelectorAll(\"a[rel=nofollow]\")\nmysite.querySelectorAll(\"a[href='#services']\")\nmysite.querySelectorAll(\"a[href$='technology']\")\nmysite.querySelectorAll('.fa-twitter')\n\nsomelinks = mysite.querySelectorAll(\"a[href*='twitter']\")\nfor l in somelinks:\n print(l.href)\n```\n\nTo use the DOM either reference your root 'html' node or import the dom modules global 'document'\n\n```python\n\n# access the document via the html tag\nmydom = html()\n# mydom.getElementbyID...\n\n# or by importing the document global\nfrom domonic.dom import document\n# document.createElement...\nprint(document)\n```\n\n### javascript\n\nThere is a javascript package that mimics the js API:\n\n```python\nfrom domonic.javascript import Math\nprint(Math.random())\n\nfrom domonic.javascript import Array\nmyArr=Array(1,2,3)\nprint(myArr.splice(1))\n# [2, 3]\n\nfrom domonic.javascript import URL\nurl = URL('https://somesite.com/blog/article-one#some-hash')\nprint(url.protocol) # https\nprint(url.host) # somesite.com\nprint(url.pathname) # /blog/article-one\nprint(url.hash) # #some-hash\n\n# Use Global class to import all the js methods from the global namespace i.e\n# from domonic.javascript import Global\n# Global.decodeURIComponent(...\n# Global.encodeComponent(...\n# Global.setInterval(...\n\n# from domonic.javascript import Date, String, Number\n# etc..\n```\n\nUse setInterval and clearInterval with params\n\n```python\nfrom domonic.javascript import setInterval, clearInterval\n\nx=0\n\ndef hi(inc):\n global x\n x = x+inc\n print(x)\n\ntest = setInterval(hi, 1000, 2)\nimport time\ntime.sleep(5)\nclearInterval(test)\nprint(f\"Final value of x:{x}\")\n```\n\nOr for a single delayed function call use setTimeout, clearTimeout\n\n```python\nfrom domonic.javascript import setTimeout, clearTimeout\ntimeoutID = setTimeout(hi, 1000)\n```\n\nYou can call ```()``` on a stringvar to transform it into a Node\n\n```python\nfrom domonic.javascript import String\n\ntest = String(\"Hi there!\")\ntest('div', _style=\"font-color:red;\")\nstr(test('div', _style=\"font-color:red;\"))\n# <div style=\"font-color:red;\">Hi there!</div>\n```\n\na-tags inherit URL:\n\n```python\nfrom domonic.html import *\n\natag = a(_href=\"https://somesite.com:8000/blog/article-one#some-hash\")\nprint('href:', atag.href)\n# href: https://somesite.com:8000/blog/article-one#some-hash\nprint('protocol:', atag.protocol)\n# protocol: https:\nprint('port:', atag.port)\n# port: 8000\n\natag.protocol = \"http\"\natag.port = 8983\nprint(atag)\n# <a href=\"http://somesite.com:8983/blog/article-one#some-hash\">\n```\n\nFor writing and using regular javascript, load from a src...\n\n```python\nscript(_src=\"/docs/5.0/dist/js/bootstrap.bundle.min.js\", _integrity=\"sha384-1234\", _crossorigin=\"anonymous\"),\n# <script src=\"/docs/5.0/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-1234\" crossorigin=\"anonymous\"></script>\n```\n\nor do inline js by opening triple quotes...\n\n```python\nscript(\"\"\"\nlet itbe = \"\"\n\"\"\"),\n```\n\n### Styling\n\nStyling is supported. Styles get passed to the style tag on render...\n\n```python\nmytag = div(\"hi\", _id=\"test\")\nmytag.style.backgroundColor = \"black\"\nmytag.style.fontSize = \"12px\"\nprint(mytag)\n# <div id=\"test\" style=\"background-color:black;font-size:12px;\">hi</div>\n```\n\nTo use css use a link tag as you usually would...\n\n```python\nlink(_href=\"styles.css\", _rel=\"stylesheet\"),\n```\n\nor use triple quotes to open style tag...\n\n```python\nstyle(\"\"\"\n.placeholder-img {\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\"\"\"),\n```\n\n### decorators\n\nuse decorators to wrap elements around function results\n\n```python\nfrom domonic.decorators import el\n\n@el(html, True)\n@el(body)\n@el(div)\ndef test():\n return 'hi!'\n\nprint(test())\n# <html><body><div>hi!</div></body></html>\n\n# returns pyml objects so call str to render\nassert str(test()) == '<html><body><div>hi!</div></body></html>'\n```\n\nIt returns the tag object by default. You can pass True as a second param to the decorator to return a rendered string instead. Also accepts strings as first param i.e. custom tags.\n\n### data-tags\n\npython doesn't allow hyphens in parameter names. so use variable keyword argument syntax for custom data-tags\n\n```python\ndiv(\"test\", **{\"_data-test\":\"test\"} )\n# <div data-test=\"test\">test</div>\n```\n\nor for example a colon...\n\n```python\nt = div( **{\"_:test\":\"something\"} )\nstr(t)\n# <div :test=\"something\"></div>\n```\n\n### JSON (utils)\n\ndecorate any function that returns python objects to return json instead\n\n```python\nfrom domonic.decorators import as_json\nimport domonic.JSON as JSON\n\n@as_json\ndef somefunc():\n myObj = {\"hi\":[1,2,3]}\n return myObj\n\nprint( somefunc() )\n# {\"hi\":[1,2,3]}\nprint( JSON.is_json(somefunc()) )\n# True\n```\n\nconvert json arrays into html tables...\n\n```python\nimport domonic.JSON as JSON\n\n# i.e. containting flat json array of dicts... [{\"id\":\"01\",\"name\": \"some item\"},{\"id\":\"02\",\"name\": \"some other item\"}]\n\njson_data = JSON.parse_file('somefile.json')\nmytable = JSON.tablify(json_data)\nprint(mytable)\n```\n\nconvert json arrays into csv files...\n\n```python\nimport domonic.JSON as JSON\n\njson_data = JSON.parse_file('somefile.json')\nJSON.csvify(json_data, 'data.csv')\n```\n\nconvert csv files to json...\n\n```python\nimport domonic.JSON as JSON\n\njson_data =JSON.csv2json(\"data.csv\")\nprint(json_data)\n```\n\nmore to come...\n\n### SVG\n\nAll tags extend 'Element'. So will have DOM and magic methods available to them. See the [docs](https://domonic.readthedocs.io/).\n\n```python\ncirc = svg(\n circle(_cx=\"50\", _cy=\"50\", _r=\"40\", _stroke=\"green\", **{\"_stroke-width\": \"4\"}, _fill=\"yellow\"),\n _width=\"100\", _height=\"100\",\n)\nmysvg = svg()\nmysvg.appendChild(circ / 10)\nprint(mysvg)\n```\n\n### Tweening\n\nTween values with the tween library:\n\n```python\nfrom domonic.lerpy.easing import *\nfrom domonic.lerpy.tween import *\n\nsomeObj = {'x':0,'y':0,'z':0}\ntwn = Tween( someObj, { 'x':10, 'y':5, 'z':3 }, 6, Linear.easeIn )\ntwn.start()\n```\n\n### aframe / x3d\n\n3d tags can be used if you import the js\n\n```python\nfrom domonic.html import *\nfrom domonic.xml.aframe import *\nfrom domonic.CDN import *\n\n_scene = scene(\n box(_position=\"-1 0.5 -3\", _rotation=\"0 45 0\", _color=\"#4CC3D9\"),\n sphere(_position=\"0 1.25 -5\", _radius=\"1.25\", _color=\"#EF2D5E\"),\n cylinder(_position=\"1 0.75 -3\", _radius=\"0.5\", _height=\"1.5\", _color=\"#FFC65D\"),\n plane(_position=\"0 0 -4\", _rotation=\"-90 0 0\", _width=\"4\", _height=\"4\", _color=\"#7BC8A4\"),\n sky(_color=\"#ECECEC\")\n )\n\n_webpage = html(head(),body(\n script(_src=CDN_JS.AFRAME_1_2), # < NOTICE you need to import aframe to use it\n str(_scene)\n )\n)\n\nrender( _webpage, 'hello.html' )\n```\n\n### dQuery (NEW)\n\ndQuery uses the \u00ba symbol (alt+0).\n\n```python\nfrom domonic.html import *\nfrom domonic.dQuery import \u00ba\n\nd = html(head(body(li(_class='things'), div(_id=\"test\"))))\n\nprint( \u00ba('#test') )\n# <div id=\"test\">\nprint( \u00ba('.things') )\n# <li class=\"things\">\nmydiv = \u00ba('<div class=\"test2\"></div>')\n# <domonic.dQuery.o object at 0x107d5c9a0>\n\nb = \u00ba('#test').append(mydiv)\nprint(b)\n# <div id=\"test\"><div class=\"test2\"></div></div>\n```\n\nOnly recently started so check to see what's implemented.\n\n### terminal\n\nThere is a command line package that can call bash/unix/posix and other apps on the command line:\n\nThis package only works on nix systems as it effectively just passes stuff off to subprocess.\n\n```python\nfrom domonic.terminal import *\n\nprint(ls())\nprint(ls(\"-al\"))\nprint(ls(\"../\"))\nprint(pwd())\nprint(mkdir('somedir'))\nprint(touch('somefile'))\nprint(git('status'))\n\nfor file in ls( \"-al\" ):\n print(\"Line : \", file)\n\nfor f in ls():\n try:\n print(f)\n print(cat(f))\n except Exception as e:\n pass\n\nfor i, l in enumerate(cat('LICENSE.txt')):\n print(i,l)\n\nprint(man(\"ls\"))\nprint(echo('test'))\nprint(df())\nprint(du())\n\nfor thing in du():\n print(thing)\n\nprint(find('.'))\n# print(ping('eventual.technology'))# < TODO - need to strean output\nprint(cowsay('moo'))\n# print(wget('eventual.technology'))\nprint(date())\nprint(cal())\n```\n\nor just run arbitrary commands...\n\n```python\nfrom domonic.terminal import command\ncommand.run(\"echo hi\")\n```\n\nTake a look at the code in 'terminal.py' to see all the commands as there's loads. (Disclaimer: not all tested.)\n\nWindows users can use now use cmd.\n\n```python\nfrom domonic.cmd import *\nprint(dir())\nprint(dir(\"..\\\\\")) \n```\n\n### DOCS\n\n[https://domonic.readthedocs.io/](https://domonic.readthedocs.io/)\n\n### CLI\n\nUse the command line interface to help you out.\n\nTo view the online the docs:\n\n```python\ndomonic -h\n```\n\nTo see the version:\n\n```bash\ndomonic -v\n```\n\nTo quickly create a domonic project for prototyping:\n\n```bash\ndomonic -p myproject\n```\n\nTo evaluate some domonic pyml:\n\n```bash\ndomonic -e 'html(head(),body(div()))'\n```\n\nTo use xpath on a website from the command line:\n\n```bash\ndomonic -x https://google.com '//a'\n```\n\nTo use css selectors on a website from the command line:\n\n```bash\ndomonic -q https://google.com 'a'\n```\n\n### EXAMPLE PROJECTS\n\n[Blueberry](https://github.com/byteface/Blueberry/) : A browser based file OS. Working example of how components can work.\n\n[ezcron](https://github.com/byteface/ezcron/) : A cron viewer\n\n[bombdisposer](https://github.com/byteface/bombdisposer/) : A basic game\n\n[htmlx](https://github.com/byteface/htmlx/tree/master/htmlx) : A low dependency lightweight (DOM only) version of domonic\n\nCheckout [the docs](https://domonic.readthedocs.io/) for more examples i.e. generating sitemaps or using domonic with server frameworks like flask, django, sanic, fastapi and others.\n\nThere's also several useage examples in the repo so pull and have a look.\n\n### Join-In\n\nFeel free to contribute if you find it useful. (I'd be grateful for help on all fronts)\n\nEmail me, message me directly if you like or create a discussion on here. Or join the [discord](https://discord.gg/a9pSZv4V5f).\n\nIf there are any methods you want that are missing or not complete yet or you think you can help make it better just update the code and send a pull request. I'll merge and releaese asap.\n\nIn the repo there's a requirements-dev.txt which is mostly the libs used in the examples.\n\nrequirements.txt are the libs used for packaging just the lib.\n\nSee also the CONTRIBUTING.md\n\n### running examples\n\n```bash\n. venv/bin/activate\npip install -r requirements-dev.txt\ncd examples\npython lifecalendar.py\n```\n\n### run tests\n\nThere are tests used during dev. They are useful as code examples and to see what still needs doing.\n\nSee Makefile to run all tests:\n\n```bash\nmake test # default tests ubuntu. so will fail on window when terminal test runs. comment out locally if that's the case\n```\n\nor to test a single function:\n\n```bash\npython -m unittest tests.test_javascript.TestCase.test_javascript_array\npython -m unittest tests.test_dQuery.TestCase.test_addClass\npython -m unittest tests.test_geom.TestCase.test_vec2\npython3 -m unittest tests.test_cmd.TestCase.test_cmd_dir # only windows\n```\n\nor to test a whole module\n\n```bash\npython -m unittest tests.test_html\npython -m unittest tests.test_CDN\n```\n\nto see coverage\n\n```bash\ncoverage run -m unittest discover tests/\ncoverage report\n```\n\nor...\n\n```bash\npip install pytest\npytest tests\n```\n\n\n### Disclaimer\n\nThere's several more widely supported libraries doing HTML generation, DOM reading/manipulation, terminal wrappers etc. Maybe use one of those for production due to strictness and support.\n\nThis is more of a fast prototyping library.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Generate html with python 3. DOM API, Javascript API and more...",
"version": "0.9.13",
"project_urls": {
"Download": "https://github.com/byteface/domonic/archive/0.9.13.tar.gz",
"Homepage": "https://github.com/byteface/domonic"
},
"split_keywords": [
"html",
" generate",
" templating",
" dom",
" vdom",
" terminal",
" json",
" web",
" template",
" javascript",
" dom",
" gui",
" render",
" website",
" apps",
" html5",
" framework",
" svg",
" x3d",
" events",
" geom"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "01881cb26f6952cf02c4ffda125435781e836f2b31c4c4dbf3715a69bf504555",
"md5": "81d56bd1f6ee5eb9f8a17c72187042dd",
"sha256": "cddf4ce90ee975ef602aa8f04f431aab1de747c3f3988ecff017b7db982c0571"
},
"downloads": -1,
"filename": "domonic-0.9.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "81d56bd1f6ee5eb9f8a17c72187042dd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 314980,
"upload_time": "2024-12-08T01:03:34",
"upload_time_iso_8601": "2024-12-08T01:03:34.758997Z",
"url": "https://files.pythonhosted.org/packages/01/88/1cb26f6952cf02c4ffda125435781e836f2b31c4c4dbf3715a69bf504555/domonic-0.9.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4ddf3241c1c91e5375c10f313e7d688f52e9a06c1a6f3277bf26d326db2c5127",
"md5": "8fb9e1200949f186b0567512a878dcbb",
"sha256": "b17e158a09da4d16fc014724e54f2a35753cd4b804959fe3f93e48a4076e6135"
},
"downloads": -1,
"filename": "domonic-0.9.13.tar.gz",
"has_sig": false,
"md5_digest": "8fb9e1200949f186b0567512a878dcbb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 359026,
"upload_time": "2024-12-08T01:03:37",
"upload_time_iso_8601": "2024-12-08T01:03:37.225678Z",
"url": "https://files.pythonhosted.org/packages/4d/df/3241c1c91e5375c10f313e7d688f52e9a06c1a6f3277bf26d326db2c5127/domonic-0.9.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-08 01:03:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "byteface",
"github_project": "domonic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "elementpath",
"specs": [
[
"~=",
"4.6.0"
]
]
},
{
"name": "python-dateutil",
"specs": [
[
"==",
"2.9.0.post0"
]
]
},
{
"name": "requests",
"specs": [
[
"~=",
"2.32.3"
]
]
},
{
"name": "urllib3",
"specs": [
[
"~=",
"2.2.3"
]
]
},
{
"name": "html5lib",
"specs": [
[
"~=",
"1.1"
]
]
},
{
"name": "cssselect",
"specs": [
[
"~=",
"1.2.0"
]
]
}
],
"lcname": "domonic"
}