From a672d0df55ec95a98336fa4ed98f1cca9ceda34d Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 18 Nov 2017 13:39:10 -0500 Subject: [PATCH] 1.1.0 --- README.md | 19 ++++++++++--------- analysis_options.yaml | 2 ++ lib/angel_mustache.dart | 20 ++++++++++---------- lib/src/cache.dart | 15 +++++++-------- lib/src/mustache_context.dart | 8 +++----- pubspec.yaml | 5 +++-- test/all_test.dart | 14 ++++++-------- 7 files changed, 41 insertions(+), 42 deletions(-) create mode 100644 analysis_options.yaml diff --git a/README.md b/README.md index a8ac83b5..afe4027b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # mustache [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/angel_dart/discussion) -[![version 1.0.3](https://img.shields.io/badge/pub-1.0.3-brightgreen.svg)](https://pub.dartlang.org/packages/angel_mustache) +[![version](https://img.shields.io/pub/v/angel_mustache.svg)](https://pub.dartlang.org/packages/angel_mustache) [![build status](https://travis-ci.org/angel-dart/mustache.svg?branch=master)](https://travis-ci.org/angel-dart/mustache) Mustache (Handlebars) view generator for the [Angel](https://github.com/angel-dart/angel) @@ -13,19 +13,20 @@ In `pubspec.yaml`: ```yaml dependencies: - angel_mustache: ^1.0.0 + angel_mustache: ^1.1.0 ``` -If your project imports [`package:angel_common`](https://github.com/angel-dart/common), -then this is already installed. - # Usage ```dart -// Run the plug-in -await app.configure(mustache(new Directory('views'))); +const FileSystem fs = const LocalFileSystem(); -// Render `hello.mustache` -await res.render('hello', {'name': 'world'}); +configureServer(Angel app) async { + // Run the plug-in + await app.configure(mustache(fs.directory('views'))); + + // Render `hello.mustache` + await res.render('hello', {'name': 'world'}); +} ``` # Options diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..518eb901 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true \ No newline at end of file diff --git a/lib/angel_mustache.dart b/lib/angel_mustache.dart index 18b5c486..ce758fa2 100644 --- a/lib/angel_mustache.dart +++ b/lib/angel_mustache.dart @@ -1,32 +1,32 @@ library angel_mustache; -import 'dart:io'; import 'package:angel_framework/angel_framework.dart'; +import 'package:file/file.dart'; import 'package:mustache4dart/mustache4dart.dart' show render; -import 'package:angel_mustache/src/cache.dart'; -import 'package:angel_mustache/src/mustache_context.dart'; -import 'package:path/path.dart' as path; +import 'package:path/path.dart' as p; +import 'src/cache.dart'; +import 'src/mustache_context.dart'; mustache(Directory viewsDirectory, {String fileExtension: '.mustache', String partialsPath: './partials'}) { - Directory partialsDirectory = - new Directory(path.join(path.fromUri(viewsDirectory.uri), partialsPath)); + Directory partialsDirectory = viewsDirectory.fileSystem + .directory(p.join(p.fromUri(viewsDirectory.uri), partialsPath)); MustacheContext context = new MustacheContext(viewsDirectory, partialsDirectory, fileExtension); - MustacheCacheController cache = new MustacheCacheController(context); + MustacheViewCache cache = new MustacheViewCache(context); return (Angel app) async { app.viewGenerator = (String name, [Map data]) async { var partialsProvider; partialsProvider = (String name) { - String template = cache.get_partial(name, app); + String template = cache.getPartialSync(name, app); return render(template, data ?? {}, partial: partialsProvider); }; - String viewTemplate = await cache.get_view(name, app); - return render(viewTemplate, data ?? {}, partial: partialsProvider); + String viewTemplate = await cache.getView(name, app); + return await render(viewTemplate, data ?? {}, partial: partialsProvider); }; }; } diff --git a/lib/src/cache.dart b/lib/src/cache.dart index debafc81..6c8f92bd 100644 --- a/lib/src/cache.dart +++ b/lib/src/cache.dart @@ -1,12 +1,11 @@ -import 'dart:io'; +import 'dart:async'; import 'dart:collection'; -import 'package:path/path.dart' as path; +import 'package:file/file.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_mustache/src/mustache_context.dart'; -class MustacheCacheController { - +class MustacheViewCache { /** * The context for which views and partials are * served from. @@ -16,9 +15,9 @@ class MustacheCacheController { HashMap viewCache = new HashMap(); HashMap partialCache = new HashMap(); - MustacheCacheController([this.context]); + MustacheViewCache([this.context]); - get_view(String viewName, Angel app) async { + Future getView(String viewName, Angel app) async { if (app.isProduction) { if (viewCache.containsKey(viewName)) { return viewCache[viewName]; @@ -27,7 +26,7 @@ class MustacheCacheController { File viewFile = context.resolveView(viewName); - if (await viewFile.exists()) { + if (viewFile.existsSync()) { String viewTemplate = await viewFile.readAsString(); if (app.isProduction) { this.viewCache[viewName] = viewTemplate; @@ -38,7 +37,7 @@ class MustacheCacheController { 'View "$viewName" was not found.', viewFile.path); } - get_partial(String partialName, Angel app) { + String getPartialSync(String partialName, Angel app) { if (app.isProduction) { if (partialCache.containsKey(partialName)) { return partialCache[partialName]; diff --git a/lib/src/mustache_context.dart b/lib/src/mustache_context.dart index d872e858..9461f82e 100644 --- a/lib/src/mustache_context.dart +++ b/lib/src/mustache_context.dart @@ -1,4 +1,4 @@ -import 'dart:io'; +import 'package:file/file.dart'; import 'package:path/path.dart' as path; class MustacheContext { @@ -11,12 +11,10 @@ class MustacheContext { MustacheContext([this.viewDirectory, this.partialDirectory, this.extension]); File resolveView(String viewName) { - return new File.fromUri( - viewDirectory.uri.resolve('${viewName}${extension}')); + return viewDirectory.childFile('${viewName}${extension}'); } File resolvePartial(String partialName) { - return new File.fromUri( - partialDirectory.uri.resolve('${partialName}${extension}')); + return partialDirectory.childFile('${partialName}${extension}'); } } diff --git a/pubspec.yaml b/pubspec.yaml index e2f3c084..9ea234a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,9 +2,10 @@ name: angel_mustache description: Mustache view generator for Angel. author: thosakwe homepage: https://github.com/angel-dart/angel_mustache -version: 1.0.3 +version: 1.1.0 dependencies: - angel_framework: ">=1.0.0-dev < 2.0.0" + angel_framework: "^1.1.0-alpha" + file: ^2.0.0 mustache4dart: ">= 1.0.0 < 2.0.0" dev_dependencies: http: ">= 0.11.3 < 0.12.0" diff --git a/test/all_test.dart b/test/all_test.dart index 532c70cd..cc5c859f 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -1,12 +1,12 @@ import 'dart:async'; -import 'dart:io'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_mustache/angel_mustache.dart'; +import 'package:file/local.dart'; import 'package:test/test.dart'; main() async { Angel angel = new Angel(); - await angel.configure(mustache(new Directory('./test'))); + await angel.configure(mustache(const LocalFileSystem().directory('./test'))); test('can render templates', () async { var hello = await angel.viewGenerator('hello', {'name': 'world'}); @@ -17,12 +17,10 @@ main() async { }); test('throws if view is not found', () { - expect( - new Future(() async { - var fails = await angel.viewGenerator( - 'fail', {'this_should': 'fail'}); - print(fails); - }), throws); + expect(new Future(() async { + var fails = await angel.viewGenerator('fail', {'this_should': 'fail'}); + print(fails); + }), throws); }); test("partials", () async {