Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
zainhoda committed Mar 18, 2023
1 parent 8ac8526 commit 9cb55d0
Show file tree
Hide file tree
Showing 12 changed files with 7,458 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"lldb.library": "/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB"
}
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing to PageBuilder

## Architecture
`generate.swift`, `generate.py`, and `pdoc` are executed. Everything else is either an input or an output

```mermaid
---
title: Code Generation Flow
---
flowchart TD
advanced(generator/includes/advanced.py.txt) --> generate.swift[[generator/generate.swift]]
generate.swift --> spec(spec/spec.json)
generate.swift --> init(src/__init__.py)
spec --> generate.py[[generator/generate.py]]
generate.py --> reference(docs/reference.html)
init --> pdoc[[pdoc]]
pdoc --> pagebuilder.html(docs/pagebuilder.html)
```

Due to the architecture above, pull requests should be submitted only to files in the `/generator` subdirectory since everything else is generated from those files

## Why Code Generation?
We want to minimize the need to have to search through documentation. Our goal is to be able to rely on autocomplete. To that end, we want to be able to attach `.add_*` methods to all appropriate components so that the list of available components in the current context is available. In order to minimize copy/paste, it's easiest to just generate the library code from a central definition.

## Why Swift?
Very strongly typed languages with exhaustive enum checking makes code generation a lot more robust. Of the languages that would suit this criteria, Swift is probably the most readable for Python developers.
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# define the name of the virtual environment directory
VENV := venv

all: $(VENV)/bin/activate

# Build init.py when generate.swift changes
src/pagebuilder/__init.py___: generator/generate.swift
swift generator/generate.swift

# Rebuild the virtual environment when init.py changes
$(VENV)/bin/activate: src/pagebuilder/__init.py___
python3 -m venv $(VENV)
./$(VENV)/bin/pip install --upgrade pip
./$(VENV)/bin/pip install .

clean:
rm -rf $(VENV)
find . -type f -name '*.pyc' -delete

.PHONY: all clean
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
# pagebuilder
Generate HTML pages from Python
# PageBuilder
PageBuilder is a Python library that offers a simple and intuitive way to create UI components for web apps without the need to write HTML code.

## Key Features
- Provides semantic Python components that compile into HTML, making it easy to use with any web framework.
- Comes with a range of semantic Python components, including headers, text, forms, buttons, and links.
- Is designed to work well with Python autocomplete, enabling quick and easy exploration of the available components and their arguments.
- Offers an alternative to hand-coding Flask templates, streamlining UI development for web apps.
- The default style uses TailwindCSS, a popular CSS framework known for its utility-first approach.
- Allows you to insert any HTML into the page by using the Page.add_html() method, providing you with the flexibility to add custom components or use third-party libraries as needed.
- Offers an easy-to-use theming system, allowing you to choose from a variety of pre-built themes, including the default theme based on TailwindCSS.
- Allows for additional themes to be added using different CSS frameworks by accepting pull requests from contributors.

## Why PageBuilder?
PageBuilder is a great fit for developers who want to:

- Create UI components for web apps using Python code without the need to write HTML.
- Use a Python library that works seamlessly with any web framework.
- Build UIs using a range of semantic Python components with explicit arguments.
- Use a utility-first CSS framework, such as TailwindCSS, to style their UI components without the need for custom CSS code.
- Insert any HTML into the page when a pre-built component doesn't fit their needs.
- Customize the style of their UI components by choosing from a variety of pre-built themes or by contributing new themes that use different CSS frameworks.
- Getting Started
- To get started with PageBuilder, simply install the library using pip:

```bash
pip install pagebuilder
```
Once installed, you can begin creating UI components by creating a new Page object and adding components to it using the add_* methods. You can then return the page as HTML by calling page.to_html().

For example, to create a new page with a header and a paragraph of text, you could use the following code:

```python
import pagebuilder as pb

page = pb.Page()
page.add_header("Welcome to PageBuilder!")
page.add_text("PageBuilder is a Python library for creating UI components for web apps without the need to write HTML code.")
print(page.to_html())
```
This will output the following HTML:

```html
<div id="page-container" class="container px-5 my-5 mx-auto">
<p class="mb-4 font-extrabold leading-none tracking-tight text-gray-900 dark:text-white text-xl sm:text-5xl ">Welcome to PageBuilder!</p>
<p class="mb-6 text-lg font-normal text-gray-500 lg:text-xl dark:text-gray-400">PageBuilder is a Python library for creating UI components for web apps without the need to write HTML code.</p>
</div>
```

## Contributions
PageBuilder is an open-source library, and [contributions](CONTRIBUTING.md) are welcome! If you have an idea for a new feature or theme, or if you find a bug and want to submit a fix, feel free to open a pull request.

Thanks for considering PageBuilder!
12 changes: 12 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PageBuilder</title>
<!--Viewport-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>PageBuilder</h1>
</body>
</html>
Loading

0 comments on commit 9cb55d0

Please sign in to comment.