From b562d171674c2f75592ff3a0dd25b51d2a2457db Mon Sep 17 00:00:00 2001 From: retoor Date: Wed, 29 Jan 2025 16:41:34 +0100 Subject: [PATCH] Added docks. --- src/snek/docs/__pycache__/app.cpython-312.pyc | Bin 0 -> 2249 bytes src/snek/docs/app.py | 43 +++++++ src/snek/docs/docs/api.html | 61 +++++++++ src/snek/docs/docs/base.html | 116 ++++++++++++++++++ src/snek/docs/docs/form_api_javascript.html | 17 +++ src/snek/docs/docs/form_api_python.html | 92 ++++++++++++++ src/snek/docs/docs/index.html | 37 ++++++ 7 files changed, 366 insertions(+) create mode 100644 src/snek/docs/__pycache__/app.cpython-312.pyc create mode 100644 src/snek/docs/app.py create mode 100644 src/snek/docs/docs/api.html create mode 100644 src/snek/docs/docs/base.html create mode 100644 src/snek/docs/docs/form_api_javascript.html create mode 100644 src/snek/docs/docs/form_api_python.html create mode 100644 src/snek/docs/docs/index.html diff --git a/src/snek/docs/__pycache__/app.cpython-312.pyc b/src/snek/docs/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6f355a637d6bd726ec89d969757d5d74527408fc GIT binary patch literal 2249 zcmb_dO>7fK6rS;}?Tvrp0ETRSfV2?ArX`jl3bYE8f|?!*QB`ifY!~l@th3%VJLCM} zNT@`uBheNr+R#%u^Z-h$a^%jjmzt!qHKkIe7KutdL<+QsL)ABHZxRfL9{Qx6nfEhq z-oAP7n;(+N7y=sUyms#MFhaixCLrK_S{s3B5t+!uHp+@QWaC088^U5O*-}ByhW)i{ zM+(tw6r&J&2btk{WJXAMNou&s$}?Dt{vnuA4RdLVoP{a=R~o9&vyGG1!x%Sd0>mr-6gZlO7uMFY`7xQssOK&Tut zaap!-S^5TliZOzne%1rK#+*++%L|UR2eKdne>eDSrTn&534(iqlhV)2mzw{8(G1e0 zQJ!R^P_zw3^rFGWXJeTQ%&_b?1_$P}IFAaMZJp)vd$8cLV0oC9ip1lJu3L`9be+fY zmXkMzbmC0%q+yym3GUAm$>tHyEiu>;6}oeT@zl8Cm^RT(H&-eUhiMTmQ(}*KabYeS z-Z{!66H{XL6d`KU^_*=`s_QfYe4n6;PrEZY*CZM0T56vSDZmVfZ@qSbU)p*cZ`^)~xa8M!eB z!=1@{%1B*Fe3n{B)s+6K(!a9r@QQNeR}jS);x(nGs`Okxb#rfR;8=Cw*iXuvYjDQ1 zr6-Ex5`1faLP@=gFw}4v=Y?4dnYari`Jm!AY0Xej409nUEoovuLSD#}fqP*|=GO~y z!%2C=hg6pGZ5x_kwbWctm5Frulurb!joA#F5i|O&614dl1pY*GwNT*C+XDI*L}beA zfA#-Igz{Tj!U2}8w+uwI{dxV1vl&Dg%m5C}cDe*`cmeL~%h00qQ8fo$0XB(D~`kv@y|IWFrPb4!ld=Q@3C z93+%@lf)aGjWKAh3^c6eXcCW5X0Q_F@>$oM;fb8<0B|y$%@hfAZ>(Uj+&FaUmtJyB>}fe4DOLkW*qR5vY;r#u3IdU^m6TmmmV?h(KXYm(^9 z)xw@gB#(OJe2GxTlj}i z-`3ULHFcn>4%|FcRflTok*a#+&bDRsXeC*XtJhE5i|?xU?ysC~_H)zr=(74c7^He@ zsXf)yo|RPp{cSrIhp!ITJG<-KkJfi;kD_wAeHF>c_SG0lbk*X!tMT0{@t5koTCI1e z+B%jd)>PoWKp;bGyn|r_4ZfVOM2bUAC-JV*LLfx^y zQ79d&D60|Fp;l6>QQ)3Zk&+KjY9|lkyRYDrL-O5Mqp;TSD4-=^uVWO5z+PQ1xMm5! zRObm@KVLHJhQ>!gKd(I5M9&ZyT&rg*{zpxkoD87np_Cn`V}KHmpVoiHfbbd@|U(0P!~P^hE9Li3IHpN3ng x;ab!HSB4vZa?CpftO$?pgke>}82^mgAE3@((9i=k^eFN&R + + + + + + + +
+
+ Snek + Docs +
+
+ {% block main %} + {% endblock %} +
+
+
+ {% markdown %} + [Respository](https://github.com/retoor/snek) + {% endmarkdown %} +
+ + + \ No newline at end of file diff --git a/src/snek/docs/docs/form_api_javascript.html b/src/snek/docs/docs/form_api_javascript.html new file mode 100644 index 0000000..c83ee7f --- /dev/null +++ b/src/snek/docs/docs/form_api_javascript.html @@ -0,0 +1,17 @@ +{% extends "docs/base.html" %} + +{% block main %} +{% markdown %} +# Form API Javascript + +## Dependencies + - generic-form.js + +## Usage +It's just a HTML component that can be declared using an one liner. Buttons and title are specified server side. +```html + +``` + +{% endmarkdown %} +{% endblock %} \ No newline at end of file diff --git a/src/snek/docs/docs/form_api_python.html b/src/snek/docs/docs/form_api_python.html new file mode 100644 index 0000000..d7e67bc --- /dev/null +++ b/src/snek/docs/docs/form_api_python.html @@ -0,0 +1,92 @@ +{% extends "docs/base.html" %} + +{% block main %} +{% markdown %} +# Form API Javascript + +## Dependencies + - `snek.system.form.Form` + - `snek.system.form.HTMLElement` + - `snek.system.form.FormInputElement` + - `snek.system.form.FormButtonElement` + +## Usage +Here is an example with custom validation. +This example contains a field that checks if user already exists. +If invalid, it adds an error message which automatically invalidates the field. +Handling of the error messages will automatically done client side. + +Forms are usaly located in `snek/form/[form name].py`. + +```python +from snek.system.form import Form, HTMLElement,FormInputElement,FormButtonElement + +class UsernameField(FormInputElement): + + @property + async def errors(self): + result = await super().errors + if self.value and await self.app.services.user.count(username=self.value): + result.append("Username is not available.") + return result + +class RegisterForm(Form): + + title = HTMLElement(tag="h1", text="Register") + + username = UsernameField( + name="username", + required=True, + min_length=2, + max_length=20, + regex=r"^[a-zA-Z0-9_]+$", + place_holder="Username", + type="text" + ) + email = FormInputElement( + name="email", + required=False, + regex=r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$", + place_holder="Email address", + type="email" + ) + password = FormInputElement( + name="password", + required=True, + regex=r"^[a-zA-Z0-9_.+-]{6,}", + type="password", + place_holder="Password" + ) + action = FormButtonElement( + name="action", + value="submit", + text="Register", + type="button" + ) +``` + +## Set data + +```python +# The input structure is in same format as output structure. +# Output structure is the result of await form.to_json() +data = dict( + username=dict(value="retoor"), + password=dict(value="retoorded") +) +form.set_user_data(data) + +# Check if form is valid. +is_valid = await form.is_valid + +# Convert form to a record (kv pairs) to be used for persistance. +# It does contain an filled uid (UUID4) field already to be used as primary key. +# Default fields: +# - uid (automatically generated, it's an UUID4 wich you can use as private key for database) +# - created_at (automatically generated, it's a string representation of UTC locale) +# - updated_at (execute await form.updated_at.update() before saving to set value) +key_value_values = await form.record +``` + +{% endmarkdown %} +{% endblock %} \ No newline at end of file diff --git a/src/snek/docs/docs/index.html b/src/snek/docs/docs/index.html new file mode 100644 index 0000000..8ced8ab --- /dev/null +++ b/src/snek/docs/docs/index.html @@ -0,0 +1,37 @@ +{% extends "docs/base.html" %} + +{% block main %} +{% markdown %} +# Snek + +# Introduction + +Snek is a high customizable chat application. +It is made because Rocket Chat didn't fit my needs anymore. It became bloathed and very heavy commercialized. You would get upsell messages on your locally hosted instance! + +This documentation is under construction. Only the form API and the small introduction is a bit documented. + +## Quick API notes +[Small introduction / cheatsheet](/docs/docs/api.html) + +## View API +With the view classes of Snek you can render HTML and Markdown + - [API Python](#) + - [API Javascript](#) + +## ORM API +Snek's database model is based on Python dataset library. +Snek uses a model/mapper architecture build on top of that library. + - [API](#) + +## Form API +Snek does have his own components for creating and rendering forms. +All forms are made server side and client side is generated client side using a HTML component. +It's client side only one line to include a form that can validate and submit. +Validation is server side using REST. Page won't refresh. +[API Python](/docs/docs/form_api_python.html) +[API Javascript](/docs/docs/form_api_javascript.html) + + +{% endmarkdown %} +{% endblock %} \ No newline at end of file