Skip to content

Commit

Permalink
Merge pull request #48 from PyreStudios/break-mirrors
Browse files Browse the repository at this point in the history
Break dependency on mirrors.
  • Loading branch information
bradcypert committed Oct 20, 2023
2 parents 3e1ddb6 + 8f7ac3c commit 6c5df15
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 672 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -9,3 +9,7 @@ build/

# Directory created by dartdoc
doc/api/


asdf*.*
.vscode/
1 change: 1 addition & 0 deletions .tool-versions
@@ -0,0 +1 @@
dart 3.1.4
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -12,7 +12,7 @@ By participating, you are expected to uphold this code. Please report unacceptab
Steward ships as two major modules, the binary module (bin) and the library module (lib).
The binary gets built as an executable and is used to provide a CLI for working with (and generating) Steward projects.

The library module contains all of the code that is used during runtime for applications built ontop of Steward (controllers, router, etc).
The library module contains all of the code that is used during runtime for applications built ontop of Steward (router, container, etc).

# How can I contribute?

Expand Down
23 changes: 2 additions & 21 deletions README.md
Expand Up @@ -25,8 +25,7 @@ dart pub global activate steward
The best examples for how to use Steward are captured in the test folder. Eventually, we'll refactor this out into tests and examples separately, but for now, they live together :)

Using the Steward framework gives you the following (but not limited to) benefits:
- A modular system with light Dependency Injection, Routing, Controllers, and more.
- Automatic dependency injection into controllers when mounting into routers.
- A modular system with light Dependency Injection, Routing, and more.
- Easy HTTP request/response management.
- Config parsing into the DI container at application boot.
- Templating via the Mustache template specification.
Expand All @@ -36,21 +35,6 @@ Here's an example of how you can use Steward!
```dart
import 'package:steward/steward.dart';
// You can pull me out to a separate file, too ya know ;)
class SampleController extends Controller {
@Injectable('UserService')
late UserService userService;
@Get('/version')
version(_) => 'v1.0';
@Get('/show')
Response show(Request request) => view('main_template');
@Get('/users')
Response users => UserService.getUsers();
}
Future main() async {
var router = Router();
var container = CacheContainer();
Expand All @@ -59,10 +43,7 @@ Future main() async {
container.bind('UserService', (_) => UserService());
// Replace the default DI container implementation
router.setContainer(container)
// Mount the controller, parsing the annotations to build paths and injecting injectables
router.mount(SimpleController);
router.setContainer(container);
// Bare route handler example
router.get('/hello', (_) {
Expand Down
31 changes: 0 additions & 31 deletions bin/new_controller.dart

This file was deleted.

11 changes: 0 additions & 11 deletions example/main.dart
@@ -1,15 +1,6 @@
import 'package:steward/app/app.dart';
import 'package:steward/controllers/controller.dart';
import 'package:steward/controllers/route_utils.dart';
import 'package:steward/router/router.dart';

class SimpleController extends Controller {
@Get('/show')
Response show(Request request) {
return Response.Ok('Hello from SimpleController@show');
}
}

Future main() async {
var router = Router();

Expand All @@ -24,8 +15,6 @@ Future main() async {
return Response.Ok(request.container.make('@config'));
});

router.mount(SimpleController);

router.get('/:name', (Request request) async {
return Response.Ok(request.pathParams['name']);
});
Expand Down
20 changes: 20 additions & 0 deletions lib/container/container.dart
@@ -1,3 +1,10 @@
/// ViewNotFoundError is thrown when we try to load a view that doesn't exist.
class ViewNotFoundError extends Error {
String fileName;

ViewNotFoundError(this.fileName);
}

abstract class Container {
void bind<T>(String key, T Function(Container) fn);
T? make<T>(String key);
Expand Down Expand Up @@ -29,6 +36,19 @@ class CacheContainer implements Container {
return null;
}

/// Load a file from the container
/// TODO: This doesnt feel like the right path forward for this.
String? view(String filename) {
String templateString;
try {
templateString = make('@views.$filename');
} catch (e) {
throw ViewNotFoundError(filename);
}

return templateString;
}

@override
Container clone() {
return CacheContainer()..bindings.addAll(bindings);
Expand Down
53 changes: 0 additions & 53 deletions lib/controllers/controller.dart

This file was deleted.

28 changes: 0 additions & 28 deletions lib/controllers/controller_mirror_factory.dart

This file was deleted.

154 changes: 0 additions & 154 deletions lib/controllers/route_utils.dart

This file was deleted.

6 changes: 0 additions & 6 deletions lib/controllers/view_not_found_error.dart

This file was deleted.

0 comments on commit 6c5df15

Please sign in to comment.