makeweb


Namemakeweb JSON
Version 0.2.3 PyPI version JSON
download
home_pageNone
SummaryMake interactive web apps using good ol' HTML, CSS and a sprinkling of JavaScript — in Python.
upload_time2025-01-25 23:10:16
maintainerNone
docs_urlNone
authorHarshad Sharma
requires_python>=3.9
licenseMIT
keywords website html css javascript generate template
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MakeWeb

Make interactive web apps using good ol' HTML, CSS
and a sprinkling of JavaScript — in Python.

## Examples

### HyperText Markup Lnguage

If we run this script:

```python
# 00-generate-html.py

from makeweb import Doc, body, h1

def generate_html():
    doc = Doc('html', lang='mr')
    with body():
        h1('हा!')
    return str(doc)

print(generate_html())
```

We should see this output on the screen:

```html
<!doctype html>
<html lang="mr">
<body>
  <h1>हा!</h1>
</body>
</html>
```

*(Whitespace added for clarity.)*

Ha! HTML was easy, let us generate CSS from Python code.

### Cascading Style Sheets

```python
# 01-generate-css.py

from makeweb import CSS

css = CSS()

css('body', background='white', color='#222')
css('h1', color='darkorange', margin__top='1em')

print(str(css))
```

Running the above example we see...

```css
body{
  background:white;
  color:#222
}
h1{
  color:darkorange;
  margin-top:1em
}
```

*(Whitespace added for clarity.)*

Notice that the double underscore in `css('h1', margin__top='1em')`
gets converted to hyphen in CSS as `h1{margin-top:1em}`.
This pattern is used throughout the library for HTML and CSS attributes.

So... CSS is even easier?!
How about something more ambitious?

### JavaScript

```python
# 02-generate-js.py

from makeweb import JS

js = JS()

@js.function
def say_hello():
    hello_box = document.getElementById("hello_box")
    hello_box.innerHTML = "Hello, World Wide Web!"

print(str(js))
```

And we get a JavaScript function out!

```javascript
function say_hello(){
  var hello_box;
  hello_box=document.getElementById("hello_box");
  hello_box.innerHTML="Hello, World Wide Web!";
}
```

*(Whitespace added for clarity.)*

Now let us use these capabilities together!

### App

```python
# hello-readme.py

from flask import Flask, Response
from makeweb import (
    Doc, CSS, JS,
    head, title, style, script,
    body, h1, button,
)

# We'll use Flask to serve, you could use any other framework 
# or save as static files, or anything else 
# that you wish to do with generated html.
app = Flask(__name__)  
css = CSS()
js = JS()

css('*,body',   # <-- Add CSS to taste.
    font__family='sans-serif',
    text__align='center')
css('h1', color="darkblue")  


@js.function  # <-- A sprinkling of JavaScript. Look ma, no braces!
def say_hello():
    hello_box = document.getElementById("hello_box")
    hello_box.innerHTML = "Hello, World Wide Web!"


@app.route('/')
def index():
    doc = Doc('html')  # <-- Generate all the HTML your app (really) needs.
    with head():
        title('Hello')
        with style():  # Embed CSS.
            css.embed()
    with body():
        h1('...', id='hello_box')  # Set attributes. 
        button('Hello', onclick="say_hello()")  # <-- hook up say_hello().
        with script():  # Embed JavaScript.
            js.embed()
    return Response(str(doc))  # <-- Serve all the awesome your users desire!


app.run()  # <-- It is time! 
```

This app transfers ~550 bytes over the network in order to run successfully,
that is including the HTTP headers overhead.
You read that right, not even one kilobyte!
The web technologies are quite simple and straightforward for general use,
and very flexible, robust and powerful too!

You might not need (or want the baggage of) complex tooling
for a small project.
It could be a one time make-and-forget tool at work
or a weekend hobby project,
or maybe something even larger if you really like this way of working.
MakeWeb can come in handy because it makes it almost trivial
to build the web like it was intended,
straight from your Python code.

Wait, somebody mentioned single-page-apps?
How about single source-file apps
that don't download half the internet to work? 😂
Kidding, this is a very, very barebones system,
and therefore you can use any existing stylesheets
or JS libraries alongside MakeWeb.

> Check out examples for more demos!

## Install

### Using Poetry (Recommended)

```shell
# Clone the repository
git clone https://github.com/hiway/makeweb.git
cd makeweb

# Install poetry if you haven't already
pip install poetry

# Install makeweb with JS support
poetry install --with js

# For development
poetry install --with dev

# For running examples
poetry install --with examples

# For everything
poetry install --with dev,js,examples
```

