Skip to content

Commit 8651c39

Browse files
authored
Merge pull request #3581 from obsidian-tasks-group/issue_3580_nested_properties
docs: Document access to nested and object properties
2 parents 43d203f + 8258f38 commit 8651c39

File tree

8 files changed

+126
-49
lines changed

8 files changed

+126
-49
lines changed

docs/Getting Started/Obsidian Properties.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ group by function \
187187

188188
Consider a file with the following example properties (or "Frontmatter"):
189189

190-
<!-- TODO this was copied from docs_sample_for_task_properties_reference.md - embed the content automatically in future... -->
191-
190+
<!-- snippet: DocsSamplesForDefaults.test.DocsSamplesForDefaults_interpret_properties.approved.yaml -->
192191
```yaml
193192
---
194193
sample_checkbox_property: true
@@ -214,8 +213,14 @@ tags:
214213
- tag-from-file-properties
215214
creation date: 2024-05-25T15:17:00
216215
project: Secret Project
216+
nested_data:
217+
surname: "Doe"
218+
firstname: "Jane"
219+
middle name: "Frances"
220+
object_serialization: {"nested1": "value1", "nested2": "value2"}
217221
---
218222
```
223+
<!-- endSnippet -->
219224

220225
The following table shows how most of those properties are interpreted in Tasks queries:
221226

@@ -235,6 +240,11 @@ The following table shows how most of those properties are interpreted in Tasks
235240
| `task.file.property('sample_link_property')` | `string` | `'[[yaml_all_property_types_populated]]'` |
236241
| `task.file.property('sample_link_list_property')` | `string[]` | `['[[yaml_all_property_types_populated]]', '[[yaml_all_property_types_empty]]']` |
237242
| `task.file.property('tags')` | `string[]` | `['#tag-from-file-properties']` |
243+
| `task.file.property('nested_data').surname` | `string` | `'Doe'` |
244+
| `task.file.property('nested_data').firstname` | `string` | `'Jane'` |
245+
| `task.file.property('nested_data')['middle name']` | `string` | `'Frances'` |
246+
| `task.file.property('object_serialization').nested1` | `string` | `'value1'` |
247+
| `task.file.property('object_serialization').nested2` | `string` | `'value2'` |
238248

239249
<!-- placeholder to force blank line after included text --><!-- endInclude -->
240250

docs/Scripting/Task Properties.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ These are described in full in [[Obsidian Properties]].
229229
| `task.file.property('sample_link_property')` | `string` | `'[[yaml_all_property_types_populated]]'` |
230230
| `task.file.property('sample_link_list_property')` | `string[]` | `['[[yaml_all_property_types_populated]]', '[[yaml_all_property_types_empty]]']` |
231231
| `task.file.property('tags')` | `string[]` | `['#tag-from-file-properties']` |
232+
| `task.file.property('nested_data').surname` | `string` | `'Doe'` |
233+
| `task.file.property('nested_data').firstname` | `string` | `'Jane'` |
234+
| `task.file.property('nested_data')['middle name']` | `string` | `'Frances'` |
235+
| `task.file.property('object_serialization').nested1` | `string` | `'value1'` |
236+
| `task.file.property('object_serialization').nested2` | `string` | `'value2'` |
232237

233238
<!-- placeholder to force blank line after included text --><!-- endInclude -->
234239

resources/sample_vaults/Tasks-Demo/Test Data/docs_sample_for_task_properties_reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ tags:
2222
- tag-from-file-properties
2323
creation date: 2024-05-25T15:17:00
2424
project: Secret Project
25+
nested_data:
26+
surname: "Doe"
27+
firstname: "Jane"
28+
middle name: "Frances"
29+
object_serialization: {"nested1": "value1", "nested2": "value2"}
2530
---
2631

