-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from javad-zobeidi/dev
Improve Template engine
- Loading branch information
Showing
11 changed files
with
186 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'dart:io'; | ||
|
||
class RouteHistory { | ||
static final RouteHistory _instance = RouteHistory._internal(); | ||
factory RouteHistory() => _instance; | ||
RouteHistory._internal(); | ||
|
||
String _currentRoute = ''; | ||
String _previousRoute = ''; | ||
|
||
String get currentRoute => _currentRoute; | ||
String get previousRoute => _previousRoute; | ||
|
||
Future<void> updateRouteHistory(HttpRequest req) async { | ||
if (req.headers.value('accept').toString().contains('html')) { | ||
if (_currentRoute.isEmpty) { | ||
_currentRoute = req.uri.path; | ||
} else { | ||
_previousRoute = _currentRoute; | ||
_currentRoute = req.uri.path; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:vania/src/view_engine/template_engine.dart'; | ||
|
||
import 'abs_processor.dart'; | ||
|
||
class ErrorProcessor extends AbsProcessor { | ||
@override | ||
String parse(String content, [Map<String, dynamic>? context]) { | ||
final hasErrorPattern = RegExp( | ||
r"hasError\(\s*'([^']*)'\s*\)", | ||
dotAll: true, | ||
); | ||
content = content.replaceAllMapped(hasErrorPattern, (match) { | ||
final errorKey = match.group(1); | ||
return TemplateEngine().sessionErrors.containsKey(errorKey).toString(); | ||
}); | ||
|
||
final errorPattern = RegExp( | ||
r"\{@\s*error\(\s*'([^']*)'\s*\)\s*@\}", | ||
dotAll: true, | ||
); | ||
|
||
content = content.replaceAllMapped(errorPattern, (error) { | ||
final errorKey = error.group(1); | ||
return TemplateEngine().sessionErrors[errorKey] ?? ''; | ||
}); | ||
|
||
return content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:vania/src/view_engine/template_engine.dart'; | ||
|
||
import 'abs_processor.dart'; | ||
|
||
class OldProcessor extends AbsProcessor { | ||
@override | ||
String parse(String content, [Map<String, dynamic>? context]) { | ||
final oldPattern = RegExp( | ||
r"\{@\s*old\(\s*'([^']*)'\s*\)\s*@\}", | ||
dotAll: true, | ||
); | ||
|
||
content = content.replaceAllMapped(oldPattern, (oldMatch) { | ||
final oldKey = oldMatch.group(1); | ||
return TemplateEngine().formData[oldKey] ?? ''; | ||
}); | ||
|
||
return content; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
lib/src/view_engine/processor_engine/session_processor.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:vania/src/view_engine/processor_engine/abs_processor.dart'; | ||
import 'package:vania/src/view_engine/template_engine.dart'; | ||
|
||
class SessionProcessor implements AbsProcessor { | ||
@override | ||
String parse(String content, [Map<String, dynamic>? context]) { | ||
final hasSessionPattern = RegExp( | ||
r"hasSession\(\s*'([^']*)'\s*\)", | ||
dotAll: true, | ||
); | ||
|
||
content = content.replaceAllMapped(hasSessionPattern, (match) { | ||
final sessionKey = match.group(1); | ||
return TemplateEngine().sessions.containsKey(sessionKey).toString(); | ||
}); | ||
|
||
final sessionPattern = RegExp( | ||
r"\{@\s*session\(\s*'([^']*)'\s*\)\s*@\}", | ||
dotAll: true, | ||
); | ||
|
||
content = content.replaceAllMapped(sessionPattern, (math) { | ||
final sessionKey = math.group(1); | ||
return TemplateEngine().sessions[sessionKey] ?? ''; | ||
}); | ||
|
||
return content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters