domonic


Namedomonic JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/byteface/domonic
SummaryGenerate html with python 3. DOM API, Javascript API and more...
upload_time2021-09-26 13:39:55
maintainer
docs_urlNone
author@byteface
requires_python>=3.6
licenseMIT
keywords html generate templating dom vdom terminal json web template javascript dom gui render website apps html5 framework svg x3d events geom
VCS
bugtrack_url
requirements python-dateutil requests urllib3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">
    <img src="https://image.freepik.com/free-vector/demonic-goat_71119-56.jpg"
    style="background-color:rgba(0,0,0,0);" height=230 alt="domonic: generate html with python 3!">
    <br>
    domonic
    <br>
    <sup><sub><sup>Generate html with python 3! (and much more)</sup></sub></sup>
    <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)


#### Contains several evolving packages:

• [html](https://domonic.readthedocs.io/_modules/domonic/html.html) : Generate html with python 3 😎 <br />
• [dom](https://domonic.readthedocs.io/_modules/domonic/dom.html) : DOM API in python 3 😲 <br />
• [javascript](https://domonic.readthedocs.io/_modules/domonic/javascript.html) : js API in python 3 😳 <br />
• [dQuery](https://domonic.readthedocs.io/_modules/domonic/dQuery.html) - utils for querying domonic. (alt + 0 for the º symbol)<br />
• terminal || cmd : call terminal commands with python3 😱 (*see at the end*)<br />
• JSON : utils for loading / decorating / transforming<br />
• SVG : Generate svg using python (untested)<br />
• aframe || x3d tags : auto generate 3d worlds with aframe. (see examples folder)<br />

See the docs/code for more features...
https://domonic.readthedocs.io/

or examples in the [repo...](https://github.com/byteface/domonic/tree/master/examples)

(small footprint. under 250kb compressed with only a few common lightweight dependencies)


## HTML Templating with Python 3

```python
from domonic.html import *
print(html(body(h1('Hello, World!'))))
```
```html
<html><body><h1>Hello, World!</h1></body></html>
```

or to format it and insert the doctype use an f-string:

```python
mydom = html(body(h1('Hello, World!')))
print(f"{mydom}")
```
```html
<!DOCTYPE html>
<html>
    <body>
        <h1>Hello, World!</h1>
    </body>
</html>
```

### install
```bash
python3 -m pip install domonic
```

or if you had it before upgrade:

```bash
python3 -m pip install domonic --upgrade
```

### 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

you can cast str() on any element to render it without formatting.

```python
el_string = str(div())
print(el_string)
```

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
```

Now try building your own static site generator!

### decorators

You can 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"} )
```

or for example a colon...

```python
t = div( **{"_:test":"something"} )
str(t)
```

### 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)

```

There's an evolving DOM API. To learn more about the webAPI go here.

https://developer.mozilla.org/en-US/docs/Web/API

And check the code/docs to see what's currently been implemented.


```python
mysite.querySelectorAll('button')  # *note - still in dev. use getElementsBySelector for more complex selectors

# mysite.getElementsBySelector
```

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))

from domonic.javascript import URL
url = URL('https://somesite.com/blog/article-one#some-hash')
print(url.protocol)
print(url.host)
print(url.pathname)
print(url.hash)

# you can 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..
```

You can 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)

```

a-tags inherits from URL:

```python
from domonic.html import *

atag = a(_href="https://somesite.com:8000/blog/article-one#some-hash")
print('href:',atag.href)
print('protocol:',atag.protocol)
print('port:',atag.port)

atag.protocol = "http"
atag.port = 8983
print(atag)
```

For writing and using regular javascript you can load from a source...

```python
script(_src="/docs/5.0/dist/js/bootstrap.bundle.min.js", _integrity="sha384-1234", _crossorigin="anonymous"),
```

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;
}
"""),
```

### JSON (utils)

decorate any function that returns python objects to return json instead

```python
from domonic.JSON import *

@return_json
def somefunc():
    myObj = {"hi":[1,2,3]}
    return myObj

print( somefunc() )
print( is_json(somefunc()) )
```

convert json arrays into html tables...

```python
from domonic.JSON import *

# 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
from domonic.JSON import *

json_data = JSON.parse_file('somefile.json')
JSON.csvify(json_data, 'data.csv')

```

convert csv files to json...

```python
from domonic.JSON import *

json_data =JSON.csv2json("data.csv")
print(json_data)

```

more to come...


### SVG

All tags extend 'Node' and 'tag'. So will have DOM and magic methods available to them. see the docs.

```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

You can 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

    d = html(head(body(li(_class='things'), div(_id="test"))))

    º(d) # you need to init a dom first. i.e. a html element

    # now you can use it
    print( º('#test') )
    print( º('.things') )
    a = º('<div class="test2"></div>')
    print( a )

    b = º('#test').append(a)
    print(b)

```

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: <br />
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/

### notes on templating

while you can create a div with content like :

    div("some content")

python doesn't allow named params before unamed ones. So you can't do this:

    div(_class="container", p("Some content") )

or it will complain the params are in the wrong order. You have to instead put content before attributes:

    div( p("Some content"), _class="container")

which is annoying when a div gets long.

You can get around this by using 'html' which is available on every Element:

div( _class="container" ).html("Some content")

This is NOT like jQuery html func that returns just the inner content. use innerHTML for that.

It is used specifically for rendering.


### Common Errors

If templates are typed incorrectly they will not work.

There's a small learning curve getting .pyml templates correct. Usually (1) a missing comma between tags, (2) an underscore missing on an attribute or (3) params in the wrong order. Use this reference when starting out as a reminder when you get an error.

Here are the 4 solutions to those common errors when creating large templates...
( i.e. see bootstrap5 examples in test_domonic.py )

IndexError: list index out of range
    - You most likely didn't put a underscore on an attribute.

SyntaxError: invalid syntax
    - You are Missing a comma between attributes

SyntaxError: positional argument follows keyword argument
    - You have to pass attributes LAST. and strings and objects first. *see notes on templating above*

TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'dict'
    - You are Missing a comma between attributes. before the **{}


##### TODO - catch these errors and raise a friendly custom ParseError that tells you what to fix



### CLI
There's a few args you can pass to domonic on the command line to help you out.

To launch the docs for a quick reference to the APIs use:

```python

python3 -m domonic -h

```

This command will attempt to generate a template from a webpage. (only simple pages for now)

```python

python3 -m domonic -d http://eventual.technology

```

Then you can edit/tweak it to get what you need and build new components quicker.


### EXAMPLE PROJECTS

A browser based file browser. Working example of how components can work:
https://github.com/byteface/Blueberry/

A cron viewer:
https://github.com/byteface/ezcron/

A basic game:
https://github.com/byteface/bombdisposer/


checkout the docs for examples on how to easily make sitemaps with python. 
or for example how to use domonic with flask, django, sanic and other server frameworks.

docs:
https://domonic.readthedocs.io/


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.

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.


### 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
```

### rebuild docs
See Makefile:
```bash
. venv/bin/activate
cd docs
make html
```

### 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": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "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/66/76/484d4f3fcc44bc5d33df54774ee7fff15de82b1c94f171ab3b750052b38f/domonic-0.6.0.tar.gz",
    "platform": "",
    "description": "<h1 align=\"center\">\n    <img src=\"https://image.freepik.com/free-vector/demonic-goat_71119-56.jpg\"\n    style=\"background-color:rgba(0,0,0,0);\" height=230 alt=\"domonic: generate html with python 3!\">\n    <br>\n    domonic\n    <br>\n    <sup><sub><sup>Generate html with python 3! (and much more)</sup></sub></sup>\n    <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\n#### Contains several evolving packages:\n\n\u2022 [html](https://domonic.readthedocs.io/_modules/domonic/html.html) : Generate html with python 3 \ud83d\ude0e <br />\n\u2022 [dom](https://domonic.readthedocs.io/_modules/domonic/dom.html) : DOM API in python 3 \ud83d\ude32 <br />\n\u2022 [javascript](https://domonic.readthedocs.io/_modules/domonic/javascript.html) : js API in python 3 \ud83d\ude33 <br />\n\u2022 [dQuery](https://domonic.readthedocs.io/_modules/domonic/dQuery.html) - utils for querying domonic. (alt + 0 for the \u00ba symbol)<br />\n\u2022 terminal || cmd : call terminal commands with python3 \ud83d\ude31 (*see at the end*)<br />\n\u2022 JSON : utils for loading / decorating / transforming<br />\n\u2022 SVG : Generate svg using python (untested)<br />\n\u2022 aframe || x3d tags : auto generate 3d worlds with aframe. (see examples folder)<br />\n\nSee the docs/code for more features...\nhttps://domonic.readthedocs.io/\n\nor examples in the [repo...](https://github.com/byteface/domonic/tree/master/examples)\n\n(small footprint. under 250kb compressed with only a few common lightweight dependencies)\n\n\n## HTML Templating with Python 3\n\n```python\nfrom domonic.html import *\nprint(html(body(h1('Hello, World!'))))\n```\n```html\n<html><body><h1>Hello, World!</h1></body></html>\n```\n\nor to format it and insert the doctype use an f-string:\n\n```python\nmydom = html(body(h1('Hello, World!')))\nprint(f\"{mydom}\")\n```\n```html\n<!DOCTYPE html>\n<html>\n    <body>\n        <h1>Hello, World!</h1>\n    </body>\n</html>\n```\n\n### install\n```bash\npython3 -m pip install domonic\n```\n\nor if you had it before upgrade:\n\n```bash\npython3 -m pip install domonic --upgrade\n```\n\n### attributes\nprepend attributes with an underscore ( avoids clashing with python keywords )\n```python\ntest = label(_class='classname', _for=\"someinput\")\nprint(test)\n```\n```html\n<label class=\"classname\" for=\"someinput\"></label>\n```\n\n### rendering\n\nyou can cast str() on any element to render it without formatting.\n\n```python\nel_string = str(div())\nprint(el_string)\n```\n\nthere's also a render method that takes 2 parameters, some domonic and an optional output file.\n```python\npage = div(span('Hello World'))\nrender(f\"{page}\", 'index.html')  # notice use of f-string to pretty print the html\n```\n\nNow try building your own static site generator!\n\n### decorators\n\nYou can use 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\n### data-tags\npython doesn't allow hyphens in parameter names. so use variable keyword argument syntax for custom data-tags\n```python\ndiv(\"test\", **{\"_data-test\":\"test\"} )\n```\n\nor for example a colon...\n\n```python\nt = div( **{\"_:test\":\"something\"} )\nstr(t)\n```\n\n### DOM\n\nDOM manipulation with python.\n\n#### createElement\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\n```\n\nThere's an evolving DOM API. To learn more about the webAPI go here.\n\nhttps://developer.mozilla.org/en-US/docs/Web/API\n\nAnd check the code/docs to see what's currently been implemented.\n\n\n```python\nmysite.querySelectorAll('button')  # *note - still in dev. use getElementsBySelector for more complex selectors\n\n# mysite.getElementsBySelector\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\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\nfrom domonic.javascript import URL\nurl = URL('https://somesite.com/blog/article-one#some-hash')\nprint(url.protocol)\nprint(url.host)\nprint(url.pathname)\nprint(url.hash)\n\n# you can 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\nYou can use setInterval and clearInterval with params\n\n```python\n\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```\n\nOr for a single delayed function call use setTimeout, clearTimeout\n\n```python\n\nfrom domonic.javascript import setTimeout, clearTimeout\n\ntimeoutID = setTimeout(hi, 1000)\n\n```\n\na-tags inherits from 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)\nprint('protocol:',atag.protocol)\nprint('port:',atag.port)\n\natag.protocol = \"http\"\natag.port = 8983\nprint(atag)\n```\n\nFor writing and using regular javascript you can load from a source...\n\n```python\nscript(_src=\"/docs/5.0/dist/js/bootstrap.bundle.min.js\", _integrity=\"sha384-1234\", _crossorigin=\"anonymous\"),\n```\n\nor do inline js by opening triple quotes...\n\n```python\nscript(\"\"\"\nlet itbe = \"\"\n\"\"\"),\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### JSON (utils)\n\ndecorate any function that returns python objects to return json instead\n\n```python\nfrom domonic.JSON import *\n\n@return_json\ndef somefunc():\n    myObj = {\"hi\":[1,2,3]}\n    return myObj\n\nprint( somefunc() )\nprint( is_json(somefunc()) )\n```\n\nconvert json arrays into html tables...\n\n```python\nfrom domonic.JSON import *\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```\n\nconvert json arrays into csv files...\n\n```python\nfrom domonic.JSON import *\n\njson_data = JSON.parse_file('somefile.json')\nJSON.csvify(json_data, 'data.csv')\n\n```\n\nconvert csv files to json...\n\n```python\nfrom domonic.JSON import *\n\njson_data =JSON.csv2json(\"data.csv\")\nprint(json_data)\n\n```\n\nmore to come...\n\n\n### SVG\n\nAll tags extend 'Node' and 'tag'. So will have DOM and magic methods available to them. see the docs.\n\n```python\n        circ = svg(\n            circle(_cx=\"50\", _cy=\"50\", _r=\"40\", _stroke=\"green\", **{\"_stroke-width\": \"4\"}, _fill=\"yellow\"),\n            _width=\"100\", _height=\"100\",\n        )\n        mysvg = svg()\n        mysvg.appendChild(circ / 10)\n        print(mysvg)\n```\n\n\n### Tweening\n\nYou can tween 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\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\n### dQuery (NEW)\n\ndQuery uses the \u00ba symbol (alt+0).\n\n```python\n\n    d = html(head(body(li(_class='things'), div(_id=\"test\"))))\n\n    \u00ba(d) # you need to init a dom first. i.e. a html element\n\n    # now you can use it\n    print( \u00ba('#test') )\n    print( \u00ba('.things') )\n    a = \u00ba('<div class=\"test2\"></div>')\n    print( a )\n\n    b = \u00ba('#test').append(a)\n    print(b)\n\n```\n\nOnly recently started so check to see what's implemented.\n\n\n### terminal\n\nThere is a command line package that can call bash/unix/posix and other apps on the command line: <br />\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'))\nprint(wget('eventual.technology'))\nprint(date())\nprint(cal())\n```\n\nor just run arbitrary commands...\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\n\nWindows users can use now use cmd.\n\n```python\nfrom domonic.cmd import *\nprint(dir())\nprint(dir(\"..\\\\\")) \n```\n\n\n## DOCS\n\nhttps://domonic.readthedocs.io/\n\n### notes on templating\n\nwhile you can create a div with content like :\n\n    div(\"some content\")\n\npython doesn't allow named params before unamed ones. So you can't do this:\n\n    div(_class=\"container\", p(\"Some content\") )\n\nor it will complain the params are in the wrong order. You have to instead put content before attributes:\n\n    div( p(\"Some content\"), _class=\"container\")\n\nwhich is annoying when a div gets long.\n\nYou can get around this by using 'html' which is available on every Element:\n\ndiv( _class=\"container\" ).html(\"Some content\")\n\nThis is NOT like jQuery html func that returns just the inner content. use innerHTML for that.\n\nIt is used specifically for rendering.\n\n\n### Common Errors\n\nIf templates are typed incorrectly they will not work.\n\nThere's a small learning curve getting .pyml templates correct. Usually (1) a missing comma between tags, (2) an underscore missing on an attribute or (3) params in the wrong order. Use this reference when starting out as a reminder when you get an error.\n\nHere are the 4 solutions to those common errors when creating large templates...\n( i.e. see bootstrap5 examples in test_domonic.py )\n\nIndexError: list index out of range\n    - You most likely didn't put a underscore on an attribute.\n\nSyntaxError: invalid syntax\n    - You are Missing a comma between attributes\n\nSyntaxError: positional argument follows keyword argument\n    - You have to pass attributes LAST. and strings and objects first. *see notes on templating above*\n\nTypeError: unsupported operand type(s) for ** or pow(): 'str' and 'dict'\n    - You are Missing a comma between attributes. before the **{}\n\n\n##### TODO - catch these errors and raise a friendly custom ParseError that tells you what to fix\n\n\n\n### CLI\nThere's a few args you can pass to domonic on the command line to help you out.\n\nTo launch the docs for a quick reference to the APIs use:\n\n```python\n\npython3 -m domonic -h\n\n```\n\nThis command will attempt to generate a template from a webpage. (only simple pages for now)\n\n```python\n\npython3 -m domonic -d http://eventual.technology\n\n```\n\nThen you can edit/tweak it to get what you need and build new components quicker.\n\n\n### EXAMPLE PROJECTS\n\nA browser based file browser. Working example of how components can work:\nhttps://github.com/byteface/Blueberry/\n\nA cron viewer:\nhttps://github.com/byteface/ezcron/\n\nA basic game:\nhttps://github.com/byteface/bombdisposer/\n\n\ncheckout the docs for examples on how to easily make sitemaps with python. \nor for example how to use domonic with flask, django, sanic and other server frameworks.\n\ndocs:\nhttps://domonic.readthedocs.io/\n\n\nThere's also several useage examples in the repo so pull and have a look.\n\n\n### Join-In\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.\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.\n\nI'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\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```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\n\npython3 -m unittest tests.test_cmd.TestCase.test_cmd_dir  # only windows\n\n```\n\nor to test a whole module\n```bash\npython -m unittest tests.test_html\npython -m unittest tests.test_CDN\n```\n\nto see coverage\n```bash\ncoverage run -m unittest discover tests/\ncoverage report\n```\n\n### rebuild docs\nSee Makefile:\n```bash\n. venv/bin/activate\ncd docs\nmake html\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.6.0",
    "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": {
                "md5": "aa242863faa5b2f4fddc4fc7a4104758",
                "sha256": "bf7d96361383a37690496c34317dc528ba90a29e3b885f46d4f01ee4aecc2b6e"
            },
            "downloads": -1,
            "filename": "domonic-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aa242863faa5b2f4fddc4fc7a4104758",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 224372,
            "upload_time": "2021-09-26T13:39:52",
            "upload_time_iso_8601": "2021-09-26T13:39:52.713169Z",
            "url": "https://files.pythonhosted.org/packages/03/f7/e926880770553466cf0745fc628ea9ded1d3b4b935df02fcab8e03725cee/domonic-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "e2300a230c8af43b90e7e9773c73177e",
                "sha256": "e92eaf98a65d3a33df8e0fd8edda4dc364ee8c21efc617b74989288a592764a7"
            },
            "downloads": -1,
            "filename": "domonic-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e2300a230c8af43b90e7e9773c73177e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 262524,
            "upload_time": "2021-09-26T13:39:55",
            "upload_time_iso_8601": "2021-09-26T13:39:55.126744Z",
            "url": "https://files.pythonhosted.org/packages/66/76/484d4f3fcc44bc5d33df54774ee7fff15de82b1c94f171ab3b750052b38f/domonic-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-09-26 13:39:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "byteface",
    "github_project": "domonic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "python-dateutil",
            "specs": [
                [
                    "==",
                    "2.8.2"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.26.0"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "1.26.6"
                ]
            ]
        }
    ],
    "lcname": "domonic"
}
        
Elapsed time: 0.33633s