From f22dd8c495e59b6e192a2ddeff181ea5559de7f5 Mon Sep 17 00:00:00 2001 From: "Patrick Stewart (aider)" Date: Sat, 26 Oct 2024 21:26:41 -0700 Subject: [PATCH] feat: Implement initial view package structure --- packages/view/.gitignore | 6 +++++ packages/view/lib/src/view.dart | 40 +++++++++++++++++++++++++++++++++ packages/view/lib/view.dart | 10 +++++++++ packages/view/pubspec.yaml | 16 +++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 packages/view/.gitignore create mode 100644 packages/view/lib/src/view.dart create mode 100644 packages/view/lib/view.dart create mode 100644 packages/view/pubspec.yaml diff --git a/packages/view/.gitignore b/packages/view/.gitignore new file mode 100644 index 0000000..3cf1f6c --- /dev/null +++ b/packages/view/.gitignore @@ -0,0 +1,6 @@ +.dart_tool/ +.packages +pubspec.lock +.pub/ +build/ +coverage/ diff --git a/packages/view/lib/src/view.dart b/packages/view/lib/src/view.dart new file mode 100644 index 0000000..ee754aa --- /dev/null +++ b/packages/view/lib/src/view.dart @@ -0,0 +1,40 @@ +import 'package:path/path.dart' as path; +import 'engine.dart'; +import 'factory.dart'; + +/// Represents a view instance that can be rendered +class View { + /// The view factory instance + final Factory factory; + + /// The engine implementation + final Engine engine; + + /// The name of the view + final String path; + + /// The data passed to the view + final Map data; + + /// The path to the view file + String? _path; + + View(this.factory, this.engine, this.path, [this.data = const {}]); + + /// Get the string contents of the view + Future render() async { + return await engine.get(this); + } + + /// Get the evaluated contents of the view + String toString() { + return path; + } + + /// Get the full path to the view + String getPath() { + if (_path != null) return _path!; + _path = factory.finder.find(path); + return _path!; + } +} diff --git a/packages/view/lib/view.dart b/packages/view/lib/view.dart new file mode 100644 index 0000000..107c1d7 --- /dev/null +++ b/packages/view/lib/view.dart @@ -0,0 +1,10 @@ +library view; + +export 'src/view.dart'; +export 'src/factory.dart'; +export 'src/finder.dart'; +export 'src/engine.dart'; +export 'src/engines/php_engine.dart'; +export 'src/engines/blade_engine.dart'; +export 'src/engines/file_engine.dart'; +export 'src/exceptions.dart'; diff --git a/packages/view/pubspec.yaml b/packages/view/pubspec.yaml new file mode 100644 index 0000000..4fe39ce --- /dev/null +++ b/packages/view/pubspec.yaml @@ -0,0 +1,16 @@ +name: view +description: View rendering package implementing Laravel-style view system +version: 0.1.0 + +environment: + sdk: '>=3.0.0 <4.0.0' + +dependencies: + path: ^1.8.0 + meta: ^1.9.0 + collection: ^1.18.0 + mustache_template: ^2.0.0 + +dev_dependencies: + test: ^1.24.0 + lints: ^2.1.0