first release

This commit is contained in:
Will Abbott 2024-06-08 14:33:11 +01:00
parent c38c990b5b
commit 4c4d00d4df
2269 changed files with 323498 additions and 2 deletions

View file

@ -0,0 +1,16 @@
"""
ASGI config for django_cotton project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_project.settings")
application = get_asgi_application()

View file

@ -0,0 +1,136 @@
"""
Django settings for django_cotton project.
Generated by 'django-admin startproject' using Django 4.2.8.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from pathlib import Path
# SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-%)7a&zw=le4uey^36*z*9^4#*iii65t)nyt$36mxq70@=(z6^n"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["0.0.0.0"]
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_cotton",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "django_cotton.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["example_project/templates", "django_cotton/templates"],
"APP_DIRS": False,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
"loaders": [
"django_cotton.cotton_loader.Loader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
"builtins": [
"django.templatetags.static",
"django_cotton.templatetags.cotton",
],
},
},
]
WSGI_APPLICATION = "django_cotton.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = "static/"
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
COTTON_TEMPLATE_CACHING_ENABLED = False

View file

@ -0,0 +1,3 @@
<c-parent>
<c-child>d</c-child>
</c-parent>

View file

@ -0,0 +1,9 @@
<c-benchmarks.partials.main>
I'm default
<c-slot name="top">
I'm top
</c-slot>
<c-slot name="bottom">
I'm bottom
</c-slot>
</c-benchmarks.partials.main>

View file

@ -0,0 +1,9 @@
{% cotton_component cotton/benchmarks/partials/main.cotton.html %}
I'm default
{% cotton_slot top %}
I'm top
{% end_cotton_slot %}
{% cotton_slot bottom %}
I'm bottom
{% end_cotton_slot %}
{% end_cotton_component %}

View file

@ -0,0 +1,13 @@
{% extends "cotton/benchmarks/partials/native_main.html" %}
{% block top %}
I'm top
{% endblock %}
{% block content %}
I'm default
{% endblock %}
{% block bottom %}
I'm bottom
{% endblock %}

View file

@ -0,0 +1,5 @@
{{ top }}
{{ slot }}
{{ bottom }}

View file

@ -0,0 +1,5 @@
{% block top %}{% endblock %}
{% block content %}{% endblock %}
{% block bottom %}{% endblock %}

View file

@ -0,0 +1 @@
<div class="i-am-child"></div>

View file

@ -0,0 +1,3 @@
<div>
{{ name }}
</div>

View file

@ -0,0 +1,3 @@
<div class="i-am-parent">
{{slot}}
</div>

View file

@ -0,0 +1,12 @@
<c-props prop1="sds" prop_with_default="1" />
<div>
{{ testy }}
<p>prop1: '{{ prop1 }}'</p>
<p>attr1: '{{ attr1 }}'</p>
<p>empty_prop: '{{ empty_prop }}'</p>
<p>prop_with_default: '{{ prop_with_default }}'</p>
<p>slot: '{{ slot }}'</p>
<p>named_slot: '{{ named_slot }}'</p>
<p>attrs: '{{ attrs }}'</p>
</div>

View file

@ -0,0 +1,3 @@
<c-parent>
<c-forms.input name="test" style="width: 100%" silica:model="first_name"/>
</c-parent>

View file

@ -0,0 +1,7 @@
{% for item in items %}
<c-named-slot-component>
<c-slot name="name">
item name: {{ item.name }}
</c-slot>
</c-named-slot-component>
{% endfor %}

View file

@ -0,0 +1 @@
<c-parent></c-parent>

View file

@ -0,0 +1,3 @@
<c-props-test-component prop1="im a prop" attr1="im an attr">
default slot
</c-props-test-component>

View file

@ -0,0 +1,4 @@
{% load static %}
<c-parent/>

22
dev/example_project/manage.py Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()

View file

@ -0,0 +1,24 @@
[project]
name = "cotton-dev-app"
requires-python = ">=3.8, <4"
dependencies = [
"django~=4.2.6",
"beautifulsoup4~=4.12.2",
"selenium~=4.13.0",
"chromedriver-py~=117.0.5938.92",
"webdriver-manager~=4.0.1"
]
[tool.poetry]
name = "cotton-dev-app"
version = "0.1"
description = "Development and test app for the django package."
authors = ["Will Abbott <wabbott@dyvenia.com>"]
[tool.poetry.dependencies]
python = "^3.8"
Django = "^4.2"
beautifulsoup4 = "~4.12.2"
selenium = "~4.13.0"
chromedriver-py = "~117.0.5938.92"
webdriver-manager = "~4.0.1"

View file

@ -0,0 +1,71 @@
from django.conf import settings
import time
from django.template.loader import render_to_string
import django
# Configure Django settings
settings.configure(
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_cotton",
],
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["example_project/templates"],
"APP_DIRS": False,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
"loaders": [
"django_cotton.cotton_loader.Loader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
"builtins": [
"django.templatetags.static",
"django_cotton.templatetags.cotton",
],
},
},
],
)
django.setup()
def benchmark_template_rendering(template_name, iterations=1000):
start_time = time.time()
for _ in range(iterations):
render_to_string(template_name)
end_time = time.time()
return end_time - start_time, render_to_string(template_name)
# Benchmarking each template
time_native_extends, output_native_extends = benchmark_template_rendering(
"cotton/benchmarks/native_extends.html"
)
# time_native_include, output_native_include = benchmark_template_rendering('cotton/benchmarks/native_include.html')
time_compiled_cotton, output_compiled_cotton = benchmark_template_rendering(
"cotton/benchmarks/cotton_compiled.html"
)
time_cotton, output_cotton = benchmark_template_rendering(
"cotton/benchmarks/cotton.cotton.html"
)
# Output results
print(f"Native Django Template using extend: {time_native_extends} seconds")
# print(f"Native Django Template using include: {time_native_include} seconds")
print(f"Compiled Cotton Template: {time_compiled_cotton} seconds")
print(f"Cotton Template: {time_cotton} seconds")