Skip to content

Commit

Permalink
✨ Update error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
perdy committed Feb 24, 2025
1 parent bd02fb0 commit 5c63323
Show file tree
Hide file tree
Showing 67 changed files with 2,331 additions and 1,951 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dist/
downloads/
eggs/
.eggs/
lib/
./lib/
lib64/
parts/
sdist/
Expand Down
12 changes: 7 additions & 5 deletions flama/debug/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,22 @@ def from_route(cls, route: t.Union["Route", "WebSocketRoute"]) -> "Endpoint":

@dataclasses.dataclass(frozen=True)
class App:
urls: list[t.Union[Endpoint, "App"]]
apps: list["App"]
endpoints: list[Endpoint]
path: str
name: t.Optional[str] = None

@classmethod
def from_app(cls, app: t.Any, path: str = "/", name: t.Optional[str] = None) -> "App":
urls: list[t.Union[Endpoint, App]] = []
apps: list[App] = []
endpoints: list[Endpoint] = []
for route in app.routes:
try:
urls.append(App.from_app(route.app, path=route.path.path, name=route.name))
apps.append(App.from_app(route.app, path=route.path.path, name=route.name))
except AttributeError:
urls.append(Endpoint.from_route(route))
endpoints.append(Endpoint.from_route(route))

return cls(urls=urls, path=path, name=name)
return cls(apps=apps, endpoints=endpoints, path=path, name=name)


@dataclasses.dataclass(frozen=True)
Expand Down
20 changes: 19 additions & 1 deletion flama/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,30 @@ def __init__(self, *args, **kwargs):
*args,
**{
**kwargs,
"comment_start_string": "||*",
"comment_end_string": "*||",
"block_start_string": "||%",
"block_end_string": "%||",
"variable_start_string": "||@",
"variable_end_string": "@||",
},
)

self.filters["safe"] = self.safe
self.filters["safe_json"] = self.safe_json

@t.overload
def _escape(self, value: str) -> str: ...
@t.overload
def _escape(self, value: bool) -> bool: ...
@t.overload
def _escape(self, value: int) -> int: ...
@t.overload
def _escape(self, value: float) -> float: ...
@t.overload
def _escape(self, value: None) -> None: ...
@t.overload
def _escape(self, value: types.JSONField) -> types.JSONField: ...
def _escape(self, value: types.JSONField) -> types.JSONField:
if isinstance(value, (list, tuple)):
return [self._escape(x) for x in value]
Expand All @@ -227,10 +242,13 @@ def _escape(self, value: types.JSONField) -> types.JSONField:
return {k: self._escape(v) for k, v in value.items()}

if isinstance(value, str):
return html.escape(value).replace("\n", "
")
return html.escape(value).replace("\n", "

")

return value

def safe(self, value: str) -> str:
return self._escape(value)

def safe_json(self, value: types.JSONField):
return json.dumps(self._escape(value)).replace('"', '\\"')

Expand Down
2 changes: 1 addition & 1 deletion flama/types/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__all__ = ["JSONField", "JSONSchema"]


JSONField = t.Union[str, int, float, bool, None, list["JSONField"], dict[str, "JSONField"]]
JSONField = t.Union[str, bool, int, float, None, list["JSONField"], dict[str, "JSONField"]]
JSONSchema = dict[str, JSONField]
44 changes: 43 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@tabler/icons-react": "^3.30.0"
}
}
7 changes: 6 additions & 1 deletion templates/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const config = {
corejs: { version: 3, proposals: true },
},
],
'@babel/preset-react',
[
'@babel/preset-react',
{
runtime: 'automatic',
},
],
'@babel/preset-typescript',
],
plugins: ['@babel/plugin-transform-runtime', '@babel/plugin-transform-spread'],
Expand Down
1 change: 1 addition & 0 deletions templates/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default [
rules: {
// turn on errors for missing imports
'import/no-unresolved': 'error',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^React$' }],
},
settings: {
'import/parsers': {
Expand Down
Loading

0 comments on commit 5c63323

Please sign in to comment.