feat: Implement initial view package structure
This commit is contained in:
parent
4c19408d1b
commit
f22dd8c495
4 changed files with 72 additions and 0 deletions
6
packages/view/.gitignore
vendored
Normal file
6
packages/view/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
.dart_tool/
|
||||
.packages
|
||||
pubspec.lock
|
||||
.pub/
|
||||
build/
|
||||
coverage/
|
40
packages/view/lib/src/view.dart
Normal file
40
packages/view/lib/src/view.dart
Normal 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!;
|
||||
}
|
||||
}
|
10
packages/view/lib/view.dart
Normal file
10
packages/view/lib/view.dart
Normal 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';
|
16
packages/view/pubspec.yaml
Normal file
16
packages/view/pubspec.yaml
Normal 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
|
Loading…
Reference in a new issue