feat: Implement initial view package structure

This commit is contained in:
Patrick Stewart (aider) 2024-10-26 21:26:41 -07:00
parent 4c19408d1b
commit f22dd8c495
4 changed files with 72 additions and 0 deletions

6
packages/view/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
.dart_tool/
.packages
pubspec.lock
.pub/
build/
coverage/

View file

@ -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<String, dynamic> 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<String> 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!;
}
}

View file

@ -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';

View file

@ -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