Skip to content

Commit

Permalink
built a template from a bs5 example to see what was like. fixed a few…
Browse files Browse the repository at this point in the history
… bits.
  • Loading branch information
byteface committed Jun 17, 2020
1 parent 34e4f3b commit 07434af
Show file tree
Hide file tree
Showing 9 changed files with 928 additions and 488 deletions.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ print(HTMLBeautifier.beautify(output, 4))
```

### common errors
If you incorrectly type the code it will obviously not work. So there are a bunch of common ones I've noticed :

##### TODO - catch these and raise a friendly error that tells you what to fix

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

SyntaxError: invalid syntax
- You most likely are missing a comma somewhere between params

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


### run tests
```bash
Expand All @@ -104,6 +109,31 @@ python3 test_domonic.py
several undocumented features. take a look at the code.


### docs

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 several ways.

With 'innerHTML' which is available on every Node:

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

With 'html' which is available on every Node:

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


### disclaimer

exerimental/learning project
Expand Down
7 changes: 5 additions & 2 deletions archive/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ TypeError: __str__() missing 1 required positional argument: 'self'





TODO - poll the source and send updates to the dom via socket? auto generate the js/python?
div("hello world", bind="http://www.somedatasource"),




- attribute for setting content. so can do _html=
15 changes: 15 additions & 0 deletions archive/bs5_test_checkout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="description" content="" /><meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors" /><meta name="generator" content="Hugo 0.72.0" /><title>Checkout example · Bootstrap</title><link rel="canonical" href="https://v5.getbootstrap.com/docs/5.0/examples/checkout/" /><link href="/docs/5.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-12345" crossorigin="anonymous" /><link rel="apple-touch-icon" href="/docs/5.0/assets/img/favicons/apple-touch-icon.png" sizes="180x180" /><link rel="icon" href="/docs/5.0/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png" /><link rel="icon" href="/docs/5.0/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png" /><link rel="manifest" href="/docs/5.0/assets/img/favicons/manifest.json" /><link rel="mask-icon" href="/docs/5.0/assets/img/favicons/safari-pinned-tab.svg" color="#7952b3" /><link rel="icon" href="/docs/5.0/assets/img/favicons/favicon.ico" /><meta name="theme-color" content="#7952b3" /><style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style><link href="form-validation.css" rel="stylesheet" /><img class="d-block mx-auto mb-4" src="/docs/5.0/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72" /><h2>Checkout form</h2><p class="lead">Below is an example form built entirely with Bootstrap’s form controls. Each required form group has a validation state that can be triggered by attempting to submit the form without completing it.</p><span class="text-muted">Your cart</span><span class="badge bg-secondary rounded-pill">3</span><div><h6 class="my-0">Product name</h6><small class="text-muted">Brief description</small></div><span class="text-muted">$12</span><div><h6 class="my-0">Second product</h6><small class="text-muted">Brief description</small></div><span class="text-muted">$8</span><div><h6 class="my-0">Third item</h6><small class="text-muted">Brief description</small></div><span class="text-muted">$5</span><h6 class="my-0">Promo code</h6><small>EXAMPLECODE</small><span class="text-success">−$5</span><span>Total (USD)</span><strong>$20</strong><input type="text" class="form-control" placeholder="Promo code" /><button type="submit" class="btn btn-secondary">Redeem</button><h4 class="mb-3">Billing address</h4><label for="firstName" class="form-label">First name</label><input type="text" class="form-control" id="firstName" placeholder="" value="" required="True" /><div class="invalid-feedback">Valid first name is required.</div><label for="lastName" class="form-label">Last name</label><input type="text" class="form-control" id="lastName" placeholder="" value="" required="True" /><div class="invalid-feedback">Valid last name is required.</div><label for="username" class="form-label">Username</label><span class="input-group-text">@</span><input type="text" class="form-control" id="username" placeholder="Username" required="True" /><div class="invalid-feedback">Your username is required.</div><label for="email" class="form-label">Email Optional</label><input type="email" class="form-control" id="email" placeholder="[email protected]" /><div class="invalid-feedback">Please enter a valid email address for shipping updates.</div><label for="address" class="form-label">Address</label><input type="text" class="form-control" id="address" placeholder="1234 Main St" required="True" /><div class="invalid-feedback">Please enter your shipping address.</div><label for="address2" class="form-label">Address 2 Optional</label><input type="text" class="form-control" id="address2" placeholder="Apartment or suite" /><label for="country" class="form-label">Country</label><option value="">Choose...</option><option>United States</option><div class="invalid-feedback">Please select a valid country.</div><label for="state" class="form-label">State</label><option value="">Choose...</option><option>California</option><div class="invalid-feedback">Please provide a valid state.</div><label for="zip" class="form-label">Zip</label><input type="text" class="form-control" id="zip" placeholder="" required="True" /><div class="invalid-feedback">Zip code required.</div><hr class="my-4" /><input type="checkbox" class="form-check-input" id="same-address" /><label class="form-check-label" for="same-address">Shipping address is the same as my billing address</label><input type="checkbox" class="form-check-input" id="save-info" /><label class="form-check-label" for="save-info">Save this information for next time</label><hr class="my-4" /><h4 class="mb-3">Payment</h4><input id="credit" name="paymentMethod" type="radio" class="form-check-input" checked="True" required="True" /><label class="form-check-label" for="credit">Credit card</label><input id="debit" name="paymentMethod" type="radio" class="form-check-input" required="True" /><label class="form-check-label" for="debit">Debit card</label><input id="paypal" name="paymentMethod" type="radio" class="form-check-input" required="True" /><label class="form-check-label" for="paypal">PayPal</label><label for="cc-name" class="form-label">Name on card</label><input type="text" class="form-control" id="cc-name" placeholder="" required="True" /><small class="text-muted">Full name as displayed on card</small><div class="invalid-feedback">Name on card is required</div><label for="cc-number" class="form-label">Credit card number</label><input type="text" class="form-control" id="cc-number" placeholder="" required="True" /><div class="invalid-feedback">Credit card number is required</div><label for="cc-expiration" class="form-label">Expiration</label><input type="text" class="form-control" id="cc-expiration" placeholder="" required="True" /><div class="invalid-feedback">Expiration date required</div><label for="cc-cvv" class="form-label">CVV</label><input type="text" class="form-control" id="cc-cvv" placeholder="" required="True" /><div class="invalid-feedback">Security code required</div><hr class="my-4" /><button class="btn btn-primary btn-lg btn-block" type="submit">Continue to checkout</button><p class="mb-1">&copy; 2020 Company Name</p><li class="list-inline-item"><a href="#">Privacy</a></li><li class="list-inline-item"><a href="#">Terms</a></li><li class="list-inline-item"><a href="#">Support</a></li><script src="/docs/5.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-12345" crossorigin="anonymous"></script><script src="form-validation.js"></script></html>
35 changes: 30 additions & 5 deletions domonic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Generate HTML using python 3
"""

__version__ = "0.0.2"
__version__ = "0.0.3"

from typing import *

Expand All @@ -25,29 +25,35 @@ def get(url:str):
return domonic.parse(r.text)

@staticmethod
def print(domonic) -> str:
def print(domonic) -> str :
''' outputs HTML str '''
# TODO - prettify by using newlines in returned content to save installing this?
# from html5print import HTMLBeautifier
# render(HTMLBeautifier.beautify(render(output), 4), 'index.html')
pass

@staticmethod
def parse(html:str):
def parse(html:str) -> str :
''' HTML as input and returns domonic '''

print("swallow honey!!!::::::::::::::::::::::::::::::")
print("attempting to parse the page")

# - TODO - should probs pretty it up first and strip want cant be
# turn all tags into class definitions.
# check closing tags. turn to closed bracks
# create strings around content and remove white space
# put underscores on attributes

import re

html = ''.join(html.split('<!DOCTYPE HTML>'))
html = ''.join(html.split('<!doctype html>'))

# html = "<html><body>some content</body></html>"

htmltags = ["html","header","head","body","meta","title","style","script","div","footer","img","a","p"]
# "style","script"

htmltags = ["html","span","button","link","form","nav","details","summary","header","head","body","meta","title","div","footer","img","a","p","h1","h2","h3","h4","h5","h6","hr","ul","ol","li","time","template","label","input","small","strong","option","select"]

for tag in htmltags:

Expand Down Expand Up @@ -93,6 +99,25 @@ def parse(html:str):
# print(count, html)

print(html)


# close any tags that arent properly self closing
flag=False
for index,char in enumerate(html):
if char=="(":flag=True
if char==")":flag=False
if char==">" and flag is True:
html = f"{html[:index]},{html[index+1:]}" # replace it for a ','
# TODO - if its self closing. replace for a ')' instead

# strip any comments
cleaned=[]
for line in html.splitlines():
print('smelly fanny!')
if "<!" in line:
continue
cleaned.append(line)
html = '\n'.join(cleaned)

# return eval('print("test")')
# return eval('Location()')
Expand Down
Loading

0 comments on commit 07434af

Please sign in to comment.