2732
# docs_sample_for_task_properties_reference
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
sample_checkbox_property: true
3+
sample_date_property: 2024-07-21
4+
sample_date_and_time_property: 2024-07-21T12:37:00
5+
sample_list_property:
6+
- Sample
7+
- List
8+
- Value
9+
sample_number_property: 246
10+
sample_text_property: Sample Text Value
11+
sample_text_multiline_property: |
12+
Sample
13+
Text
14+
Value
15+
sample_link_property: "[[yaml_all_property_types_populated]]"
16+
sample_link_list_property:
17+
- "[[yaml_all_property_types_populated]]"
18+
- "[[yaml_all_property_types_empty]]"
19+
aliases:
20+
- YAML All Property Types Populated
21+
tags:
22+
- tag-from-file-properties
23+
creation date: 2024-05-25T15:17:00
24+
project: Secret Project
25+
nested_data:
26+
surname: "Doe"
27+
firstname: "Jane"
28+
middle name: "Frances"
29+
object_serialization: {"nested1": "value1", "nested2": "value2"}
30+
---

tests/DocumentationSamples/DefaultsDocs/DocsSamplesForDefaults.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Pos } from 'obsidian';
22

33
import { verify, verifyAsJson } from 'approvals/lib/Providers/Jest/JestApprovals';
44
import { getTasksFileFromMockData } from '../../TestingTools/MockDataHelpers';
5+
import docs_sample_for_task_properties_reference from '../../Obsidian/__test_data__/docs_sample_for_task_properties_reference.json';
56
import query_file_defaults_all_options_null from '../../Obsidian/__test_data__/query_file_defaults_all_options_null.json';
67
import query_file_defaults_all_options_true from '../../Obsidian/__test_data__/query_file_defaults_all_options_true.json';
78
import query_file_defaults_short_mode from '../../Obsidian/__test_data__/query_file_defaults_short_mode.json';
@@ -32,6 +33,10 @@ describe('DocsSamplesForDefaults', () => {
3233
verifyWithFileExtension(extractFrontmatter(query_file_defaults_all_options_true), '.yaml');
3334
});
3435

