Skip to content

[mustache_template] Add example app - #36

Closed
princesoni18 wants to merge 11 commits into
flutter:mainfrom
princesoni18:add-mustache-template-example
Closed

princesoni18 wants to merge 11 commits into
flutter:mainfrom
princesoni18:add-mustache-template-example

Conversation

@princesoni18

Copy link
Copy Markdown

Adds an example application for the mustache_template package and updates the README to be more high-level.

Previously the package had no example app (causing a pub.dev score deduction), and most of the documentation lived in the README. This PR moves the detailed examples into a proper example/ directory and cleans up the README.

Fixes flutter/flutter#183936

Pre-Review Checklist

This PR only adds an example app and improves documentation. It does not change any package code, so no version bump or CHANGELOG entry is required. It also falls under the test exemption for pure documentation / example changes.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new example package for mustache_template, including a main.dart file with usage examples and a pubspec.yaml file, and updates the .gitignore to exclude FVM cache. It also updates the README.md to reference these examples using code-excerpt markers. The review feedback highlights discrepancies between the code snippets in README.md and the actual implementations in example/lib/main.dart for exampleUsage, nestedPaths, and lambdasExample, which should be kept in sync.

Comment thread third_party/packages/mustache_template/README.md Outdated
Comment thread third_party/packages/mustache_template/README.md Outdated
Comment thread third_party/packages/mustache_template/README.md Outdated

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

It does not change any package code, so no version bump or CHANGELOG entry is required. It also falls under the test exemption for pure documentation / example changes.

The exemption is for unpublished portions of the example; main.dart is published on pub.dev

Also, this PR does not appear to have had the formatter run on it, as indicated in the checklist, nor does it pass analysis.

Comment thread .gitignore Outdated
.settings

# FVM Version Cache
.fvm/ No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignores for local tools should be done in your user-level git ignore, not added to the repository.

path: ../

dev_dependencies:
lints: ^3.0.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use lints.

{'firstname': 'Bob', 'lastname': 'Johnson'}
]});
/// The main entrypoint for the example app.
void main() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this is relevant to the example; just the original code, omitting the main() and print, should be part of the excerpt.

'author': <String, String>{'name': 'Greg Lowe'},
});
print(output);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then more generally, you've significantly changed the structure of all of these examples, making them longer by adding unnecessary boilerplate. The code being excerpted should be structurally the same as it was, with the changes being those necessary to follow style rules.


## Example usage

<?code-excerpt "main.dart (example_usage)"?>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reference is not correct. Did you run the excerpting tool, or did you manually copy everything between the files?

@princesoni18

Copy link
Copy Markdown
Author

ok i will make the changes and update it ASAP!!

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Regarding your comment in the issue about this PR, you will need to be running a current version of the repository tooling to correctly implement this. Targeting a version of the tooling that is more than three years old won't result in a PR that passes CI.

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

From triage: is this ready for re-review?

@princesoni18

Copy link
Copy Markdown
Author

yes this is ready for re-review with the changes

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs to include removing the ci_config.yaml that exempts this package from excerpt enforcement.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of having this file? All of the code appears to exactly duplicate code in main.dart.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this PR reformatting unrelated files?

None of these changes pass our formatting check. Code needs to be autoformatted using a recent version of Dart, and using our repository's line length settings.

// Simple lambda
var t1 = Template('{{# foo }}inner{{/ foo }}');
Object lambda1(Object? _) => 'bar';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've removed the renderString line, which shows how to actually turn the template into a string and what the result of each example is, making the examples much less useful.

Adopting code excepts should not remove useful parts of examples.

Object lambda5(LambdaContext ctx) => ctx.renderSource('${ctx.source} {{cmd}}');
```

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the structure of the README changed here?

Comment thread .gitignore

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the change to this file.

// ignore_for_file: avoid_print
// ignore_for_file: omit_local_variable_types
// ignore_for_file: strict_raw_type
// ignore_for_file: prefer_final_locals

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you disabled core style rules? We have a consistent style for a reason.

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Thanks for the contribution, but since #40 has passed review, closing in favor of that PR.

jmagman pushed a commit that referenced this pull request Sep 15, 2026
Replaces the hand-written Dart snippets in `mustache_template`'s README
with `<?code-excerpt?>` pragmas backed by a new
`example/lib/readme_excerpts.dart`, so every snippet is validated
against compilable, analyzed source instead of free-hand text (`dart pub
global run flutter_plugin_tools update-excerpts` / `validate` both pass
clean).

This surfaced two pre-existing doc bugs:
- `Template('{{# foo }}')` in the first lambda example had no closing
tag, so it threw a parse error the moment it was actually executed.
- The two `<b>PUB</b>` lambda examples were an exact copy-pasted
duplicate; the duplicate is removed.

Also removes `ci_config.yaml`, whose only purpose was opting the package
out of excerpt validation (see #102679-style TODO in the file) — no
longer needed now that the README is excerpt-backed.

**Note on overlap:** flutter/flutter#183936 already has two other open
PRs addressing it — #23 and #36. This PR was written independently and
additionally removes the `ci_config.yaml` exemption, which neither of
those does. Happy to have maintainers close this in favor of one of
those if that's preferred; flagging here so reviewer time isn't wasted
on duplicate review.

Fixes flutter/flutter#183936

## Pre-Review Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] page, which explains my
responsibilities.
- [x] I read and followed the [Flutter style guide] and ran [the
auto-formatter].
- [x] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[vector_math]`
- [x] I [linked to at least one issue that this PR fixes] in the
description above.
- [x] I followed [the version and CHANGELOG instructions], using
[semantic versioning] and the [repository CHANGELOG style], or I have
commented below to indicate which documented exception this PR falls
under[^1].
- [x] I updated/added any relevant documentation (doc comments with
`///`).
- [x] I added new tests to check the change I am making, or I have
commented below to indicate which [test exemption] this PR falls
under[^1].
- [x] All existing and new tests are passing.

This PR only touches the README, CHANGELOG, an example app, and a CI
opt-out file — no package source changed, so it falls under the
documentation/example test exemption. The new
`example/lib/readme_excerpts.dart` is exercised directly (`dart run`) as
part of verifying this change, and every existing test in the package
(`dart test`, 252 tests) still passes.

[^1]: Regular contributors who have demonstrated familiarity with the
repository guidelines only need to comment if the PR is not
auto-exempted by repo tooling.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/core-packages/blob/main/CONTRIBUTING.md
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[Flutter style guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md
[the auto-formatter]:
https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code
[CLA]: https://cla.developers.google.com/
[linked to at least one issue that this PR fixes]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[the version and CHANGELOG instructions]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version-and-changelog-updates
[semantic versioning]:
https://dart.dev/tools/pub/versioning#semantic-versions
[repository CHANGELOG style]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style
[test exemption]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests

FPOCTSMP-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mustache_template] No example app

2 participants