From c05d45995516508ce08e991415b96ff968671f66 Mon Sep 17 00:00:00 2001 From: Chima Precious Date: Fri, 22 Dec 2023 04:01:49 +0000 Subject: [PATCH] tiny fixes (#15) --- yaroo/lib/src/_router/router.dart | 5 ++++- yaroo/lib/src/_router/utils.dart | 3 ++- yaroo/lib/src/core.dart | 4 ++-- yaroo/pubspec.yaml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/yaroo/lib/src/_router/router.dart b/yaroo/lib/src/_router/router.dart index 604effc6..cadef3d5 100644 --- a/yaroo/lib/src/_router/router.dart +++ b/yaroo/lib/src/_router/router.dart @@ -61,5 +61,8 @@ abstract interface class Route { } static FunctionalRouteDefinition handler(HTTPMethod method, String path, RequestHandler handler) => - FunctionalRouteDefinition(HTTPMethod.GET, path, handler); + FunctionalRouteDefinition(method, path, handler); + + static FunctionalRouteDefinition notFound(RequestHandler handler, [HTTPMethod method = HTTPMethod.ALL]) => + FunctionalRouteDefinition(method, '/*', handler); } diff --git a/yaroo/lib/src/_router/utils.dart b/yaroo/lib/src/_router/utils.dart index acd373d8..3aeb2850 100644 --- a/yaroo/lib/src/_router/utils.dart +++ b/yaroo/lib/src/_router/utils.dart @@ -1,7 +1,8 @@ import 'dart:io'; String cleanRoute(String route) { - return route.replaceAll(RegExp(r'/+$'), '').replaceAll(RegExp(r'/+'), '/'); + final result = route.replaceAll(RegExp(r'/+'), '/').replaceAll(RegExp(r'/$'), ''); + return result.isEmpty ? '/' : result; } String symbolToString(Symbol symbol) { diff --git a/yaroo/lib/src/core.dart b/yaroo/lib/src/core.dart index 1ea5a6b5..026817e2 100644 --- a/yaroo/lib/src/core.dart +++ b/yaroo/lib/src/core.dart @@ -55,9 +55,9 @@ class AppServiceProvider extends ServiceProvider { autoReload: false, trimBlocks: true, leftStripBlocks: true, - loader: FileSystemLoader(paths: ['public']), + loader: FileSystemLoader(paths: ['public', 'templates'], extensions: {'j2'}), ); - app.useViewEngine(JinjaViewEngine(environment)); + app.useViewEngine(JinjaViewEngine(environment, fileExt: 'j2')); } } diff --git a/yaroo/pubspec.yaml b/yaroo/pubspec.yaml index 541bf009..3a1bb0dd 100644 --- a/yaroo/pubspec.yaml +++ b/yaroo/pubspec.yaml @@ -17,7 +17,7 @@ dependencies: git: url: https://github.com/codekeyz/pharaoh.git path: packages/pharaoh - spanner: ^1.0.1+1 + spanner: ^1.0.1+2 spookie: ^1.0.2+1 meta: ^1.11.0 collection: ^1.18.0