Skip to content

Commit

Permalink
Merge pull request #55 from tetra-framework/tetra-package
Browse files Browse the repository at this point in the history
change package name to "tetra"
  • Loading branch information
nerdoc authored Apr 14, 2024
2 parents f98e255 + 6fbc766 commit 0655743
Show file tree
Hide file tree
Showing 60 changed files with 1,032 additions and 203 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: pytest-django CI

on:
push:
# TODO: change that to "main" when merging
branches: [ "tetra-package" ]
pull_request:
branches: [ "tetra-package" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.11, 3.12]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[dev]
cd tests
npm install
- name: Run Tests
run: |
cd tests
pytest
16 changes: 16 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Read the Docs configuration file for MkDocs projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

version: 2

build:
os: ubuntu-22.04
tools:
python: "3.12"

mkdocs:
configuration: mkdocs.yml

python:
install:
- requirements: docs/requirements.txt
5 changes: 4 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
recursive-include tetra/static *
recursive-include tetra/js *
recursive-include tetra/templates *
prune demosites
prune demosite
prune .github
exclude mkdocs.yml
exclude .readthedocs.yaml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Tetra is a new full stack component framework for Django, bridging the gap betwe

See examples at [tetraframework.com](https://www.tetraframework.com)

Read the [Documentation](https://www.tetraframework.com/docs)
Read the [Documentation](https://tetra.readthedocs.org)

```
pip install tetraframework
pip install tetra
```

## What does Tetra do?
Expand Down
5 changes: 5 additions & 0 deletions demosite/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEBUG=True
SECRET_KEY=
# ALLOWED_HOSTS="www.tetraframework.com,tetraframework.com"
# CSRF_TRUSTED_ORIGINS="https://www.tetraframework.com,https://tetraframework.com"
# STATIC_ROOT="..."
19 changes: 11 additions & 8 deletions demosite/demo/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ def load(self):
self.todos = ToDo.objects.filter(session_key=self.request.session.session_key)

@public
def add_todo(self, title):
todo = ToDo(
title=title,
session_key=self.request.session.session_key,
)
todo.save()
self.title = ""
def add_todo(self, title: str):
if self.title:
todo = ToDo(
title=title,
session_key=self.request.session.session_key,
)
todo.save()
self.title = ""

template: django_html = """
<div>
<div class="input-group mb-2">
<input type="text" x-model="title" class="form-control"
placeholder="New task..." @keyup.enter="add_todo(title)">
<button class="btn btn-primary" @click="add_todo(title)">Add</button>
<button class="btn btn-primary" :class="{'disabled': title == ''}"
@click="add_todo(
title)">Add</button>
</div>
<div class="list-group">
{% for todo in todos %}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
demo_default-GUWUK47B.js
demo_default-JLCHQSL2.js
36 changes: 25 additions & 11 deletions demosite/demosite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@

import os
from pathlib import Path
import environ

env = environ.Env(
# set casting, default value
DEBUG=(bool, False)
)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Take environment variables from .env file
environ.Env.read_env(os.path.join(BASE_DIR, ".env"))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY", "insecure!")
# Raises Django's ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG", False) == "True"
DEBUG = env("DEBUG")
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=["127.0.0.1", "localhost"])

ALLOWED_HOSTS = [
"localhost",
"127.0.0.1",
"www.tetraframework.com",
"tetraframework.com",
]
CSRF_TRUSTED_ORIGINS = ["https://www.tetraframework.com", "https://tetraframework.com"]
CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", default=[])


# Application definition
Expand All @@ -50,6 +55,7 @@

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
Expand Down Expand Up @@ -126,8 +132,16 @@
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "static"
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STATIC_ROOT = env("STATIC_ROOT", default=BASE_DIR / "static")

# STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STORAGES = (
{
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
},
)

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
Expand Down
11 changes: 0 additions & 11 deletions dev-requirements.txt

This file was deleted.

13 changes: 8 additions & 5 deletions docs/attribute-tag.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Title: Attribute Tag
---
title: "The `...` Attribute"
---

# `...` Attribute Tag

Expand All @@ -12,7 +14,7 @@ The attributes tag is automaticity available in your component templates. In oth
checked=a_boolian_varible %}>
```

All Tetra components have a `attrs` context available, which is a `dict` of attributes that have been passed to the component when it is included in a template with the [`@` tag](component-tag). It can be unpacked as HTML attributes on your root node:
All Tetra components have an `attrs` context available, which is a `dict` of attributes that have been passed to the component when it is included in a template with the [`@` tag](component-tag.md). It can be unpacked as HTML attributes on your root node:

``` django
<div {% ... attrs %}>
Expand Down Expand Up @@ -68,14 +70,15 @@ Would result in:
<div style="font-size:2em; color:blue;">
```

> **Note:** Tetra currently does not understand that a style property can be applied in multiple ways. Therefore, if you pass both `margin-top: 1em` and `margin: 2em 0 0 0`, both will appear in the final HTML style tag, with the final property taking precedence in the browser.
!!! note
Tetra currently does not understand that a style property can be applied in multiple ways. Therefore, if you pass both `margin-top: 1em` and `margin: 2em 0 0 0`, both will appear in the final HTML style tag, with the final property taking precedence in the browser.

## Conditional values

The [`if` and `else` template filters](if-else-filters) are provided to enable conditional attribute values:
The [`if` and `else` template filters](if-else-filters.md) are provided to enable conditional attribute values:

``` html
<div {% ... class="class1"|if:variable_name|else:"class2" %}>
```

See the documentation for the [`if` and `else` template filters](if-else-filters).
See the documentation for the [`if` and `else` template filters](if-else-filters.md).
4 changes: 3 additions & 1 deletion docs/basic-components.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Title: Basic Components
---
title: Basic Components
---

# Basic Components

Expand Down
Loading

0 comments on commit 0655743

Please sign in to comment.