Skip to content

Releases: HapticX/happyx

v2.3.0

19 Aug 15:31
Compare
Choose a tag to compare

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

16 Aug 08:52
89cb8d9
Compare
Choose a tag to compare

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

  • Python Bindings 🐍 (#91)
  • Python in HappyX CLI (#105)

Full Changelog: v2.1.0...v2.2.4

v2.1.0

11 Aug 11:30
Compare
Choose a tag to compare

Changelog

  • .hpx files support (#76)

Full Changelog: v2.0.0...v2.1.0

v2.0.0

09 Aug 15:47
Compare
Choose a tag to compare

Changelog

  • Nim v2.0.0 was released, so HappyX supports it 🎉(#98)
  • Automatically generated documentation (#80)
  • New CLI command - serve (#66)

Full Changelog: v1.12.0...v2.0.0

Cookies, status code, hashing

30 Jul 05:30
Compare
Choose a tag to compare

Changelog

  • Hashing (#72)
  • Easily status code changing (#94)
  • Cookies support (#75)
  • Fix (#93, #89)

Components Update

26 Jul 05:33
Compare
Choose a tag to compare

Changelog

  • component methods now support (#77)
  • component constructors now support (#79)
  • enums in path params (#65)
  • fix (#62)
  • fix (#84)
  • improve docs (#71)

`use` statement, refactor, fix

15 Jul 13:45
Compare
Choose a tag to compare

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:
    self.state.val()()
    Now:
    self.state()
  • Fix CSS into component style 🌿

Raw HTML

03 Jul 11:38
Compare
Choose a tag to compare

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

01 Jul 04:22
Compare
Choose a tag to compare

Since v1.7.0 you can use single-quoted strings as autoformatted:

  1. Autoformatting
    var myVar = 1
    # Translates to "Hello, 1"
    "Hello, {myVar}"
  2. Raw string
    var myVar = 1
    # Translates to "Hello, {myVar}"
    """Hello, {myVar}"""
  3. Handle raw strings
    var myVar = 1
    # Translates to "Hello, 1"
    {fmt"""Hello, {myVar}"""}

Auto Translate 👨‍🔬

24 Jun 13:52
Compare
Choose a tag to compare

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