0
# Static Files and Assets
1
2
Static file management system for CSS, JavaScript, images, and other assets with automatic URL generation, dependency ordering, and development/production optimization.
3
4
## Capabilities
5
6
### Static File Classes
7
8
Classes for managing different types of static assets.
9
10
```python { .api }
11
class StaticFile:
12
def __init__(self, name: str, path: str = '', string: str = ''):
13
"""
14
Base static file descriptor.
15
16
Args:
17
name (str): File identifier name
18
path (str): File system path
19
string (str): File content as string
20
"""
21
22
# Properties
23
name: str # File identifier
24
path: str # File system path
25
url: str # Generated URL
26
sort_order: int # Loading order priority
27
link: str # HTML link tag
28
enabled_by_default: bool # Default enabled state
29
enabled: bool # Current enabled state
30
static_url_prefix: str # URL prefix for static files
31
32
class StyleSheet(StaticFile):
33
"""CSS stylesheet file descriptor."""
34
35
class Script(StaticFile):
36
"""JavaScript file descriptor."""
37
```
38
39
### Sort Order Constants
40
41
Constants for controlling static file loading order.
42
43
```python { .api }
44
class SORT_ORDER:
45
FRAMEWORK: int = 100 # Framework files (loaded first)
46
LIBRARY: int = 200 # Library files (loaded second)
47
APPLICATION: int = 300 # Application files (loaded last)
48
```
49
50
### App Static File Methods
51
52
Methods for registering static files with the application.
53
54
```python { .api }
55
# Available on App class
56
def add_static_file(self, name: str, string: str = '', path: str = ''):
57
"""
58
Add static file to application.
59
60
Args:
61
name (str): File name/identifier
62
string (str): File content as string
63
path (str): Path to file on disk
64
"""
65
```
66
67
#### Usage Example
68
69
```python
70
from lona import App
71
from lona.static_files import StyleSheet, Script, SORT_ORDER
72
73
app = App(__file__)
74
75
# Add CSS files
76
app.add_static_file('bootstrap.css', path='static/css/bootstrap.min.css')
77
app.add_static_file('main.css', path='static/css/main.css')
78
79
# Add JavaScript files
80
app.add_static_file('jquery.js', path='static/js/jquery.min.js')
81
app.add_static_file('app.js', path='static/js/app.js')
82
83
# Using static file objects
84
bootstrap_css = StyleSheet('bootstrap', path='static/bootstrap.min.css')
85
custom_js = Script('custom', string='console.log("Hello World");')
86
```
87
88
## Types
89
90
```python { .api }
91
from typing import Union, Optional
92
93
StaticFileName = str
94
StaticFilePath = str
95
StaticFileContent = str
96
SortOrderValue = int
97
```