Releases: HapticX/happyx
Releases · HapticX/happyx
v2.3.0
Changelog
- [
Python binds
] Compatibility with Jinja2 (#112)from happyx import new_server, setup_jinja2, TemplateResponse setup_jinja2('./my/dir/with/jinja2/templates') app = new_server() @app.get('/') def home(): return TemplateResponse('index.html')
- [
Python binds
] static files (#111)from happyx import new_server, static app = new_server() app.static('/static', directory='dir')
Python Bindings
Meet - Python Bindings! 👋
Since v2.2.4 you can use HappyX with Python 🐍
Install
pip install happyx
Usage
from happyx import new_server, HttpRequest, RequestModelBase, JsonResponse
class User(RequestModelBase):
name: str
age: int
app = new_server("127.0.0.1", 5000)
user = new_server()
app.mount("/user", user)
@app.get('/')
def home(request: HttpRequest):
print(request)
return "Hello, world!"
@user.get('/')
def user_home(a: int, b: float, c: bool = true):
"""
Try to send GET request to localhost:5000/user/
And try to send queries:
?a=5&b=10.4&c=off
"""
return f"Hello, world! a={a}, b={b}, c={c}"
@user.post('/[u]')
def create_user(u: User):
print(u)
print(u.name)
print(u.age)
return u.to_dict()
app.start()
Changelog
Full Changelog: v2.1.0...v2.2.4
v2.1.0
v2.0.0
Cookies, status code, hashing
Components Update
`use` statement, refactor, fix
Changelog ✨
use
statement - keep your component exemplars in variables and work with it like with objects ✌var comp = use: component MyComponent(myArg = 100): "component slot" tDiv: ... echo comp.myArg.val buildHtml: component comp component MyComponent(myArg = 101)
elem
statement (shortcut for document.getElementById) ✨<input id="myInput">
echo elem(myInput).value
- Built-in UI components 🎴 (compile with
-d:enableUi
)
Docs
Example:buildHtml: component Button: "Click me!" component Input(placeholder = "Edit text ...", label = "Edit text ...")
- events in event handlers 🛠
buildHtml: tInput: @input(ev): # `ev` is just param name. It may be anything. Works with any built-in web event echo ev.data
- Callable states available 🔥
Before:Now:self.state.val()()
self.state()
- Fix CSS into component
style
🌿
Raw HTML
Meet: Raw HTML 🎉
Usage 👨🔬
var myHtml = buildHtml:
tDiv:
"Here is just text"
rawHtml: """
<div>
Here is raw HTML
</div>
"""
CLI ✨
You can easily translate your HTML code into buildHtml
macro with HappyX CLI!
Just run command:
hpx html2tag source.html
source.html
<div>
<a href="/some">Hello</a><br>
<hr>
</div>
source.nim
import happyx
var html = buildHtml:
tDiv:
a(href = "/some"):
Hello
br
hr
String Formatting
Since v1.7.0 you can use single-quoted strings as autoformatted:
- Autoformatting
var myVar = 1 # Translates to "Hello, 1" "Hello, {myVar}"
- Raw string
var myVar = 1 # Translates to "Hello, {myVar}" """Hello, {myVar}"""
- Handle raw strings
var myVar = 1 # Translates to "Hello, 1" {fmt"""Hello, {myVar}"""}
Auto Translate 👨🔬
You can improve your translatable strings since v1.6.0
serve(...):
"/":
return "Hello"
With flag -d:translate
it converts into
serve(...):
"/":
return translate("Hello")
It works for SPA also