36+
it('interpret_properties', () => {
37+
verifyWithFileExtension(extractFrontmatter(docs_sample_for_task_properties_reference), '.yaml');
38+
});
39+
3540
describe('demo-short-mode', () => {
3641
// Load query_file_defaults_short_mode.json
3742
const data = query_file_defaults_short_mode;

tests/Obsidian/__test_data__/docs_sample_for_task_properties_reference.json

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
"YAML All Property Types Populated"
66
],
77
"creation date": "2024-05-25T15:17:00",
8+
"nested_data": {
9+
"firstname": "Jane",
10+
"middle name": "Frances",
11+
"surname": "Doe"
12+
},
13+
"object_serialization": {
14+
"nested1": "value1",
15+
"nested2": "value2"
16+
},
817
"project": "Secret Project",
918
"sample_checkbox_property": true,
1019
"sample_date_and_time_property": "2024-07-21T12:37:00",
@@ -49,8 +58,8 @@
4958
"frontmatterPosition": {
5059
"end": {
5160
"col": 3,
52-
"line": 24,
53-
"offset": 614
61+
"line": 29,
62+
"offset": 754
5463
},
5564
"start": {
5665
"col": 0,
@@ -65,46 +74,46 @@
6574
"position": {
6675
"end": {
6776
"col": 43,
68-
"line": 26,
69-
"offset": 659
77+
"line": 31,
78+
"offset": 799
7079
},
7180
"start": {
7281
"col": 0,
73-
"line": 26,
74-
"offset": 616
82+
"line": 31,
83+
"offset": 756
7584
}
7685
}
7786
}
7887
],
7988
"listItems": [
8089
{
81-
"parent": -30,
90+
"parent": -35,
8291
"position": {
8392
"end": {
8493
"col": 83,
85-
"line": 30,
86-
"offset": 765
94+
"line": 35,
95+
"offset": 905
8796
},
8897
"start": {
8998
"col": 0,
90-
"line": 30,
91-
"offset": 682
99+
"line": 35,
100+
"offset": 822
92101
}
93102
},
94103
"task": " "
95104
},
96105
{
97-
"parent": -30,
106+
"parent": -35,
98107
"position": {
99108
"end": {
100109
"col": 71,
101-
"line": 31,
102-
"offset": 837
110+
"line": 36,
111+
"offset": 977
103112
},
104113
"start": {
105114
"col": 0,
106-
"line": 31,
107-
"offset": 766
115+
"line": 36,
116+
"offset": 906
108117
}
109118
},
110119
"task": " "
@@ -115,8 +124,8 @@
115124
"position": {
116125
"end": {
117126
"col": 3,
118-
"line": 24,
119-
"offset": 614
127+
"line": 29,
128+
"offset": 754
120129
},
121130
"start": {
122131
"col": 0,
@@ -130,13 +139,13 @@
130139
"position": {
131140
"end": {
132141
"col": 43,
133-
"line": 26,
134-
"offset": 659
142+
"line": 31,
143+
"offset": 799
135144
},
136145
"start": {
137146
"col": 0,
138-
"line": 26,
139-
"offset": 616
147+
"line": 31,
148+
"offset": 756
140149
}
141150
},
142151
"type": "heading"
@@ -145,13 +154,13 @@
145154
"position": {
146155
"end": {
147156
"col": 19,
148-
"line": 28,
149-
"offset": 680
157+
"line": 33,
158+
"offset": 820
150159
},
151160
"start": {
152161
"col": 0,
153-
"line": 28,
154-
"offset": 661
162+
"line": 33,
163+
"offset": 801
155164
}
156165
},
157166
"type": "paragraph"
@@ -160,13 +169,13 @@
160169
"position": {
161170
"end": {
162171
"col": 71,
163-
"line": 31,
164-
"offset": 837
172+
"line": 36,
173+
"offset": 977
165174
},
166175
"start": {
167176
"col": 0,
168-
"line": 30,
169-
"offset": 682
177+
"line": 35,
178+
"offset": 822
170179
}
171180
},
172181
"type": "list"
@@ -177,13 +186,13 @@
177186
"position": {
178187
"end": {
179188
"col": 19,
180-
"line": 28,
181-
"offset": 680
189+
"line": 33,
190+
"offset": 820
182191
},
183192
"start": {
184193
"col": 0,
185-
"line": 28,
186-
"offset": 661
194+
"line": 33,
195+
"offset": 801
187196
}
188197
},
189198
"tag": "#tag-from-file-body"
@@ -192,13 +201,13 @@
192201
"position": {
193202
"end": {
194203
"col": 11,
195-
"line": 30,
196-
"offset": 693
204+
"line": 35,
205+
"offset": 833
197206
},
198207
"start": {
199208
"col": 6,
200-
"line": 30,
201-
"offset": 688
209+
"line": 35,
210+
"offset": 828
202211
}
203212
},
204213
"tag": "#task"
@@ -207,13 +216,13 @@
207216
"position": {
208217
"end": {
209218
"col": 83,
210-
"line": 30,
211-
"offset": 765
219+
"line": 35,
220+
"offset": 905
212221
},
213222
"start": {
214223
"col": 64,
215-
"line": 30,
216-
"offset": 746
224+
"line": 35,
225+
"offset": 886
217226
}
218227
},
219228
"tag": "#tag-from-task-line"
@@ -222,20 +231,20 @@
222231
"position": {
223232
"end": {
224233
"col": 11,
225-
"line": 31,
226-
"offset": 777
234+
"line": 36,
235+
"offset": 917
227236
},
228237
"start": {
229238
"col": 6,
230-
"line": 31,
231-
"offset": 772
239+
"line": 36,
240+
"offset": 912
232241
}
233242
},
234243
"tag": "#task"
235244
}
236245
]
237246
},
238-
"fileContents": "---\nsample_checkbox_property: true\nsample_date_property: 2024-07-21\nsample_date_and_time_property: 2024-07-21T12:37:00\nsample_list_property:\n - Sample\n - List\n - Value\nsample_number_property: 246\nsample_text_property: Sample Text Value\nsample_text_multiline_property: |\n Sample\n Text\n Value\nsample_link_property: \"[[yaml_all_property_types_populated]]\"\nsample_link_list_property:\n - \"[[yaml_all_property_types_populated]]\"\n - \"[[yaml_all_property_types_empty]]\"\naliases:\n - YAML All Property Types Populated\ntags:\n - tag-from-file-properties\ncreation date: 2024-05-25T15:17:00\nproject: Secret Project\n---\n\n# docs_sample_for_task_properties_reference\n\n#tag-from-file-body\n\n- [ ] #task Task in 'docs_sample_for_task_properties_reference' #tag-from-task-line\n- [ ] #task Another task in 'docs_sample_for_task_properties_reference'\n",
247+
"fileContents": "---\nsample_checkbox_property: true\nsample_date_property: 2024-07-21\nsample_date_and_time_property: 2024-07-21T12:37:00\nsample_list_property:\n - Sample\n - List\n - Value\nsample_number_property: 246\nsample_text_property: Sample Text Value\nsample_text_multiline_property: |\n Sample\n Text\n Value\nsample_link_property: \"[[yaml_all_property_types_populated]]\"\nsample_link_list_property:\n - \"[[yaml_all_property_types_populated]]\"\n - \"[[yaml_all_property_types_empty]]\"\naliases:\n - YAML All Property Types Populated\ntags:\n - tag-from-file-properties\ncreation date: 2024-05-25T15:17:00\nproject: Secret Project\nnested_data:\n surname: \"Doe\"\n firstname: \"Jane\"\n middle name: \"Frances\"\nobject_serialization: {\"nested1\": \"value1\", \"nested2\": \"value2\"}\n---\n\n# docs_sample_for_task_properties_reference\n\n#tag-from-file-body\n\n- [ ] #task Task in 'docs_sample_for_task_properties_reference' #tag-from-task-line\n- [ ] #task Another task in 'docs_sample_for_task_properties_reference'\n",
239248
"filePath": "Test Data/docs_sample_for_task_properties_reference.md",
240249
"getAllTags": [
241250
"#tag-from-file-properties",

tests/Scripting/TaskProperties.test.task_frontmatter_properties.approved.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
| `task.file.property('sample_link_property')` | `string` | `'[[yaml_all_property_types_populated]]'` |
1515
| `task.file.property('sample_link_list_property')` | `string[]` | `['[[yaml_all_property_types_populated]]', '[[yaml_all_property_types_empty]]']` |
1616
| `task.file.property('tags')` | `string[]` | `['#tag-from-file-properties']` |
17+
| `task.file.property('nested_data').surname` | `string` | `'Doe'` |
18+
| `task.file.property('nested_data').firstname` | `string` | `'Jane'` |
19+
| `task.file.property('nested_data')['middle name']` | `string` | `'Frances'` |
20+
| `task.file.property('object_serialization').nested1` | `string` | `'value1'` |
21+
| `task.file.property('object_serialization').nested2` | `string` | `'value2'` |
1722

1823

1924
<!-- placeholder to force blank line after included text -->

tests/Scripting/TaskProperties.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ describe('task', () => {
188188
"task.file.property('sample_link_property')",
189189
"task.file.property('sample_link_list_property')",
190190
"task.file.property('tags')",
191+
192+
"task.file.property('nested_data').surname",
193+
"task.file.property('nested_data').firstname",
194+
"task.file.property('nested_data')['middle name']",
195+
196+
"task.file.property('object_serialization').nested1",
197+
"task.file.property('object_serialization').nested2",
198+
191199
// 'task.file.tags', // TODO Replace
192200
// 'task.file.tags()', // TODO Implement
193201
// "task.file.tags('body')", // TODO Implement

0 commit comments

Comments
 (0)