Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for 'reflectable' #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ------------------------------------------------------------------------------
# Config for Analyzer
# More: https://pub.dartlang.org/packages/analyzer
#
# Analyzer options:
# https://www.dartlang.org/guides/language/analysis-options
#

analyzer:
strong-mode: true

# Exclude wegen https://github.com/dart-lang/sdk/issues/26420
# und https://github.com/dart-lang/test/issues/436
# exclude:
# - test/**
28 changes: 28 additions & 0 deletions example/basic.reflectable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
8 changes: 8 additions & 0 deletions example/browser/reflection/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.buildlog
.DS_Store
.idea
.packages
.pub/
build/
packages
pubspec.lock
5 changes: 5 additions & 0 deletions example/browser/reflection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.0.1

- Initial version, created by Stagehand
24 changes: 24 additions & 0 deletions example/browser/reflection/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2016, <your name>.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 5 additions & 0 deletions example/browser/reflection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Uber-simple web app

An absolute bare-bones web app.

Generated by Stagehand. See LICENSE.
22 changes: 22 additions & 0 deletions example/browser/reflection/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'mustache_reflection_test'

version: 0.0.1
description: An absolute bare-bones web app.
#author: Your Name <[email protected]>
#homepage: https://www.example.com

environment:
sdk: '>=1.0.0 <2.0.0'

dependencies:

mustache:
path: ../../../

dev_dependencies:

build_runner: ^0.8.0
build_test: ^0.10.0
build_web_compilers: ^0.4.0


25 changes: 25 additions & 0 deletions example/browser/reflection/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>

<!--
Copyright (c) 2016, <your name>. All rights reserved. Use of this source code
is governed by a BSD-style license that can be found in the LICENSE file.
-->

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/google/stagehand">
<title>reflection</title>
<link rel="stylesheet" href="styles.css">
<script async src="main.dart" type="application/dart"></script>
<script defer src="main.dart.js"></script>
</head>

<body>

<div id="output"></div>

</body>
</html>
43 changes: 43 additions & 0 deletions example/browser/reflection/web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2016, <your name>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:html' as dom;
import 'package:mustache/mustache.dart';

import 'main.reflectable.dart';

@mustache
class Version {
final int major;
final int minor;

Version(this.major, this.minor);
}

@mustache
class DartLang {
final String name;
final Version version;
final String message;

DartLang(this.name, this.version, this.message);
}