### Using pip (Legacy)

#### Stable

```shell
python3 -m venv makeweb
source makeweb/bin/activate
pip install makeweb[js]
```

#### Current

```shell
python3 -m venv makeweb
source makeweb/bin/activate
git clone https://github.com/hiway/makeweb.git
cd makeweb
pip install -e .[examples]
```

#### Development

```shell
python3 -m venv makeweb
source makeweb/bin/activate
git clone https://github.com/hiway/makeweb.git
cd makeweb
pip install -e .[dev]
```

- libtidy-dev

#### Test

```console
pytest tests.py
```

With coverage:

```console
pytest --cov=makeweb --cov-report=term tests.py
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "makeweb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "website, html, css, javascript, generate, template",
    "author": "Harshad Sharma",
    "author_email": "harshad@sharma.io",
    "download_url": "https://files.pythonhosted.org/packages/c7/74/ac2bb3b8bda4b956e25dd2e8ef6ae1d8d71a7b8030f3b1826334a73833e6/makeweb-0.2.3.tar.gz",
    "platform": null,
    "description": "# MakeWeb\n\nMake interactive web apps using good ol' HTML, CSS\nand a sprinkling of JavaScript \u2014 in Python.\n\n## Examples\n\n### HyperText Markup Lnguage\n\nIf we run this script:\n\n```python\n# 00-generate-html.py\n\nfrom makeweb import Doc, body, h1\n\ndef generate_html():\n    doc = Doc('html', lang='mr')\n    with body():\n        h1('\u0939\u093e!')\n    return str(doc)\n\nprint(generate_html())\n```\n\nWe should see this output on the screen:\n\n```html\n<!doctype html>\n<html lang=\"mr\">\n<body>\n  <h1>\u0939\u093e!</h1>\n</body>\n</html>\n```\n\n*(Whitespace added for clarity.)*\n\nHa! HTML was easy, let us generate CSS from Python code.\n\n### Cascading Style Sheets\n\n```python\n# 01-generate-css.py\n\nfrom makeweb import CSS\n\ncss = CSS()\n\ncss('body', background='white', color='#222')\ncss('h1', color='darkorange', margin__top='1em')\n\nprint(str(css))\n```\n\nRunning the above example we see...\n\n```css\nbody{\n  background:white;\n  color:#222\n}\nh1{\n  color:darkorange;\n  margin-top:1em\n}\n```\n\n*(Whitespace added for clarity.)*\n\nNotice that the double underscore in `css('h1', margin__top='1em')`\ngets converted to hyphen in CSS as `h1{margin-top:1em}`.\nThis pattern is used throughout the library for HTML and CSS attributes.\n\nSo... CSS is even easier?!\nHow about something more ambitious?\n\n### JavaScript\n\n```python\n# 02-generate-js.py\n\nfrom makeweb import JS\n\njs = JS()\n\n@js.function\ndef say_hello():\n    hello_box = document.getElementById(\"hello_box\")\n    hello_box.innerHTML = \"Hello, World Wide Web!\"\n\nprint(str(js))\n```\n\nAnd we get a JavaScript function out!\n\n```javascript\nfunction say_hello(){\n  var hello_box;\n  hello_box=document.getElementById(\"hello_box\");\n  hello_box.innerHTML=\"Hello, World Wide Web!\";\n}\n```\n\n*(Whitespace added for clarity.)*\n\nNow let us use these capabilities together!\n\n### App\n\n```python\n# hello-readme.py\n\nfrom flask import Flask, Response\nfrom makeweb import (\n    Doc, CSS, JS,\n    head, title, style, script,\n    body, h1, button,\n)\n\n# We'll use Flask to serve, you could use any other framework \n# or save as static files, or anything else \n# that you wish to do with generated html.\napp = Flask(__name__)  \ncss = CSS()\njs = JS()\n\ncss('*,body',   # <-- Add CSS to taste.\n    font__family='sans-serif',\n    text__align='center')\ncss('h1', color=\"darkblue\")  \n\n\n@js.function  # <-- A sprinkling of JavaScript. Look ma, no braces!\ndef say_hello():\n    hello_box = document.getElementById(\"hello_box\")\n    hello_box.innerHTML = \"Hello, World Wide Web!\"\n\n\n@app.route('/')\ndef index():\n    doc = Doc('html')  # <-- Generate all the HTML your app (really) needs.\n    with head():\n        title('Hello')\n        with style():  # Embed CSS.\n            css.embed()\n    with body():\n        h1('...', id='hello_box')  # Set attributes. \n        button('Hello', onclick=\"say_hello()\")  # <-- hook up say_hello().\n        with script():  # Embed JavaScript.\n            js.embed()\n    return Response(str(doc))  # <-- Serve all the awesome your users desire!\n\n\napp.run()  # <-- It is time! \n```\n\nThis app transfers ~550 bytes over the network in order to run successfully,\nthat is including the HTTP headers overhead.\nYou read that right, not even one kilobyte!\nThe web technologies are quite simple and straightforward for general use,\nand very flexible, robust and powerful too!\n\nYou might not need (or want the baggage of) complex tooling\nfor a small project.\nIt could be a one time make-and-forget tool at work\nor a weekend hobby project,\nor maybe something even larger if you really like this way of working.\nMakeWeb can come in handy because it makes it almost trivial\nto build the web like it was intended,\nstraight from your Python code.\n\nWait, somebody mentioned single-page-apps?\nHow about single source-file apps\nthat don't download half the internet to work? \ud83d\ude02\nKidding, this is a very, very barebones system,\nand therefore you can use any existing stylesheets\nor JS libraries alongside MakeWeb.\n\n> Check out examples for more demos!\n\n## Install\n\n### Using Poetry (Recommended)\n\n```shell\n# Clone the repository\ngit clone https://github.com/hiway/makeweb.git\ncd makeweb\n\n# Install poetry if you haven't already\npip install poetry\n\n# Install makeweb with JS support\npoetry install --with js\n\n# For development\npoetry install --with dev\n\n# For running examples\npoetry install --with examples\n\n# For everything\npoetry install --with dev,js,examples\n```\n\n### Using pip (Legacy)\n\n#### Stable\n\n```shell\npython3 -m venv makeweb\nsource makeweb/bin/activate\npip install makeweb[js]\n```\n\n#### Current\n\n```shell\npython3 -m venv makeweb\nsource makeweb/bin/activate\ngit clone https://github.com/hiway/makeweb.git\ncd makeweb\npip install -e .[examples]\n```\n\n#### Development\n\n```shell\npython3 -m venv makeweb\nsource makeweb/bin/activate\ngit clone https://github.com/hiway/makeweb.git\ncd makeweb\npip install -e .[dev]\n```\n\n- libtidy-dev\n\n#### Test\n\n```console\npytest tests.py\n```\n\nWith coverage:\n\n```console\npytest --cov=makeweb --cov-report=term tests.py\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Make interactive web apps using good ol' HTML, CSS and a sprinkling of JavaScript \u2014 in Python.",
    "version": "0.2.3",
    "project_urls": null,
    "split_keywords": [
        "website",
        " html",
        " css",
        " javascript",
        " generate",
        " template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e754eaa648082a977f03288c82f22e2505b58e876f699723d0de5601b5b9c07b",
                "md5": "b237630083608844e9845cead2a3aaab",
                "sha256": "3234fac95cbc2228008e172bc9dd84255295c731b8199f906ac0a566470776f5"
            },
            "downloads": -1,
            "filename": "makeweb-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b237630083608844e9845cead2a3aaab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 10598,
            "upload_time": "2025-01-25T23:10:14",
            "upload_time_iso_8601": "2025-01-25T23:10:14.008348Z",
            "url": "https://files.pythonhosted.org/packages/e7/54/eaa648082a977f03288c82f22e2505b58e876f699723d0de5601b5b9c07b/makeweb-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c774ac2bb3b8bda4b956e25dd2e8ef6ae1d8d71a7b8030f3b1826334a73833e6",
                "md5": "493aae2d541e0b848f6bccd065eabb88",
                "sha256": "bb6d141234af95425535c8ecc67806d3f061b3b414e2f99dacd18693d77e6720"
            },
            "downloads": -1,
            "filename": "makeweb-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "493aae2d541e0b848f6bccd065eabb88",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 11420,
            "upload_time": "2025-01-25T23:10:16",
            "upload_time_iso_8601": "2025-01-25T23:10:16.157194Z",
            "url": "https://files.pythonhosted.org/packages/c7/74/ac2bb3b8bda4b956e25dd2e8ef6ae1d8d71a7b8030f3b1826334a73833e6/makeweb-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-25 23:10:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "makeweb"
}
        
Elapsed time: 0.42324s