HTML template generator for Python.
Project description
wBuilder
wBuilder
(c) 2020 Rodney Maniego Jr.
MIT License
HTML template generator for Python.
Read: Introducing wBuilder: An HTML5 Generator for Python
Requirements:
- BS4
Go to examples/*.py
for basic usage.
Returned value is in string and can be saved into file.
Future Features
- Basic JQuery generator
WebBuilder Usage
Import
from wbuilder.wbuilder import WebBuilder
Initialize
html = WebBuilder()
Basic usage
html.at("body").button().text("OK").done()
HTML head
html.at("head").title().text("WebBuilder").done()
html.at("head").meta().charset("UTF-8").done()
html.at("head").meta().name("viewport").content("width=device-width, initial-scale=1, shrink-to-fit=no").done()
html.at("head").link().rel("icon").href("icon.png").Type("image/png").sizes("96x96").done(static=True)
html.at("head").link().rel("stylesheet").href("reset.css").done(static=True)
html.at("head").link().rel("stylesheet").href("design.css").done()
CSS selectors
html.at("body").div("prompt-msg", "popup").done()
html.at("#prompt-msg").div(Class="header").text("Welcome!").done()
html.at("#prompt-msg").div(Class="message").text("Lorem ipsum...").done()
# CSS as a string
html.css(".header", "font-size: 14px; font-weight: bold;")
# CSS as a dictionary
design = { "font-size": "12px",
"color": "#222",
"background-color": "#f0f0f0" }
html.css(".message", design)
html.css(".message", { "font-size": "12px",
"color": "#222",
"background-color": "#f0f0f0" })
Update element attribute
html.attrs("head", "lang", "en", 0)
html.attrs("div", "style", "display: block;")
html.attrs("div", "style", "display: none;", attrs={"class": "popup"})
CSS fonts
html.font("funfont", "funfont.ttf")
html.at("body").div(Class="fun").text("Fun message...").done()
html.css(".fun", "font-family: funfont;")
Preview HTML
print(html.build())
Save to file
# defaults
html.save_to_html()
html.save_stylesheet()
# custom filepaths
html.save_to_html("templates", "home.html")
html.save_stylesheet("static", "custom.css")
Css class
Initialize
from wbuilder.wbuilder import Css
print("\n# Initialize...")
css = Css(sort=True)
Show all selectors
print("\n# Bulk add dfrom string...")
css.add_from_string(".box", "width: 200px; height: 100px")
Show all selectors
print("\n# Bulk add dictionary...")
css.add(".btn", { "font-size": "16px",
"background-color": "#f0f0f0",
"color": "#c0c0c0"})
Show all selectors
print("\n# Add by property...")
css.update("body", "font-size", "12px")
css.update(".nav", "position", "fixed")
css.update(".nav", "font-size", "14px")
Show all selectors
print("\n# Show all selectors...")
print(css.build())
Save to file
print("\n# Save to file...")
css.save("static", "design.css")
Remove selector data
print("\n# Remove selector data..")
css.remove(".nav")
print(css.build())
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
wbuilder-2.2.0.tar.gz
(25.3 kB
view hashes)
Built Distribution
wbuilder-2.2.0-py3-none-any.whl
(11.0 kB
view hashes)