Banish the underscores
diff --git a/lib/mustache.dart b/lib/mustache.dart
index 9d5683b..9dd87b7 100644
--- a/lib/mustache.dart
+++ b/lib/mustache.dart
@@ -21,7 +21,7 @@
{bool lenient,
bool htmlEscapeValues,
String name,
- PartialResolver partialResolver}) = impl.TemplateImpl.fromSource;
+ PartialResolver partialResolver}) = impl.Template.fromSource;
String get name;
String get source;
diff --git a/lib/src/lambda_context.dart b/lib/src/lambda_context.dart
index c5b9a73..135a23e 100644
--- a/lib/src/lambda_context.dart
+++ b/lib/src/lambda_context.dart
@@ -1,14 +1,14 @@
part of mustache.impl;
/// Passed as an argument to a mustache lambda function.
-class _LambdaContext implements LambdaContext {
+class LambdaContext implements m.LambdaContext {
- final _Node _node;
- final _RenderContext _context;
+ final Node _node;
+ final RenderContext _context;
final bool _isSection;
bool _closed = false;
- _LambdaContext(this._node, this._context, {bool isSection: true})
+ LambdaContext(this._node, this._context, {bool isSection: true})
: _isSection = isSection;
void close() {
@@ -36,10 +36,10 @@
}
void _renderSubtree(StringSink sink, Object value) {
- var ctx = new _RenderContext.subtree(_context, sink);
+ var ctx = new RenderContext.subtree(_context, sink);
_SectionNode section = _node;
if (value != null) ctx.push(value);
- _renderWithContext(ctx, section.children);
+ renderWithContext(ctx, section.children);
}
void render({Object value}) {
@@ -85,12 +85,12 @@
delimiters = node.delimiters;
}
- var nodes = _parse(source,
+ var nodes = parse(source,
_context.lenient,
_context.templateName,
delimiters);
- var ctx = new _RenderContext.lambda(
+ var ctx = new RenderContext.lambda(
_context,
source,
_context.indent,
@@ -98,7 +98,7 @@
delimiters);
if (value != null) ctx.push(value);
- _renderWithContext(ctx, nodes);
+ renderWithContext(ctx, nodes);
return sink.toString();
}
diff --git a/lib/src/mustache_impl.dart b/lib/src/mustache_impl.dart
index 2ecd10a..1531e9d 100644
--- a/lib/src/mustache_impl.dart
+++ b/lib/src/mustache_impl.dart
@@ -1,9 +1,9 @@
library mustache.impl;
-@MirrorsUsed(metaTargets: const [mustache])
+@MirrorsUsed(metaTargets: const [m.mustache])
import 'dart:mirrors';
-import 'package:mustache/mustache.dart';
+import 'package:mustache/mustache.dart' as m;
part 'lambda_context.dart';
part 'node.dart';
diff --git a/lib/src/node.dart b/lib/src/node.dart
index 2b1356a..62b8b8b 100644
--- a/lib/src/node.dart
+++ b/lib/src/node.dart
@@ -1,6 +1,6 @@
part of mustache.impl;
-void _renderWithContext(_RenderContext ctx, List<_Node> nodes) {
+void renderWithContext(RenderContext ctx, List<Node> nodes) {
if (ctx.indent == null || ctx.indent == '') {
nodes.forEach((n) => n.render(ctx));
@@ -23,11 +23,11 @@
}
}
-abstract class _Node {
+abstract class Node {
- _Node(this.start, this.end);
+ Node(this.start, this.end);
- void render(_RenderContext renderer);
+ void render(RenderContext renderer);
// The offset of the start of the token in the file. Unless this is a section
// or inverse section, then this stores the start of the content of the
@@ -41,13 +41,13 @@
}
-class _TextNode extends _Node {
+class _TextNode extends Node {
_TextNode(this.text, int start, int end) : super(start, end);
final String text;
- void render(_RenderContext ctx, {lastNode: false}) {
+ void render(RenderContext ctx, {lastNode: false}) {
if (text == '') return;
if (ctx.indent == null || ctx.indent == '') {
ctx.write(text);
@@ -62,7 +62,7 @@
}
}
-class _VariableNode extends _Node {
+class _VariableNode extends Node {
_VariableNode(this.name, int start, int end, {this.escape: false})
: super(start, end);
@@ -70,12 +70,12 @@
final String name;
final bool escape;
- void render(_RenderContext ctx) {
+ void render(RenderContext ctx) {
var value = ctx.resolveValue(name);
if (value is Function) {
- var context = new _LambdaContext(this, ctx, isSection: false);
+ var context = new LambdaContext(this, ctx, isSection: false);
value = value(context);
context.close();
}
@@ -125,7 +125,7 @@
}
-class _SectionNode extends _Node {
+class _SectionNode extends Node {
_SectionNode(this.name, int start, int end, this.delimiters,
{this.inverse: false})
@@ -136,14 +136,14 @@
final bool inverse;
int contentStart;
int contentEnd;
- final List<_Node> children = <_Node>[];
+ final List<Node> children = <Node>[];
//TODO can probably combine Inv and Normal to shorten.
- void render(_RenderContext ctx) => inverse
+ void render(RenderContext ctx) => inverse
? renderInv(ctx)
: renderNormal(ctx);
- void renderNormal(_RenderContext renderer) {
+ void renderNormal(RenderContext renderer) {
var value = renderer.resolveValue(name);
if (value == null) {
@@ -166,7 +166,7 @@
throw renderer.error('Value was missing for section tag: ${name}.', this);
} else if (value is Function) {
- var context = new _LambdaContext(this, renderer, isSection: true);
+ var context = new LambdaContext(this, renderer, isSection: true);
var output = value(context);
context.close();
if (output != null) renderer.write(output);
@@ -178,7 +178,7 @@
}
}
- void renderInv(_RenderContext ctx) {
+ void renderInv(RenderContext ctx) {
var value = ctx.resolveValue(name);
if (value == null) {
@@ -209,14 +209,14 @@
}
}
- void _renderWithValue(_RenderContext ctx, value) {
+ void _renderWithValue(RenderContext ctx, value) {
ctx.push(value);
children.forEach((n) => n.render(ctx));
ctx.pop();
}
}
-class _PartialNode extends _Node {
+class _PartialNode extends Node {
_PartialNode(this.name, int start, int end, this.indent)
: super(start, end);
@@ -227,14 +227,14 @@
// it's content can be correctly indented.
final String indent;
- void render(_RenderContext ctx) {
+ void render(RenderContext ctx) {
var partialName = name;
- TemplateImpl template = ctx.partialResolver == null
+ Template template = ctx.partialResolver == null
? null
: ctx.partialResolver(partialName);
if (template != null) {
- var partialCtx = new _RenderContext.partial(ctx, template, this.indent);
- _renderWithContext(partialCtx, template._nodes);
+ var partialCtx = new RenderContext.partial(ctx, template, this.indent);
+ renderWithContext(partialCtx, template._nodes);
} else if (ctx.lenient) {
// do nothing
} else {
diff --git a/lib/src/parse.dart b/lib/src/parse.dart
index d90a866..9f73111 100644
--- a/lib/src/parse.dart
+++ b/lib/src/parse.dart
@@ -1,6 +1,6 @@
part of mustache.impl;
-List<_Node> _parse(String source,
+List<Node> parse(String source,
bool lenient,
String templateName,
String delimiters) {
@@ -8,12 +8,12 @@
if (source == null) throw new ArgumentError.notNull('Template source');
var tokens =
- new _Scanner(source, templateName, delimiters, lenient: lenient).scan();
+ new Scanner(source, templateName, delimiters, lenient: lenient).scan();
tokens = _removeStandaloneWhitespace(tokens);
tokens = _mergeAdjacentText(tokens);
- var stack = new List<_Node>()..add(new _SectionNode('root', 0, 0, delimiters));
+ var stack = new List<Node>()..add(new _SectionNode('root', 0, 0, delimiters));
var delim;
@@ -90,10 +90,10 @@
// LINE_END => TEXT
// TODO could rewrite this to use a generator, rather than creating an inter-
// mediate list.
-List<_Token> _removeStandaloneWhitespace(List<_Token> tokens) {
+List<Token> _removeStandaloneWhitespace(List<Token> tokens) {
int i = 0;
- _Token read() { var ret = i < tokens.length ? tokens[i++] : null; return ret; }
- _Token peek([int n = 0]) => i + n < tokens.length ? tokens[i + n] : null;
+ Token read() { var ret = i < tokens.length ? tokens[i++] : null; return ret; }
+ Token peek([int n = 0]) => i + n < tokens.length ? tokens[i + n] : null;
bool isTag(token) => token != null
&& const [_OPEN_SECTION, _OPEN_INV_SECTION, _CLOSE_SECTION, _COMMENT,
@@ -102,7 +102,7 @@
bool isWhitespace(token) => token != null && token.type == _WHITESPACE;
bool isLineEnd(token) => token != null && token.type == _LINE_END;
- var result = new List<_Token>();
+ var result = new List<Token>();
add(token) => result.add(token);
standaloneLineCheck() {
@@ -147,11 +147,11 @@
while ((t = read()) != null) {
if (t.type == _LINE_END) {
// Convert line end to text token
- add(new _Token(_TEXT, t.value, t.start, t.end));
+ add(new Token(_TEXT, t.value, t.start, t.end));
standaloneLineCheck();
} else if (t.type == _WHITESPACE) {
// Convert whitespace to text token
- add(new _Token(_TEXT, t.value, t.start, t.end));
+ add(new Token(_TEXT, t.value, t.start, t.end));
} else {
// Preserve token
add(t);
@@ -164,10 +164,10 @@
// Merging adjacent text nodes will improve the render speed, but slow down
// parsing. It will be beneficial where templates are parsed once and rendered
// a number of times.
-List<_Token> _mergeAdjacentText(List<_Token> tokens) {
- if (tokens.isEmpty) return <_Token>[];
+List<Token> _mergeAdjacentText(List<Token> tokens) {
+ if (tokens.isEmpty) return <Token>[];
- var result = new List<_Token>();
+ var result = new List<Token>();
int i = 0;
while(i < tokens.length) {
var t = tokens[i];
@@ -182,7 +182,7 @@
buffer.write(tokens[i].value);
i++;
}
- result.add(new _Token(_TEXT, buffer.toString(), t.start, t.end));
+ result.add(new Token(_TEXT, buffer.toString(), t.start, t.end));
}
}
return result;
diff --git a/lib/src/render_context.dart b/lib/src/render_context.dart
index ffc4d73..d506209 100644
--- a/lib/src/render_context.dart
+++ b/lib/src/render_context.dart
@@ -5,9 +5,9 @@
const Object _noSuchProperty = const Object();
-class _RenderContext {
+class RenderContext {
- _RenderContext(this._sink,
+ RenderContext(this._sink,
List stack,
this.lenient,
this.htmlEscapeValues,
@@ -17,7 +17,7 @@
this.source)
: _stack = new List.from(stack);
- _RenderContext.partial(_RenderContext ctx, TemplateImpl partial, String indent)
+ RenderContext.partial(RenderContext ctx, Template partial, String indent)
: this(ctx._sink,
ctx._stack,
ctx.lenient,
@@ -27,7 +27,7 @@
ctx.indent + indent,
partial.source);
- _RenderContext.subtree(_RenderContext ctx, StringSink sink)
+ RenderContext.subtree(RenderContext ctx, StringSink sink)
: this(sink,
ctx._stack,
ctx.lenient,
@@ -37,8 +37,8 @@
ctx.indent,
ctx.source);
- _RenderContext.lambda(
- _RenderContext ctx,
+ RenderContext.lambda(
+ RenderContext ctx,
String source,
String indent,
StringSink sink,
@@ -56,7 +56,7 @@
final List _stack;
final bool lenient;
final bool htmlEscapeValues;
- final PartialResolver partialResolver;
+ final m.PartialResolver partialResolver;
final String templateName;
final String indent;
final String source;
@@ -121,6 +121,6 @@
return invocation.reflectee;
}
- TemplateException error(String message, _Node node)
+ m.TemplateException error(String message, Node node)
=> new _TemplateException(message, templateName, source, node.start);
}
diff --git a/lib/src/scanner.dart b/lib/src/scanner.dart
index 6f2b81b..5b3908c 100644
--- a/lib/src/scanner.dart
+++ b/lib/src/scanner.dart
@@ -1,8 +1,8 @@
part of mustache.impl;
-class _Scanner {
+class Scanner {
- _Scanner(String source, this._templateName, String delimiters, {bool lenient: true})
+ Scanner(String source, this._templateName, String delimiters, {bool lenient: true})
: _source = source,
_lenient = lenient,
_itr = source.runes.iterator {
@@ -29,7 +29,7 @@
int _offset = 0;
int _c = 0;
- final List<_Token> _tokens = new List<_Token>();
+ final List<Token> _tokens = new List<Token>();
// These can be changed by the change delimiter tag.
int _openDelimiter;
@@ -37,7 +37,7 @@
int _closeDelimiterInner;
int _closeDelimiter;
- List<_Token> scan() {
+ List<Token> scan() {
while(true) {
int c = _peek();
if (c == _EOF) break;
@@ -122,24 +122,24 @@
} else if (c == _NEWLINE) {
_read();
var value = new String.fromCharCode(c);
- _tokens.add(new _Token(_LINE_END, value, start, _offset));
+ _tokens.add(new Token(_LINE_END, value, start, _offset));
} else if (c == _RETURN) {
_read();
if (_peek() == _NEWLINE) {
_read();
- _tokens.add(new _Token(_LINE_END, '\r\n', start, _offset));
+ _tokens.add(new Token(_LINE_END, '\r\n', start, _offset));
} else {
- _tokens.add(new _Token(_TEXT, '\r', start, _offset));
+ _tokens.add(new Token(_TEXT, '\r', start, _offset));
}
} else if (c == _SPACE || c == _TAB) {
var value = _readWhile((c) => c == _SPACE || c == _TAB);
- _tokens.add(new _Token(_WHITESPACE, value, start, _offset));
+ _tokens.add(new Token(_WHITESPACE, value, start, _offset));
} else {
var value = _readWhile((c) => c != _openDelimiter && c != _NEWLINE);
- _tokens.add(new _Token(_TEXT, value, start, _offset));
+ _tokens.add(new Token(_TEXT, value, start, _offset));
}
}
}
@@ -153,7 +153,7 @@
// If just a single delimeter character then this is a text token.
if (_openDelimiterInner != null && _peek() != _openDelimiterInner) {
var value = new String.fromCharCode(_openDelimiter);
- _tokens.add(new _Token(_TEXT, value, start, _offset));
+ _tokens.add(new Token(_TEXT, value, start, _offset));
return;
}
@@ -199,7 +199,7 @@
var type = sigils[sigil];
var indent = type == _PARTIAL ? _getPrecedingWhitespace() : '';
- _tokens.add(new _Token(type, identifier, start, _offset, indent: indent));
+ _tokens.add(new Token(type, identifier, start, _offset, indent: indent));
}
_errorEofInTag() => throw _error('Tag not closed before the end of the template.');
@@ -256,7 +256,7 @@
_expect(_CLOSE_MUSTACHE);
if (_closeDelimiterInner != null) _expect(_closeDelimiterInner);
_expect(_closeDelimiter);
- _tokens.add(new _Token(_UNESC_VARIABLE, value, start, _offset));
+ _tokens.add(new Token(_UNESC_VARIABLE, value, start, _offset));
}
void _scanCommentTag(int start) {
@@ -265,7 +265,7 @@
: _readWhile((c) => c != _closeDelimiter, _errorEofInTag).trim();
if (_closeDelimiterInner != null) _expect(_closeDelimiterInner);
_expect(_closeDelimiter);
- _tokens.add(new _Token(_COMMENT, value, start, _offset));
+ _tokens.add(new Token(_COMMENT, value, start, _offset));
}
//TODO consider changing the parsing here to use a regexp. It will probably
@@ -319,10 +319,10 @@
_closeDelimiterInner,
_closeDelimiter);
- _tokens.add(new _Token(_CHANGE_DELIMITER, value, start, _offset));
+ _tokens.add(new Token(_CHANGE_DELIMITER, value, start, _offset));
}
- TemplateException _error(String message) {
+ m.TemplateException _error(String message) {
return new _TemplateException(message, _templateName, _source, _offset);
}
diff --git a/lib/src/template.dart b/lib/src/template.dart
index 440e284..30b1455 100644
--- a/lib/src/template.dart
+++ b/lib/src/template.dart
@@ -1,25 +1,25 @@
part of mustache.impl;
-class TemplateImpl implements Template {
+class Template implements m.Template {
- TemplateImpl.fromSource(String source,
+ Template.fromSource(String source,
{bool lenient: false,
bool htmlEscapeValues : true,
String name,
- PartialResolver partialResolver})
+ m.PartialResolver partialResolver})
: source = source,
- _nodes = _parse(source, lenient, name, '{{ }}'),
+ _nodes = parse(source, lenient, name, '{{ }}'),
_lenient = lenient,
_htmlEscapeValues = htmlEscapeValues,
_name = name,
_partialResolver = partialResolver;
final String source;
- final List<_Node> _nodes;
+ final List<Node> _nodes;
final bool _lenient;
final bool _htmlEscapeValues;
final String _name;
- final PartialResolver _partialResolver;
+ final m.PartialResolver _partialResolver;
String get name => _name;
@@ -30,13 +30,13 @@
}
void render(values, StringSink sink) {
- var ctx = new _RenderContext(sink, [values], _lenient, _htmlEscapeValues,
+ var ctx = new RenderContext(sink, [values], _lenient, _htmlEscapeValues,
_partialResolver, _name, '', source);
- _renderWithContext(ctx, _nodes);
+ renderWithContext(ctx, _nodes);
}
}
-class _TemplateException implements TemplateException {
+class _TemplateException implements m.TemplateException {
_TemplateException(this.message, this.templateName, this.source, this.offset);
diff --git a/lib/src/token.dart b/lib/src/token.dart
index 2683a04..9e9b88f 100644
--- a/lib/src/token.dart
+++ b/lib/src/token.dart
@@ -1,8 +1,8 @@
part of mustache.impl;
-class _Token {
+class Token {
- _Token(this.type, this.value, this.start, this.end, {this.indent : ''});
+ Token(this.type, this.value, this.start, this.end, {this.indent : ''});
final int type;
final String value;