Skip to content

Commit cd4691b

Browse files
Document current real-world naming conventions
1 parent a4927b8 commit cd4691b

File tree

1 file changed

+111
-40
lines changed

1 file changed

+111
-40
lines changed

docs/coding_style/yaml.md

Lines changed: 111 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,55 +64,126 @@ Where possible, avoid using leading digits in file names. Leading digits
6464
are not valid in Python variable names, and it is often convenient to have
6565
variable names and file names have matching prefixes.
6666

67-
### Use descriptive names for YAML files
67+
### When there is just one YAML file in the package, use a descriptive name for it
6868

69-
When you are editing a file, the context sometimes is missing in places that the
70-
file name is displayed. Therefore, you should prefer using file names like
71-
"eviction_interview.yml" to just "interview.yml". Have the name describe the
72-
function of the file, and give it a name that might be meaningful and build
73-
trust with your end user.
69+
Most interviews use just one YAML file. This name can "leak" into the user's view
70+
in some cases, so it is usually best to make it a complete, descriptive filename.
7471

75-
Avoid using numbers, underscores, and other markers to indicate that you have a
76-
"final", "draft", etc. interview even during the editing process, as these have
77-
a chance of getting leaked to the public. Instead, use [version
78-
control](../authoring/github.md) to track the history of your files as your project develops.
72+
For example: `eviction.yml` is probably a better filename than `interview.yml`. It will
73+
be easier to know what file you are working on, and the name will be more descriptive if
74+
it shows to the final user of your tool.
7975

80-
### Use a small number of YAML files for each project
76+
The descriptive name can, and often will, match the name of the package.
8177

82-
It can be a frustrating game of "which file is that in, again?" if you have too
83-
many YAML files. Start out with just one YAML file for your interview. Start
84-
adding additional files when:
78+
Your interview YAML name should avoid:
8579

86-
1. you want to use an interview like a module inside another interview
87-
1. your YAML file is thousands of lines long and you have clear functional
88-
separation between each file. For example: code, style, questions; or
89-
maybe "eviction", "appeals", "bad_housing_conditions".
90-
1. you need to split work between multiple developers and you are running into
91-
challenges with overwriting each others' work
92-
1. you need non-technical members of your team to be able to make changes with
93-
confidence. You might choose to separate code from question language, in that
94-
case.
80+
* Suffixes like `_final`, `_draft`, etc., even when you are in the middle of building it.
81+
Use GitHub [version control](../authoring/github.md) instead to track multiple versions of the work in progress.
82+
* Any other "insider" information that you do not want the public to see, like the statute number.
9583

96-
### Use clear filenames for modular interview files
84+
Make sure to remove characters that accidentally got added during the edit process, like
85+
(1) that might have been added when you download the file to a Downloads folder that
86+
already has a copy of the same file.
9787

98-
Docassemble allows you to include one interview into another interview file.
99-
If you want to design a file to be re-used:
88+
### When you have multiple files in a single package, give each file a clear prefix
10089

