-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[mustache_template] Initial import #9944
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
Merged
auto-submit
merged 225 commits into
flutter:main
from
stuartmorgan-g:mustache-template-import
Sep 4, 2025
Merged
Changes from all commits
Commits
Show all changes
225 commits
Select commit
Hold shift + click to select a range
65a318a
Packaging
xxgreg 3f17ddc
Fixes
xxgreg 1a0883c
Add README
xxgreg a21cdfc
Preserve source location in tokens
xxgreg 7b3c588
Preserve source location in nodes
xxgreg 3d338ed
Add source location to error messages
xxgreg 61bb26f
Render should return a String
xxgreg 62be8ca
Update test
xxgreg 8d06196
Add html escaping
xxgreg dce306f
Make sure all tests are passing
xxgreg e21cc68
Make template variables private
xxgreg ee97da0
Update readme and docs
xxgreg c32100a
Add nested sections test
xxgreg 5a232b7
Add strict/lenient mode
xxgreg 6d824b8
Mark escape tags as unimplemented
xxgreg 811f7fc
Update docs, fix comments
xxgreg 7515284
update readme
xxgreg 08c2bde
README.md
xxgreg a8cba79
Update template to use StringSink interface
xxgreg 284937e
Add drone.io badge
xxgreg c19df8b
Bump version
xxgreg 5bb626d
Add parameter to disable html escaping
xxgreg 9ea0c32
Hookup escape tags
xxgreg fd713a0
Update readme
xxgreg ec66136
Bump version
xxgreg 2d20576
Add mustache spec tests
xxgreg 894fdef
Fix no interpolation failure
xxgreg 963f6cd
Trim whitespace from tag names
xxgreg f13c7e7
Handled nested sections where value is not a map
xxgreg f930156
Fix inverse section context misses
xxgreg 450291f
Update spec test
xxgreg 124498f
Update README.md
xxgreg b1a40fd
Resolve names from outer sections in a nested section
xxgreg 4e1919e
Bump version
xxgreg 107acbe
Update readme
xxgreg 612a4be
Comment out test which is a known failure
xxgreg db24b73
Bump version
xxgreg 5d0928d
Implemented standalone lines (Basic without whitespace handling)
xxgreg 8af6cd0
Standalone lines
xxgreg a9b3c91
Handle comments in standalone lines
xxgreg 12cfa23
Implemented dotted names
xxgreg c75e54d
Handle windows line endings
xxgreg da7d524
Add standalone line test
xxgreg 0417366
Added support for implicit iterators
xxgreg e678ba5
Update readme
xxgreg 6b8cd62
Update to Dart M4 release
xxgreg f8b752e
Bump version
xxgreg a05e26e
Support {{#.}} and Iterable values
michaelhixson 7fd5849
Support arbitrary getters in templates via reflection
michaelhixson c956a44
Attempt #2 at reflection
michaelhixson 1b8e245
Add import for dart:mirror
xxgreg a7cee54
Fix test - was overly strict
xxgreg 27839ce
Update options handling, and json usage to latest sdk style
xxgreg 74b9d93
Update dependency and sdk versions, bump version
xxgreg 4b2bbcb
Allow iterable items to be targeted by index
timkendrick 5c099bc
Merge pull request #5 from timkendrick/master
xxgreg 4a0e5a3
Add test for array indexing
xxgreg 19b977f
Bump version
xxgreg 11fbe03
Fix outdated reference to 'members'
yjbanov 7b9c8f1
Merge pull request #6 from yjbanov/mirrors-fix
xxgreg 302b493
Bump version
xxgreg 0deecaf
Update README.md
sethladd dfc8d37
Merge pull request #8 from sethladd/patch-1
xxgreg a374fe6
Initial hack at partials support.
xxgreg e0196af
Cleaned up partials support a little
xxgreg 0f73f5a
Rename MustacheContext to TemplateRenderer
xxgreg 001be5f
Fix warning - FormatException was updated at some point, remove depen…
xxgreg e46fdde
Fix partial test
xxgreg 948a9cf
Fix tests FormatException => MustacheFormatException
xxgreg d209b45
Pass template name in error messages
xxgreg 594773e
Fix lenient handling of partials resolution
xxgreg b9dfb0a
Add more partials tests
xxgreg 7be9160
Add basic lambda support
xxgreg c455223
Add test for Seth's use case
xxgreg 49c4120
Refactor
xxgreg 862d4d0
Add mirrors lambda test
xxgreg 7faee5e
Add mirrors support back
xxgreg 93b89c2
Update pubspec sdk constraint
xxgreg 92f1c8a
Add mirrors used tag to dart library
xxgreg 906596c
Bump version
xxgreg 26aa3ff
Expose name getter on template
xxgreg fb20966
Add whitespace tests issue #10
xxgreg c14c6f4
Investigate other implementations behaviour
xxgreg 823a657
Update gitignore
xxgreg e91b119
Match whitespace handing with python and node mustache implementations
xxgreg 48414cf
Update readme
xxgreg 1dabe42
Update readme
xxgreg f017cb2
Add mirrors note.
xxgreg 5a13693
Update README.md
xxgreg 49ba211
Better error message if null is passed to Template ctor
177cffc
Fix spec test
3862a40
Plug partial whitespace indentation string through to renderPartial
6d0d95e
Initial attempt at indenting partial content correctly - no dice
xxgreg 6bf0ff6
Fix partials handling of whitespace
xxgreg 5c59f88
Initial implementation of the lambda context
xxgreg 12e3831
Fix exception
xxgreg 43bc651
Fix nested partials indenting
xxgreg 5e83cda
Complete lambda context implementation
xxgreg 1160180
Initial delimiters implementation
xxgreg 9cdac99
Improve delimiter implementation
xxgreg 889a10a
Fix handling of delimiters in lambda sections - all spec tests pass woot
xxgreg 5f31bf1
Move classes into separate files
xxgreg 0f5e093
Move standalone whitespace removal into parse, merge text nodes durin…
xxgreg b8afb55
Remove delimiter class
xxgreg 01bd6ab
Change parse to use switch
xxgreg 6481f49
Don't call lambdas for inverted sections - matches mustache.js behaviour
xxgreg a1f3d0a
Change TemplateException
xxgreg 605b499
Start updating scanner
xxgreg 4495d79
Fix indentation of partials
xxgreg a6c2a6d
Clean up some error messages
xxgreg 80176f5
Fix a failing test
xxgreg c6c105d
Cleanups
xxgreg 0e46f1e
Remove char reader class, merge code into scanner
xxgreg 2b0067a
Update README.md
xxgreg d49a0a6
Update README.md
xxgreg c77154a
Update README.md
xxgreg ae6d992
Update README.md
xxgreg 91cfc79
Update README.md
xxgreg 4eaa81b
Add change log
xxgreg 366e04e
Update readme, create changelog, and add some tests
xxgreg 7b12b34
Update README.md
xxgreg 4df408e
Fix travis build
xxgreg b2e3b92
Merge branch 'master' of https://github.com/xxgreg/mustache
xxgreg 7e9aaca
Update README.md
xxgreg e5cae3c
Update dependencies
xxgreg 2b9c1f1
Clean up analyzer hints - not sure why only on command line analyzer
xxgreg 92b20d7
Update changelog
xxgreg 1b01983
Bump version
xxgreg 8c44290
Added examples copied from README, fixed README
damondouglas ad9471f
Update README.md
xxgreg 567417f
Refactor node into seperate classes move render methods into nodes fr…
xxgreg 13ff1af
Clean up handling of delimiters and indenting
xxgreg 6d8b26e
Refactor renderering
xxgreg eee5510
Improved error handling for unclosed tags
xxgreg 76b8a11
Added more methods to LambdaContext
xxgreg 1cf3221
Create mustache.impl library
xxgreg 22cb9e9
Banish the underscores
xxgreg 2a80cac
Fix dartdoc
xxgreg dfc2205
Banish more underscores
xxgreg 96a39d0
Initial scanner impl
xxgreg 08acb17
Clean up scanner
xxgreg c7b361d
Banish even more underscores
xxgreg a35e8e5
Add initial parser re-implementation
xxgreg d65221f
Refactor merge whitespace - do it during parse
xxgreg 035437a
Improve parser
xxgreg c9e979b
Fix standalone whitespace handling
xxgreg 470e496
Set contentStart/End on SectionNode
xxgreg e646577
Handle consecutive standalone lines
xxgreg 9eb8da7
Fix bug with triple mustache tags
xxgreg 3c854b9
Fix usage of sigil constants, use an enum instead
xxgreg 2a2c71f
Fix scanning of change delimiter tags
xxgreg 6c41a3a
Fix incorrect test
xxgreg bf7ab01
Fix handling of comments
xxgreg cdeb981
_readTag() change comments
xxgreg 11fd360
Handle standalone lines for comments and change delimiter tags - most…
xxgreg 7ce6c1f
Add more error messages, and change imports
xxgreg 4c2ee45
Fix corner case with triple mustache tags
xxgreg c60dd1a
Improve parser._readTag()
xxgreg c01f53b
More parser improvements
xxgreg 1c3a521
More parser tweaks
xxgreg 80fb727
More parser tweaks II
xxgreg 7603a6d
More parser and scanner tweaks III
xxgreg b40a2e9
Fix failing test
xxgreg baa6e93
Fix test
xxgreg 321056b
Refactor rendering code out of nodes
xxgreg d618273
Combine RenderContext and Renderer
xxgreg 57a41f0
Handle EOFs while parsing change delimiter tag
xxgreg 79824ff
Update change log
xxgreg 3319982
Bump version
xxgreg 4172d5d
Move equals check from node and token into test
xxgreg 74458ca
Add lame toString test, because I'm a coverage whore
xxgreg 019208a
Inline delimiter code
xxgreg c5b47db
moar coverage
xxgreg 465caef
Add lambda context tests
xxgreg 1b62d8a
Test long exception lines
xxgreg 5188b38
Add mirror method test
xxgreg e4baf49
Remove dead code
xxgreg eb7164f
Fix mirrors used meta target to use annotation type rather than the i…
546ba47
Bump version, update change log
b8a2541
Allow arbitrary objects for truthiness checks in lenient mode, run da…
mkustermann 3cfce2c
Merge pull request #21 from mkustermann/lenient-section-objects
xxgreg 4eeb850
Bump version, update change log
xxgreg c21fc4d
Fix #23: tags containing "=" fail
greg-montoux 3a9f4be
adding delimiters in the constructor of the template class
jorishermans b96632d
adding tests for this new change
jorishermans 036ea9e
Add delimiters parameter to Template interface, and fix test
greg-montoux ce4f525
Fix analyser hints
greg-montoux 72528ec
Dartfmt all the things
greg-montoux 8373940
Remove MustacheFormatException
greg-montoux d10dbd8
Bump version, update changelog
greg-montoux 3de3bca
Fix #24: renderString shrinks multiple newlines to just one
greg-montoux a9b3683
Update travis build badge
greg-montoux 575ffcb
Bump version (hotfix)
greg-montoux 7d6eef5
Fixing strong mode errors
srawlins 35da328
Merge pull request #29 from srawlins/fix-strong-errors
xxgreg 0557f49
Bump version
greg-montoux 1a17688
Move tests to using package test
keertip 3797e70
Changes for landing https://github.com/dart-lang/sdk/issues/32161
MichaelRFairhurst 0d1c1f0
Avoid invocation of Object.
stereotype441 3a23224
Enable strong mode
xxgreg 3421e42
Dart 2: fix failing spec test
xxgreg 7114aba
1.0.1
xxgreg 574d06d
Set the max SDK constraint to <3.0.0
nshahan 5529e74
Merge pull request #40 from nshahan/bump-sdk
xxgreg 580a507
Add support for class members in sections
jcollins-g 22220a5
Merge pull request #41 from jcollins-g/nested-class-resolution
xxgreg 4fd8117
Bump version to 1.1.0
xxgreg 5d46180
Fixes #42
Rodsevich 6382d72
Merge pull request #43 from Rodsevich/master
xxgreg 1601e94
Bumped version to 1.1.1
xxgreg 9b850d4
remove mirrors
ee883fa
update for Dart 2
4f687b8
remove deprecated parse function
bcf938a
update configuration
729331c
fix pubspec
87b3b7c
fix pubspec.yaml
a5c55ba
update pubspec.yaml
ad4bb5d
add export library
6067dd7
fixes to make all existing tests work
6f99021
more updates to changelog
4d440ab
migrate to null safe dart
jonahwilliams cbae271
update sdk constraint
jonahwilliams 2d9ab9c
Initial import of mustache_template
stuartmorgan-g c8c7f59
[mustache_template] Import: Autoformat
stuartmorgan-g cfe8bcd
[mustache_template] Import: Update for reo conventions
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| ## 2.0.1 | ||
|
|
||
| * Transfers the package source from https://github.com/jonahwilliams/mustache | ||
| to https://github.com/flutter/packages. | ||
| * Updates minimum supported SDK version to Dart 3.7. | ||
| * Updates code for new analysis options. | ||
|
|
||
| ## 2.0.0 | ||
|
|
||
| * Support for null safe dart added. | ||
|
|
||
| ## 1.0.0+1 | ||
|
|
||
| * Fixed regression where lookups from list did not work. Removed failing tests | ||
| that depend on reflection. | ||
|
|
||
| ## 1.0.0 | ||
|
|
||
| * Forked from original repo. Support for mirrors removed. | ||
|
|
||
| ## Fork | ||
|
|
||
| ## 1.1.1 | ||
|
|
||
| * Fixed error "boolean expression must not be null". Thanks Nico. | ||
|
|
||
| ## 1.1.0 | ||
|
|
||
| * Better support for class members in sections. Thanks to Janice Collins. | ||
| * Set the SDK constraint to Dart 2+. | ||
|
|
||
| ## 1.0.2 | ||
| Set the max SDK constraint to <3.0.0. | ||
|
|
||
| ## 0.2.5 | ||
|
|
||
| * Remove MustacheFormatException | ||
| * Allow templates to specify default delimiters. Thanks to Joris Hermans. | ||
| * Fix #24: renderString shrinks multiple newlines to just one (Thanks to John Ryan for the repro). | ||
|
|
||
| ## 0.2.4 | ||
|
|
||
| * Fix #23 failure if tag or comment contains "=" | ||
|
|
||
| ## 0.2.3 | ||
|
|
||
| * Change handling of lenient sections to match python mustache implementation. | ||
|
|
||
| ## 0.2.2 | ||
|
|
||
| * Fix MirrorsUsed tag for using mirrors on dart2js. | ||
| * Clean up dead code. | ||
|
|
||
| ## 0.2.1 | ||
|
|
||
| * Added new methods to LambdaContext. | ||
|
|
||
| ## 0.2 | ||
|
|
||
| * Deprecated parse() function - please update your code to use new Template(source). | ||
| * Deprecated MustacheFormatException - please update your code to use TemplateException. | ||
| * Breaking change: Template.render and Template.renderString methods no longer | ||
| take the optional lenient and htmlEscapeValues. These should now be passed to | ||
| the Template constructor. | ||
| * Fully passing all mustache spec tests. | ||
| * Added support for MirrorsUsed. | ||
| * Implemented partials. #11 | ||
| * Implemented lambdas. #4 | ||
| * Implemented change delimiter tag. | ||
| * Add template name parameter, and show this in error messages. | ||
| * Allow whitespace at begining of tags. #10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Copyright (c) 2013, Greg Lowe | ||
| 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. | ||
| 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: "mustache_template" | ||
| description: | ||
| "Mustache template Dart library" | ||
|
|
||
| third_party { | ||
| identifier { | ||
| type: "Git" | ||
| value: "https://github.com/jonahwilliams/mustache" | ||
| primary_source: true | ||
| version: "c4344e0dd45f6605758eb11aa4837859e2c055f0" | ||
| } | ||
| version: "c4344e0dd45f6605758eb11aa4837859e2c055f0" | ||
| last_upgrade_date { year: 2025 month: 9 day: 3 } | ||
| license_type: NOTICE | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Mustache templates | ||
|
|
||
| A Dart library to parse and render [mustache templates](https://mustache.github.io/). | ||
|
|
||
| See the [mustache manual](http://mustache.github.com/mustache.5.html) for detailed usage information. | ||
|
|
||
| This library passes all [mustache specification](https://github.com/mustache/spec/tree/master/specs) tests. | ||
|
|
||
| ## Example usage | ||
| ```dart | ||
| import 'package:mustache_template/mustache_template.dart'; | ||
|
|
||
| main() { | ||
| var source = ''' | ||
| {{# names }} | ||
| <div>{{ lastname }}, {{ firstname }}</div> | ||
| {{/ names }} | ||
| {{^ names }} | ||
| <div>No names.</div> | ||
| {{/ names }} | ||
| {{! I am a comment. }} | ||
| '''; | ||
|
|
||
| var template = Template(source, name: 'template-filename.html'); | ||
|
|
||
| var output = template.renderString({'names': [ | ||
| {'firstname': 'Greg', 'lastname': 'Lowe'}, | ||
| {'firstname': 'Bob', 'lastname': 'Johnson'} | ||
| ]}); | ||
|
|
||
| print(output); | ||
| } | ||
| ``` | ||
|
|
||
| A template is parsed when it is created, after parsing it can be rendered any number of times with different values. A TemplateException is thrown if there is a problem parsing or rendering the template. | ||
|
|
||
| The Template contstructor allows passing a name, this name will be used in error messages. When working with a number of templates, it is important to pass a name so that the error messages specify which template caused the error. | ||
|
|
||
| By default all output from `{{variable}}` tags is html escaped, this behaviour can be changed by passing htmlEscapeValues : false to the Template constructor. You can also use a `{{{triple mustache}}}` tag, or a unescaped variable tag `{{&unescaped}}`, the output from these tags is not escaped. | ||
|
|
||
| ## Differences between strict mode and lenient mode. | ||
|
|
||
| ### Strict mode (default) | ||
|
|
||
| * Tag names may only contain the characters a-z, A-Z, 0-9, underscore, period and minus. Other characters in tags will cause a TemplateException to be thrown during parsing. | ||
|
|
||
| * During rendering, if no map key or object member which matches the tag name is found, then a TemplateException will be thrown. | ||
|
|
||
| ### Lenient mode | ||
|
|
||
| * Tag names may use any characters. | ||
| * During rendering, if no map key or object member which matches the tag name is found, then silently ignore and output nothing. | ||
|
|
||
| ## Nested paths | ||
|
|
||
| ```dart | ||
| var t = Template('{{ author.name }}'); | ||
| var output = template.renderString({'author': {'name': 'Greg Lowe'}}); | ||
| ``` | ||
|
|
||
| ## Partials - example usage | ||
|
|
||
| ```dart | ||
|
|
||
| var partial = Template('{{ foo }}', name: 'partial'); | ||
|
|
||
| var resolver = (String name) { | ||
| if (name == 'partial-name') { // Name of partial tag. | ||
| return partial; | ||
| } | ||
| }; | ||
|
|
||
| var t = Template('{{> partial-name }}', partialResolver: resolver); | ||
|
|
||
| var output = t.renderString({'foo': 'bar'}); // bar | ||
|
|
||
| ``` | ||
|
|
||
| ## Lambdas - example usage | ||
|
|
||
| ```dart | ||
| var t = Template('{{# foo }}'); | ||
| var lambda = (_) => 'bar'; | ||
| t.renderString({'foo': lambda}); // bar | ||
| ``` | ||
|
|
||
| ```dart | ||
| var t = Template('{{# foo }}hidden{{/ foo }}'); | ||
| var lambda = (_) => 'shown'; | ||
| t.renderString('foo': lambda); // shown | ||
| ``` | ||
|
|
||
| ```dart | ||
| var t = Template('{{# foo }}oi{{/ foo }}'); | ||
| var lambda = (LambdaContext ctx) => '<b>${ctx.renderString().toUpperCase()}</b>'; | ||
| t.renderString({'foo': lambda}); // <b>OI</b> | ||
| ``` | ||
|
|
||
| ```dart | ||
| var t = Template('{{# foo }}{{bar}}{{/ foo }}'); | ||
| var lambda = (LambdaContext ctx) => '<b>${ctx.renderString().toUpperCase()}</b>'; | ||
| t.renderString({'foo': lambda, 'bar': 'pub'}); // <b>PUB</b> | ||
| ``` | ||
|
|
||
| ```dart | ||
| var t = Template('{{# foo }}{{bar}}{{/ foo }}'); | ||
| var lambda = (LambdaContext ctx) => '<b>${ctx.renderString().toUpperCase()}</b>'; | ||
| t.renderString({'foo': lambda, 'bar': 'pub'}); // <b>PUB</b> | ||
| ``` | ||
|
|
||
| In the following example `LambdaContext.renderSource(source)` re-parses the source string in the current context, this is the default behaviour in many mustache implementations. Since re-parsing the content is slow, and often not required, this library makes this step optional. | ||
|
|
||
| ```dart | ||
| var t = Template('{{# foo }}{{bar}}{{/ foo }}'); | ||
| var lambda = (LambdaContext ctx) => ctx.renderSource(ctx.source + ' {{cmd}}'); | ||
| t.renderString({'foo': lambda, 'bar': 'pub', 'cmd': 'build'}); // pub build | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # See https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#arguments | ||
| override_platforms: | ||
| chrome: | ||
| settings: | ||
| executable: chrome | ||
| arguments: --no-sandbox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import 'src/template.dart' as t; | ||
|
|
||
| /// A Template can be efficiently rendered multiple times with different | ||
| /// values. | ||
| abstract class Template { | ||
| /// The constructor parses the template source and throws [TemplateException] | ||
| /// if the syntax of the source is invalid. | ||
| /// Tag names may only contain characters a-z, A-Z, 0-9, underscore, and minus, | ||
| /// unless lenient mode is specified. | ||
| factory Template( | ||
| String source, { | ||
| bool lenient, | ||
| bool htmlEscapeValues, | ||
| String name, | ||
| PartialResolver? partialResolver, | ||
| String delimiters, | ||
| }) = t.Template.fromSource; | ||
|
|
||
| /// An optional name used to identify the template in error logging. | ||
| String? get name; | ||
|
|
||
| /// The template that should be filled when calling [render] or | ||
| /// [renderString]. | ||
| String get source; | ||
|
|
||
| /// [values] can be a combination of Map, List, String. Any non-String object | ||
| /// will be converted using toString(). Null values will cause a | ||
| /// [TemplateException], unless lenient module is enabled. | ||
| String renderString(Object? values); | ||
|
|
||
| /// [values] can be a combination of Map, List, String. Any non-String object | ||
| /// will be converted using toString(). Null values will cause a | ||
| /// [TemplateException], unless lenient module is enabled. | ||
| void render(Object? values, StringSink sink); | ||
| } | ||
|
|
||
| // TODO(stuartmorgan): Remove this. See https://github.com/flutter/flutter/issues/174722. | ||
| // ignore: public_member_api_docs | ||
| typedef PartialResolver = Template? Function(String); | ||
|
|
||
| // TODO(stuartmorgan): Remove this. See https://github.com/flutter/flutter/issues/174722. | ||
| // ignore: public_member_api_docs | ||
| typedef LambdaFunction = Object Function(LambdaContext context); | ||
|
|
||
| /// Passed as an argument to a mustache lambda function. The methods on | ||
| /// this object may only be called before the lambda function returns. If a | ||
| /// method is called after it has returned an exception will be thrown. | ||
| abstract class LambdaContext { | ||
| /// Render the current section tag in the current context and return the | ||
| /// result as a string. If provided, value will be added to the top of the | ||
| /// context's stack. | ||
| String renderString({Object? value}); | ||
|
|
||
| /// Render and directly output the current section tag. If provided, value | ||
| /// will be added to the top of the context's stack. | ||
| void render({Object value}); | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Output a string. The output will not be html escaped, and will be written | ||
| /// before the output returned from the lambda. | ||
| void write(Object object); | ||
|
|
||
| /// Get the unevaluated template source for the current section tag. | ||
| String get source; | ||
|
|
||
| /// Evaluate the string as a mustache template using the current context. If | ||
| /// provided, value will be added to the top of the context's stack. | ||
| String renderSource(String source, {Object? value}); | ||
|
|
||
| /// Lookup the value of a variable in the current context. | ||
| Object? lookup(String variableName); | ||
| } | ||
|
|
||
| /// [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 { | ||
| /// A message describing the problem parsing or rendering the template. | ||
| String get message; | ||
|
|
||
| /// The name used to identify the template, as passed to the Template | ||
| /// constructor. | ||
| String? get templateName; | ||
|
|
||
| /// The 1-based line number of the token where formatting error was found. | ||
| int get line; | ||
|
|
||
| /// The 1-based column number of the token where formatting error was found. | ||
| int get column; | ||
|
|
||
| /// The character offset within the template source. | ||
| int? get offset; | ||
|
|
||
| /// The template source. | ||
| String? get source; | ||
|
|
||
| /// A short source substring of the source at the point the problem occurred | ||
| /// with parsing or rendering. | ||
| String get context; | ||
| } | ||
1 change: 1 addition & 0 deletions
1
third_party/packages/mustache_template/lib/mustache_template.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export 'mustache.dart'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The named parameters in this factory constructor are non-nullable and don't have default values or a
requiredkeyword, which will cause analysis errors in Dart 3. They should be updated to match the implementation inTemplate.fromSource, using default values and nullable types where appropriate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird, and looks like a mistake in the initial conversion to NNBD, but I'm not going to change it here.