Reverse the sense of the terms snippet and sample. (#48254)
This commit is contained in:
committed by
Flutter GitHub Bot
parent
dbed575c01
commit
fabf4e3d0d
@@ -9,8 +9,8 @@ in the source code into API documentation, as seen on https://api.flutter.dev/.
|
||||
## Table of Contents
|
||||
|
||||
- [Types of code blocks](#types-of-code-blocks)
|
||||
- [Sample tool](#sample-tool)
|
||||
- [Snippet tool](#snippet-tool)
|
||||
- [Sample tool](#sample-tool)
|
||||
- [Skeletons](#skeletons)
|
||||
- [Test Doc Generation Workflow](#test-doc-generation-workflow)
|
||||
|
||||
@@ -18,21 +18,21 @@ in the source code into API documentation, as seen on https://api.flutter.dev/.
|
||||
|
||||
There's two kinds of code blocks.
|
||||
|
||||
* samples, which are more or less context-free snippets that we
|
||||
* snippets, which are more or less context-free code snippets that we
|
||||
magically determine how to analyze, and
|
||||
|
||||
* snippets, which get placed into a full-fledged application, and can
|
||||
* samples, which get placed into a full-fledged application, and can
|
||||
be actually executed inline in the documentation using DartPad.
|
||||
|
||||
### Sample Tool
|
||||
### Snippet Tool
|
||||
|
||||

|
||||

|
||||
|
||||
The code `sample` tool generates a block containing a description and example
|
||||
code. Here is an example of the code `sample` tool in use:
|
||||
The code `snippet` tool generates a block containing a description and example
|
||||
code. Here is an example of the code `snippet` tool in use:
|
||||
|
||||
```dart
|
||||
/// {@tool sample}
|
||||
/// {@tool snippet}
|
||||
///
|
||||
/// If the avatar is to have an image, the image should be specified in the
|
||||
/// [backgroundImage] property:
|
||||
@@ -48,13 +48,13 @@ code. Here is an example of the code `sample` tool in use:
|
||||
This will generate sample code that can be copied to the clipboard and added
|
||||
to existing applications.
|
||||
|
||||
This uses the skeleton for [sample](config/skeletons/sample.html)
|
||||
This uses the skeleton for [snippet](config/skeletons/snippet.html)
|
||||
snippets when generating the HTML to put into the Dart docs.
|
||||
|
||||
#### Analysis
|
||||
|
||||
The `../bots/analyze-sample-code.dart` script finds code inside the
|
||||
`@tool sample` sections and uses the Dart analyzer to check them.
|
||||
`@tool snippet` sections and uses the Dart analyzer to check them.
|
||||
|
||||
There are several kinds of sample code you can specify:
|
||||
|
||||
@@ -91,16 +91,16 @@ You can assume that the entire Flutter framework and most common
|
||||
`dart:*` packages are imported and in scope; `dart:math` as `math` and
|
||||
`dart:ui` as `ui`.
|
||||
|
||||
### Snippet Tool
|
||||
### Sample Tool
|
||||
|
||||

|
||||

|
||||
|
||||
The code `snippet` tool can expand sample code into full Flutter applications.
|
||||
The code `sample` tool can expand sample code into full Flutter applications.
|
||||
These sample applications can be directly copied and used to demonstrate the
|
||||
API's functionality in a sample application:
|
||||
|
||||
```dart
|
||||
/// {@tool snippet --template=stateless_widget_material}
|
||||
/// {@tool sample --template=stateless_widget_material}
|
||||
/// This example shows how to make a simple [FloatingActionButton] in a
|
||||
/// [Scaffold], with a pink [backgroundColor] and a thumbs up [Icon].
|
||||
///
|
||||
@@ -126,10 +126,10 @@ API's functionality in a sample application:
|
||||
/// {@end-tool}
|
||||
```
|
||||
|
||||
This uses the skeleton for [application](config/skeletons/application.html)
|
||||
This uses the skeleton for [application](config/skeletons/sample.html)
|
||||
snippets.
|
||||
|
||||
Code `snippets` also allow for quick Flutter app generation using the following command:
|
||||
Code `sample` also allow for quick Flutter app generation using the following command:
|
||||
|
||||
```bash
|
||||
flutter create --sample=[directory.File.sampleNumber] [name_of_project_directory]
|
||||
@@ -138,12 +138,12 @@ flutter create --sample=[directory.File.sampleNumber] [name_of_project_directory
|
||||
#### Templates
|
||||
|
||||
In order to support showing an entire app when you click on the right tab of
|
||||
the code snippet UI, we have to be able to insert the `snippet` into the template
|
||||
and instantiate the right parts.
|
||||
the code sample UI, we have to be able to insert the `sample` block into the
|
||||
template and instantiate the right parts.
|
||||
|
||||
To do this, there is a [config/templates](config/templates) directory that
|
||||
contains a list of templates. These templates represent an entire app that the
|
||||
`snippet` can be placed into, basically a replacement for `lib/main.dart` in a
|
||||
`sample` can be placed into, basically a replacement for `lib/main.dart` in a
|
||||
flutter app package.
|
||||
|
||||
For more information about how to create, use, or update templates, see
|
||||
@@ -152,7 +152,7 @@ For more information about how to create, use, or update templates, see
|
||||
#### Analysis
|
||||
|
||||
The `../bots/analyze-sample-code.dart` script finds code inside the
|
||||
`@tool snippet` sections and uses the Dart analyzer to check them
|
||||
`@tool sample` sections and uses the Dart analyzer to check them
|
||||
after applying the specified template.
|
||||
|
||||
## Skeletons
|
||||
@@ -161,17 +161,17 @@ A skeleton (in relation to this tool) is an HTML template into which the Dart
|
||||
code blocks and descriptions are interpolated.
|
||||
|
||||
There is currently one skeleton for
|
||||
[application](config/skeletons/application.html) `snippets` and one for
|
||||
[sample](config/skeletons/sample.html) `snippets`, but there could be more.
|
||||
[application](config/skeletons/sample.html) samples and one for
|
||||
[snippet](config/skeletons/snippet.html) code samples, but there could be more.
|
||||
|
||||
Skeletons use mustache notation (e.g. `{{code}}`) to mark where components will
|
||||
be interpolated into the template. It doesn't actually use the mustache
|
||||
package, since these are simple string substitutions, but it uses the same
|
||||
syntax.
|
||||
|
||||
The code block generation tools process the source input and emit HTML for output,
|
||||
which dartdoc places back into the documentation. Any options given to the
|
||||
`{@tool ...}` directive are passed on verbatim to the tool.
|
||||
The code block generation tools process the source input and emit HTML for
|
||||
output, which dartdoc places back into the documentation. Any options given to
|
||||
the `{@tool ...}` directive are passed on verbatim to the tool.
|
||||
|
||||
The `snippets` tool renders these examples through a combination of markdown
|
||||
and HTML using the `{@inject-html}` dartdoc directive.
|
||||
|
||||
Reference in New Issue
Block a user