101-
1. avoid putting any mandatory blocks in the file
102-
1. use the [`named block` pattern](https://suffolklitlab.org/legal-tech-class/docs/practical-guide-docassemble/controlling-interview-order#triggering-code-and-then-continuing-using-named-blocks) for the `interview order` block
103-
1. reference your `named block` in the file users will run
104-
1. describe the function of each file in the name
90+
While simple interviews have one YAML file, there are three strong reasons to have more than one YAML file in
91+
a single Docassemble package:
92+
93+
1. If one package has multiple, distinct interviews contained within it, perhaps for different audiences, like
94+
children, parents, or interested people, or someone filing a complaint or someone answering it.
95+
2. If one interview assembles multiple complex forms. In that case, it may be helpful to put any unique
96+
questions for each form, as well as the attachment block, into its own YAML file.
97+
3. If the YAML file simply is getting too large to easily manage. In that case, you might break up the YAML
98+
into multiple files that are easier to edit. In this case, make sure the reasoning for each file is clear. E.g., you could separate the interview's metadata, questions, and logic into three separate files.
99+
100+
Even if an interview makes sense on its own, you may want to make it re-usable as a module in other interviews.
101+
For example: a fee waiver, an interpreter notice, or a request for accommodation. In that case, you want
102+
to make sure that the mandatory logic and metadata are separated from the part you want to re-use in other
103+
interviews.
105104

106-
We recommend the annotations:
105+
Keep things simple when you can! Think ahead to the developer experience. If you are dividing work
106+
across multiple authors, think through what a single change will look like. Can an author make a change
107+
without having to edit multiple YAML files in most cases?
107108

108-
1. `to_include` for the file with the interview logic, attachment block, and questions
109-
1. `standalone` for a file that includes and then runs just one `to_include` file
110-
1. `umbrella` for a file that generates multiple templates
109+
Our current recommendations to name the files in this scenario are:
111110

112-
Example:
111+
1. Any runnable files in your package should be named `main.yml`. If there are multiple runnable files,
112+
give each file the prefix `main_`. (`main` has a long history in computer programming.)
113+
1. If the interview assembles multiple documents, you can make a separate YAML file for each document that contains the unique questions it needs and the document's attachment block. Name it after the document itself,
114+
e.g., `financial_statement.yml`. (be consistent with this: if the
115+
separate documents are very short, you may not need this, but it should be all or nothing inside a single package.)
116+
1. Name the file that is used by multiple related interview endpoints `shared.yml`.
113117

114-
Filename | Purpose
115-
------------------------|--------------
116-
eviction_to_include.yml | The interview order block, questions, and content for one interview that cannot be run from this file.
117-
eviction_standalone.yml | Include and run just one interview about evictions
118-
eviction_umbrella.yml | Include and run multiple interviews related to eviction
118+
:::info
119+
Remember, there should be only one `mandatory` block in a given combination of YAML files. That means
120+
you should never put a `mandatory` block in the files for each individual document.
121+
122+
To group logic that you might want to run with the template it relates to, without making it mandatory:
123+
124+
1. use the [`named block` pattern](https://suffolklitlab.org/legal-tech-class/docs/practical-guide-docassemble/controlling-interview-order#triggering-code-and-then-continuing-using-named-blocks) for the `interview order` block
125+
1. reference your `named block` in a mandatory block inside the `main` file that users will run.
126+
127+
While in the development phase, you might want to temporarily test a single document at a time.
128+
You can do so by making, e.g., a `financial_statement.yml` and a `main_financial_statement.yml` file.
129+
The `mandatory` block will be in the `main_financial_statement.yml` and reference the `named block`
130+
inside the `financial_statement.yml` file. Be careful to not rely on this for more than quick tests!
131+
You'll always want a final round of testing when `financial_statement.yml` runs in combination with
132+
the forms you want the user to interact with.
133+
:::
134+
135+
If you need to subdivide very long YAML files further:
136+
137+
1. Label files that contain only questions `questions.yml`, or prefix with `questions_`. If the name is too long, `ql_eviction.yml` is a reasonable abbreviation that follows the Assembly Line's existing conventions.
138+
1. Name shared files that contain other kind of functionality, e.g., integration with a separate service,
139+
`support.yml` or prefix the filename with `support_`. E.g., `support_legal_server.yml`, `support_s3.yml`.
140+
1. Name files that contain only logic `logic.yml`, or prefix with `logic_`. E.g., `logic_eviction_defenses.yml`.
141+
1. Name files that contain functionality that only affects the appearance of the interview (e.g., loading CSS)`theme.yml` or `visual.yml`.
142+
143+
Examples:
144+
145+
#### An interview with exactly one YAML file in it
146+
147+
Filename | Purpose
148+
---------|--------
149+
`eviction.yml` _or_ `main_eviction.yml` | The one YAML file containing mandatory blocks, attachments, metadata. The whole enchilada.
150+
151+
`main_eviction.yml` is slightly more flexible for future growth. But, for many simple interviews,
152+
you know you do not need this future flexibility.
153+
154+
#### A fee waiver that can be assembled by many different interviews
155+
156+
Filename | Purpose
157+
---------|---------
158+
`main.yml` _or_ `main_fee_waiver.yml` | The runnable interview file when someone wants ONLY the fee waiver. Contains mandatory code and metadata (e.g., interview title), and the document bundle (al_user_bundle and al_court_bundle).
159+
`fee_waiver.yml` | Has **no** mandatory logic. Contains questions and the attachment block, and a "named block" with interview order logic that can be referenced in a parent interview's mandatory interview order block.
160+
161+
#### An interview that assembles multiple documents in different combinations depending on audience
162+
163+
Filename | Purpose
164+
---------|---------
165+
`main_petition_for_guardianship.yml` | Entry point for an interested person. Has metadata, a mandatory interview order block and the document bundle (al_user_bundle and al_court_bundle).
166+
`main_object_to_guardianship.yml` | Entry point for the person whose right is being restricted (e.g., a parent or incapacitated adult). Has metadata, a mandatory interview order block and the document bundle (al_user_bundle and al_court_bundle).
167+
`shared.yml` | Contains shared questions, and only questions (perhaps with some basic code setting simple shared variables), for the guardianship process that multiple documents might need written the same way.
168+
`petition_for_guardianship.yml` | Contains unique questions for the petition and attachment code. No mandatory blocks.
169+
`bond.yml` | Contains unique questions, logic, and attachment code for a bond form.
170+
`request_for_counsel.yml` | Contains unique questions, logic, and attachment code for a counsel request form. No mandatory blocks.
171+
172+
#### A complex interview with only one entry point but where managing a single YAML file is too cumbersome
173+
174+
Filename | Purpose
175+
---------|-------------
176+
`main.yml` _or_ `eviction.yml` | Metadata, mandatory logic, document bundle
177+
`questions.yml` | Only questions
178+
`logic.yml` | Code blocks that define various behavior, such as whether a defense or claim will be made.
179+
`support_legal_server.yml` | Support / setup code that handles connecting to the Legal Server CMS.
180+
`support_office_365.yml` | Support / setup code for connecting to Office 365.
181+
`theme.yml` | Code / setup / metadata that controls the appearance of the interview, but nothing else.
182+
183+
:::info
184+
Above we suggest that you can use either `main.yml` (a functional name) or `eviction.yml` (descriptive).
185+
186+
Remember that the descriptive name is great when you are sure that you will only have one "descriptive"
187+
name in the package. If you might edit the package later to add multiple documents, it might be best
188+
to start with `main.yml` right at the start of the interview.
189+
:::

0 commit comments

Comments
 (0)