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

Recommend filenames for package examples #911

Merged
merged 3 commits into from
Jun 11, 2018
Merged
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
25 changes: 23 additions & 2 deletions src/tools/pub/package-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,31 @@ course! Those go inside the `example` directory. If the examples are complex
and use multiple files, consider making a directory for each example. Otherwise,
you can place each one right inside `example`.

This is an important place to consider using `package:` to import files from
your own package. That ensures the example code in your package looks exactly
In your examples, use `package:` to import files from your own package.
That ensures the example code in your package looks exactly
like code outside of your package would look.

If you might publish your package,
consider creating an example file with one of the following names:

* <code>example/lib/main.dart</code>
* <code>example/main.dart</code>
* <code>example/lib/<em>package_name</em>.dart</code>
* <code>example/<em>package_name</em>.dart</code>
* <code>example/lib/<em>package_name</em>_example.dart</code>
* <code>example/<em>package_name</em>_example.dart</code>
* <code>example/lib/example.dart</code>
* <code>example/example.dart</code>

When you publish a package that contains one of the above files,
the pub site creates an **Example** tab to display that file.
For example, the json_serializable package contains a file named
`example/example.dart`, which appears in the
[json_serializable Example tab.](https://pub.dartlang.org/packages/json_serializable#pub-pkg-tab-example)
To see exactly how the example file is chosen, look at the
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the late response. I just meant add a code comment here so any future maintainer of this page knows where the data comes from!

Then it isn't weird to point to a specific file at a specific commit, etc.

[source code.](https:/search?q=org%3Adart-lang+exampleFileCandidates&type=Code)


## Internal tools and scripts

{% prettify none %}
Expand Down