From d56697a20e0c08f0e9c81386c0f90e9ef97f9dd5 Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Sun, 27 Oct 2024 15:16:20 -0700 Subject: [PATCH] remove: removing view package test --- packages/view/lib/src/engine.dart | 13 ----- packages/view/lib/src/exceptions.dart | 18 ------ packages/view/lib/src/factory.dart | 82 --------------------------- packages/view/lib/src/finder.dart | 52 ----------------- packages/view/lib/src/view.dart | 40 ------------- packages/view/lib/view.dart | 10 ---- 6 files changed, 215 deletions(-) delete mode 100644 packages/view/lib/src/engine.dart delete mode 100644 packages/view/lib/src/exceptions.dart delete mode 100644 packages/view/lib/src/factory.dart delete mode 100644 packages/view/lib/src/finder.dart delete mode 100644 packages/view/lib/src/view.dart delete mode 100644 packages/view/lib/view.dart diff --git a/packages/view/lib/src/engine.dart b/packages/view/lib/src/engine.dart deleted file mode 100644 index cad0e42..0000000 --- a/packages/view/lib/src/engine.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'view.dart'; - -/// Abstract engine interface for view rendering -abstract class Engine { - /// Get the evaluated contents of the view - Future get(View view); - - /// Add a piece of shared data to the engine - void share(String key, dynamic value); - - /// Get all of the shared data for the engine - Map getShared(); -} diff --git a/packages/view/lib/src/exceptions.dart b/packages/view/lib/src/exceptions.dart deleted file mode 100644 index d02b18c..0000000 --- a/packages/view/lib/src/exceptions.dart +++ /dev/null @@ -1,18 +0,0 @@ -/// Base exception for view related errors -class ViewException implements Exception { - final String message; - ViewException(this.message); - - @override - String toString() => 'ViewException: $message'; -} - -/// Exception thrown when a view is not found -class ViewNotFoundException extends ViewException { - ViewNotFoundException(String message) : super(message); -} - -/// Exception thrown when there's an error compiling the view -class ViewCompileException extends ViewException { - ViewCompileException(String message) : super(message); -} diff --git a/packages/view/lib/src/factory.dart b/packages/view/lib/src/factory.dart deleted file mode 100644 index dc424a9..0000000 --- a/packages/view/lib/src/factory.dart +++ /dev/null @@ -1,82 +0,0 @@ -import 'dart:async'; -import 'package:path/path.dart' as path; -import 'engine.dart'; -import 'finder.dart'; -import 'view.dart'; -import 'exceptions.dart'; - -/// The view factory implementation -class Factory { - /// The view finder implementation - final ViewFinder finder; - - /// The engine resolver callback - final FutureOr Function(String) engineResolver; - - /// The extension to engine mappings - final Map extensions; - - /// The shared data for the factory - final Map _shared = {}; - - /// The view composers - final Map> _composers = {}; - - /// The view creators - final Map> _creators = {}; - - Factory(this.finder, this.engineResolver, [this.extensions = const {}]); - - /// Create a new view instance - Future make(String path, [Map data = const {}]) async { - String normalizedPath = _normalizePath(path); - - // Determine the engine for this view - String extension = path.split('.').last; - String engineName = extensions[extension] ?? 'file'; - Engine engine = await engineResolver(engineName); - - // Create the view instance - View view = View(this, engine, normalizedPath, {..._shared, ...data}); - - // Call creators - _callCreators(view); - - // Call composers - _callComposers(view); - - return view; - } - - /// Add a piece of shared data to the factory - void share(String key, dynamic value) { - _shared[key] = value; - } - - /// Register a view composer - void composer(String path, Function(View) callback) { - _composers.putIfAbsent(path, () => []).add(callback); - } - - /// Register a view creator - void creator(String path, Function(View) callback) { - _creators.putIfAbsent(path, () => []).add(callback); - } - - /// Call the creators for a given view - void _callCreators(View view) { - List? creators = _creators[view.path]; - creators?.forEach((creator) => creator(view)); - } - - /// Call the composers for a given view - void _callComposers(View view) { - List? composers = _composers[view.path]; - composers?.forEach((composer) => composer(view)); - } - - /// Normalize the given view path - String _normalizePath(String path) { - return path.replaceAll('.', '/'); - } -} diff --git a/packages/view/lib/src/finder.dart b/packages/view/lib/src/finder.dart deleted file mode 100644 index e56e1f5..0000000 --- a/packages/view/lib/src/finder.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'dart:io'; -import 'package:path/path.dart' as path; -import 'exceptions.dart'; - -/// The view finder implementation -class ViewFinder { - /// The paths to search for views - final List paths; - - /// The file extensions to search for - final List extensions; - - /// Cache of found views - final Map _cache = {}; - - ViewFinder(this.paths, [this.extensions = const ['.blade.php', '.php', '.html']]); - - /// Find the given view in the filesystem - String find(String name) { - if (_cache.containsKey(name)) { - return _cache[name]!; - } - - String result = _findInPaths(name); - _cache[name] = result; - return result; - } - - /// Find the given view in the filesystem paths - String _findInPaths(String name) { - for (String location in paths) { - for (String extension in extensions) { - String viewPath = path.join(location, '$name$extension'); - if (File(viewPath).existsSync()) { - return viewPath; - } - } - } - - throw ViewNotFoundException('View [$name] not found.'); - } - - /// Add a location to the finder - void addLocation(String location) { - paths.add(location); - } - - /// Flush the cache of located views - void flush() { - _cache.clear(); - } -} diff --git a/packages/view/lib/src/view.dart b/packages/view/lib/src/view.dart deleted file mode 100644 index ee754aa..0000000 --- a/packages/view/lib/src/view.dart +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index 107c1d7..0000000 --- a/packages/view/lib/view.dart +++ /dev/null @@ -1,10 +0,0 @@ -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';