void main() {
initializeReflectable();

final Template template = new Template(
"""
<div>
Language: {{name}}<br>
Version: {{version.major}}.{{version.minor}}<br>
Comment: {{message}}
</div>
""".trim(), lenient: false,htmlEscapeValues: false);
final DartLang language = new DartLang("Dart",new Version(1,13),"Your Dart app is running.");

final String content = template.renderString(language);
final dom.Element child = new dom.Element.html(content);

dom.querySelector('#output').append(child);
}
29 changes: 29 additions & 0 deletions example/browser/reflection/web/main.reflectable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'main.dart' as prefix1;
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[new r.NonGenericClassMirrorImpl(r"Version", r".Version", 7, 0, const prefix0.MustacheMirrorsUsedAnnotation(), const <int>[0, 1, 7], const <int>[8, 9, 10, 11, 12, 5, 6], const <int>[], -1, {}, {}, {r"": (b) => (major, minor) => b ? new prefix1.Version(major, minor) : null}, -1, -1, const <int>[-1], null, null), new r.NonGenericClassMirrorImpl(r"DartLang", r".DartLang", 7, 1, const prefix0.MustacheMirrorsUsedAnnotation(), const <int>[2, 3, 4, 16], const <int>[8, 9, 10, 11, 12, 13, 14, 15], const <int>[], -1, {}, {}, {r"": (b) => (name, version, message) => b ? new prefix1.DartLang(name, version, message) : null}, -1, -1, const <int>[-1], null, null)], <m.DeclarationMirror>[new r.VariableMirrorImpl(r"major", 33797, 0, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null), new r.VariableMirrorImpl(r"minor", 33797, 0, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null), new r.VariableMirrorImpl(r"name", 33797, 1, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null), new r.VariableMirrorImpl(r"version", 33797, 1, const prefix0.MustacheMirrorsUsedAnnotation(), 0, 0, 0, null), new r.VariableMirrorImpl(r"message", 33797, 1, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 0, 2, 2, 5), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 1, 2, 2, 6), new r.MethodMirrorImpl(r"", 0, 0, -1, 0, 0, const <int>[0, 1], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"==", 131074, null, -1, 4, 4, const <int>[2], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"toString", 131074, null, -1, 3, 3, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"noSuchMethod", 65538, null, null, null, null, const <int>[3], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"hashCode", 131075, null, -1, 2, 2, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"runtimeType", 131075, null, -1, 5, 5, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 2, 3, 3, 13), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 3, 0, 0, 14), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 4, 3, 3, 15), new r.MethodMirrorImpl(r"", 0, 1, -1, 1, 1, const <int>[4, 5, 6], const prefix0.MustacheMirrorsUsedAnnotation(), null)], <m.ParameterMirror>[new r.ParameterMirrorImpl(r"major", 32774, 7, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null, null, null), new r.ParameterMirrorImpl(r"minor", 32774, 7, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null, null, null), new r.ParameterMirrorImpl(r"other", 16390, 8, const prefix0.MustacheMirrorsUsedAnnotation(), null, null, null, null, null, null), new r.ParameterMirrorImpl(r"invocation", 32774, 10, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 6, 6, null, null, null), new r.ParameterMirrorImpl(r"name", 32774, 16, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null, null, null), new r.ParameterMirrorImpl(r"version", 32774, 16, const prefix0.MustacheMirrorsUsedAnnotation(), 0, 0, 0, null, null, null), new r.ParameterMirrorImpl(r"message", 32774, 16, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null, null, null)], <Type>[prefix1.Version, prefix1.DartLang, int, String, bool, Type, Invocation], 2, {r"==": (dynamic instance) => (x) => instance == x, r"toString": (dynamic instance) => instance.toString, r"noSuchMethod": (dynamic instance) => instance.noSuchMethod, r"hashCode": (dynamic instance) => instance.hashCode, r"runtimeType": (dynamic instance) => instance.runtimeType, r"major": (dynamic instance) => instance.major, r"minor": (dynamic instance) => instance.minor, r"name": (dynamic instance) => instance.name, r"version": (dynamic instance) => instance.version, r"message": (dynamic instance) => instance.message}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
2 changes: 1 addition & 1 deletion example/lambdas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:mustache/mustache.dart';

main() {
var t = new Template('{{ foo }}');
var lambda = (_) => 'bar';
var lambda = (LambdaContext ctx) => 'bar';
var output = t.renderString({'foo': lambda}); // bar
print(output);

Expand Down
28 changes: 28 additions & 0 deletions example/lambdas.reflectable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
28 changes: 28 additions & 0 deletions example/nested_paths.reflectable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
28 changes: 28 additions & 0 deletions example/partials.reflectable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
18 changes: 11 additions & 7 deletions lib/mustache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

library mustache;

import 'package:reflectable/reflectable.dart';
import 'src/template.dart' as t;

class MustacheMirrorsUsedAnnotation extends Reflectable {
const MustacheMirrorsUsedAnnotation() : super(
invokingCapability,
reflectedTypeCapability
);
}

const MustacheMirrorsUsedAnnotation mustache = const MustacheMirrorsUsedAnnotation();


/// Use new Template(source) instead.
@deprecated
Template parse(String source, {bool lenient: false}) =>
Expand Down Expand Up @@ -69,13 +80,6 @@ abstract class LambdaContext {
Object lookup(String variableName);
}

const MustacheMirrorsUsedAnnotation mustache =
const MustacheMirrorsUsedAnnotation();

class MustacheMirrorsUsedAnnotation {
const MustacheMirrorsUsedAnnotation();
}

/// [TemplateException] is used to obtain the line and column numbers
/// of the token which caused parse or render to fail.
abstract class TemplateException implements Exception {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lambda_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LambdaContext implements m.LambdaContext {

if (nodes.isEmpty) return '';

if (nodes.length == 1 && nodes.first is TextNode) return nodes.first.text;
if (nodes.length == 1 && nodes.first is TextNode) return (nodes.first as TextNode).text;

return _renderer.source.substring(node.contentStart, node.contentEnd);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ class Parser {
children.add(new TextNode(token.value, token.start, token.end));
} else {
var last = children.removeLast();
var node = new TextNode(last.text + token.value, last.start, token.end);
children.add(node);
if(last is! TextNode) {
children.add(new TextNode(token.value, token.start, token.end));
} else {
children.add(new TextNode((last as TextNode).text + token.value, last.start, token.end));
}
}
}

Expand Down
Loading