Write responsive web apps in full python
—
Static file management system for CSS, JavaScript, images, and other assets with automatic URL generation, dependency ordering, and development/production optimization.
Classes for managing different types of static assets.
class StaticFile:
def __init__(self, name: str, path: str = '', string: str = ''):
"""
Base static file descriptor.
Args:
name (str): File identifier name
path (str): File system path
string (str): File content as string
"""
# Properties
name: str # File identifier
path: str # File system path
url: str # Generated URL
sort_order: int # Loading order priority
link: str # HTML link tag
enabled_by_default: bool # Default enabled state
enabled: bool # Current enabled state
static_url_prefix: str # URL prefix for static files
class StyleSheet(StaticFile):
"""CSS stylesheet file descriptor."""
class Script(StaticFile):
"""JavaScript file descriptor."""Constants for controlling static file loading order.
class SORT_ORDER:
FRAMEWORK: int = 100 # Framework files (loaded first)
LIBRARY: int = 200 # Library files (loaded second)
APPLICATION: int = 300 # Application files (loaded last)Methods for registering static files with the application.
# Available on App class
def add_static_file(self, name: str, string: str = '', path: str = ''):
"""
Add static file to application.
Args:
name (str): File name/identifier
string (str): File content as string
path (str): Path to file on disk
"""from lona import App
from lona.static_files import StyleSheet, Script, SORT_ORDER
app = App(__file__)
# Add CSS files
app.add_static_file('bootstrap.css', path='static/css/bootstrap.min.css')
app.add_static_file('main.css', path='static/css/main.css')
# Add JavaScript files
app.add_static_file('jquery.js', path='static/js/jquery.min.js')
app.add_static_file('app.js', path='static/js/app.js')
# Using static file objects
bootstrap_css = StyleSheet('bootstrap', path='static/bootstrap.min.css')
custom_js = Script('custom', string='console.log("Hello World");')from typing import Union, Optional
StaticFileName = str
StaticFilePath = str
StaticFileContent = str
SortOrderValue = intInstall with Tessl CLI
npx tessl i tessl/pypi-lona