Skip to content

Commit 64a60d6

Browse files
committed
landing page; instructions refactor
1 parent 617ce28 commit 64a60d6

File tree

12 files changed

+321
-304
lines changed

12 files changed

+321
-304
lines changed

LearnJsonEverything/Pages/Index.razor

+12-47
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,15 @@
44
<PageTitle>Learn json-everything</PageTitle>
55

66
<div class="row mx-3 fill-remaining">
7-
<div class="mh-100 scroll text-center">
8-
<h1 class="display-4 mt-5 mb-4">
9-
Learn <span class="font-monospace text-muted">json-everything</span>
10-
</h1>
11-
<p class="lead mb-5">An interactive guide to utilizing JSON in .Net</p>
12-
13-
<Feature Title="JSON Schema"
14-
Description="@IndexContent.SchemaTagline"
15-
LessonsUrl="json-schema"
16-
DocsUrl="https://docs.json-everything.net/schema/basics/"
17-
ImageUrl="img/json-schema.png">
18-
</Feature>
19-
@* <Feature Title="JSON Path"
20-
Description="@IndexContent.PathTagline"
21-
LessonsUrl="json-path"
22-
DocsUrl="https://docs.json-everything.net/path/basics/"
23-
ImageUrl="img/json-path.png"
24-
Flipped="true">
25-
</Feature>
26-
<Feature Title="JSON-e"
27-
Description="@IndexContent.JsonETagline"
28-
LessonsUrl="json-e"
29-
DocsUrl="https://docs.json-everything.net/json-e/basics/"
30-
ImageUrl="img/json-e.png">
31-
</Feature>
32-
<Feature Title="JSON Logic"
33-
Description="@IndexContent.LogicTagline"
34-
LessonsUrl="json-logic"
35-
DocsUrl="https://docs.json-everything.net/pointer/basics/"
36-
ImageUrl="img/json-logic.png"
37-
Flipped="true">
38-
</Feature>
39-
<Feature Title="JSON Patch"
40-
Description="@IndexContent.PatchTagline"
41-
LessonsUrl="json-patch"
42-
DocsUrl="https://docs.json-everything.net/patch/basics/"
43-
ImageUrl="img/json-patch.png">
44-
</Feature>
45-
<Feature Title="JSON Pointer"
46-
Description="@IndexContent.PointerTagline"
47-
LessonsUrl="json-pointer"
48-
DocsUrl="https://docs.json-everything.net/pointer/basics/"
49-
ImageUrl="img/json-pointer.png"
50-
Flipped="true">
51-
</Feature>
52-
*@ </div>
53-
</div>
7+
<div class="mh-100 scroll">
8+
<div class="text-center">
9+
<h1 class="display-4 mt-5 mb-4">
10+
Learn <span class="font-monospace text-muted">json-everything</span>
11+
</h1>
12+
<p class="lead mb-5">An interactive guide to utilizing JSON in .Net</p>
13+
</div>
14+
<div class="mt-5 text-justify">
15+
<MarkdownSpan Content="@HelpContent.Intro"></MarkdownSpan>
16+
</div>
17+
</div>
18+
</div>

LearnJsonEverything/Services/HelpContent.cs

+33-197
Original file line numberDiff line numberDiff line change
@@ -2,202 +2,38 @@
22

33
public static class HelpContent
44
{
5-
public const string SchemaEvaluate =
6-
"""
7-
## Evaluating a schema
8-
9-
The schema to be used for evaluation will go in the editor on the left.
10-
11-
The JSON data to evaluate (the "instance") will go in the editor on the right.
12-
13-
Ensure the options are as desired and click "Run".
14-
15-
All of the `json-everything` vocabulary extensions are also available. Use these URIs for your
16-
`$schema` value to enable them:
17-
18-
- [Data](https://docs.json-everything.net/schema/vocabs/data-2023/) - `https://json-everything.net/meta/data-2023`
19-
- [OpenAPI v3.1](https://docs.json-everything.net/schema/vocabs/openapi/) - `https://spec.openapis.org/oas/3.1/meta/base`
20-
- [ArrayExt](https://docs.json-everything.net/schema/vocabs/array-ext/) - `https://json-everything.net/meta/vocab/array-ext`
21-
22-
\* _The Data 2022 dialect is also still supported._
23-
""";
24-
25-
public const string SchemaGenerateSchema =
26-
"""
27-
## Generating a Schema
28-
29-
Enter your C# classes in the editor on the left. The playground will generate a schema for
30-
the first type it encounters, so supporting classes need to be placed at the bottom of the code.
31-
32-
There is no need to add a namespace, however you may need to add `using` statements depending
33-
on the types you expect to use. A few are included by default:
34-
35-
- `System`
36-
- `System.Collections.Generic`
37-
- `System.Text.Json`
38-
- `System.Text.Json.Nodes`
39-
- `System.Text.Json.Serialization`
40-
- `Json.Schema`
41-
- `Json.Schema.Generation`
42-
43-
When you're done, click "Run".
44-
45-
If the C# is valid, you will receive a JSON Schema in the results editor. Otherwise, you will
46-
receive an error that says "compilation error."
47-
48-
***NOTE** The playground will output the compilation error to the console, including the
49-
serialized details. I haven't yet figured out how to interpret these details to provide any
50-
insight into what in particular is wrong. If you know, please feel free to raise an issue.*
51-
52-
## AOT Support
53-
54-
_JsonSchem.Net.Generation_ supports AOT in that it is properly marked as requiring reflection.
55-
However, due to that requirement, it likely will not work as expected in an AOT context.
56-
""";
57-
58-
public const string SchemaGenerateData =
59-
"""
60-
## Generating Random Data
61-
62-
Enter the schema for which you like to generate data into the left editor.
63-
64-
Click "Run", and the resulting data will appear in the right editor.
65-
66-
There are a few limitations on which keywords are supported for data generation. Please
67-
read the [documentation](https://docs.json-everything.net/schema/datagen/schema-datagen/) to find out
68-
what's supported.
69-
""";
70-
71-
public const string SchemaVersion =
72-
"""
73-
Allows selection of which JSON Schema version to use. This option serves as a fallback for when
74-
the schema itself does not include a `$schema` keyword.
75-
""";
76-
77-
public const string SchemaOutputFormat =
78-
"""
79-
The output format is described in the JSON Schema specification. By default, JsonSchema.Net
80-
uses the formats described by the next version of the specification. More information can be
81-
found in [this blog post](https://json-schema.org/blog/posts/fixing-json-schema-output).
82-
83-
The available formats are:
84-
85-
- Flag - just a true/false indication of whether validation succeeded.
86-
- List - All validation results are organized into a top-level list.
87-
- Hierarchical - Validation results are organized into a hierarchy that mimics the schema structure.
88-
89-
If you prefer, you can choose the equivalent 2020-12 output formats using the **Output Structure**
90-
option below. See the [evaluation results](https://docs.json-everything.net/schema/basics/#schema-results)
91-
section of the docs for more information on what the library offers.
92-
""";
93-
94-
public const string SchemaDroppedAnnotations =
95-
"""
96-
Per the JSON Schema specification, subschemas which fail evaluation must drop their annotations.
97-
This option will include these annotations under a `droppedAnnotations` property when using the
98-
"Draft-Next" output. This can be useful for debugging.
99-
""";
100-
101-
public const string SchemaUnknownKeywordsAnnotation =
102-
"""
103-
(experimental) Adds an annotation to the output that contains a list of schema keywords that were
104-
unrecognized by its meta-schema. See
105-
[this JSON Schema discussion](https://github.com/orgs/json-schema-org/discussions/512) for more
106-
information to provide feedback on the potential feature.
107-
""";
108-
109-
public const string SchemaValidateFormat =
110-
"""
111-
Allows you to specify whether the `format` keyword should be asserted. Typically this is an
112-
annotation-only keyword, meaning that it will appear in the output, but it will not be validated.
113-
""";
114-
115-
public const string PathExtraWhitespace =
116-
"""
117-
JSON Path only permits whitespace in specific locations. This option will allow whitespace everywhere.
118-
""";
119-
120-
public const string PathJsonLiterals =
121-
"""
122-
JSON Path doesn't allow composite JSON literals such as arrays and objects in filter expressions.
123-
This option will allow these kinds of values. For example,
124-
125-
```
126-
$[[email protected]=={"key":"value"}]
127-
```
128-
129-
to find all elements where `@.foo` is the JSON object `{"key":"value"}`.
130-
131-
Composite JSON literals are only valid for equality checks, not comparisons.
132-
133-
JSON literals MUST use double quotes `"`, not single quotes `'`.
134-
""";
135-
136-
public const string PathJsonInOperator =
137-
"""
138-
JSON Path does not support the `in` operator in expressions. For example,
139-
140-
```
141-
$[[email protected] in ["a","b","c"]]
142-
```
143-
144-
to find all elements where `@.foo` is either `"a"`, `"b"`, or `"c"`. Or
145-
146-
```
147-
$[?!(5 in @.bar)]
148-
```
149-
150-
to find all elements where `@.bar` does not contain a `5`.
151-
""";
152-
153-
public const string PathMathOperators =
154-
"""
155-
JSON Path only defines equality and comparison operators. This enables other math operators.
156-
Unless otherwise specified, these are only valid for numeric values. If an incompatible value is
157-
encountered during evaluation, the node will not be selected.
158-
159-
- `+` - addition (numbers) & concatenation (strings)
160-
- `-` - subtraction
161-
- `*` - multiplication
162-
- `/` - division
163-
""";
164-
165-
public const string PathRelativeStart =
166-
"""
167-
JSON Path requires paths to start with `$`. However, during development of the specification,
168-
a use case was raised for allowing paths to start with `@`. This option allows such paths.
169-
For example, `@.foo` would be valid as a complete path.
170-
""";
171-
172-
public const string PathEvaluate =
173-
"""
174-
By default, _JsonPath.Net_ operates per the specification. The above options allow
175-
the library to deviate from the specification in useful ways.
176-
""";
177-
178-
public const string JsonEEvaluate =
179-
"""
180-
JSON-e evaluates templates with an optional context.
181-
182-
The template may be any JSON value, and the context must be an object. The output will be displayed below.
183-
184-
Please read the [documentation](https://docs.json-everything.net/json-e/basics/) for more information.
185-
186-
It may also be beneficial to compare your results with the [original JavaScript playground](https://json-e.js.org/playground.html).
187-
188-
This playground also supports YAML input. If either of the inputs are YAML, the output will also be YAML.
189-
""";
190-
191-
public const string PatchApply =
192-
"""
193-
To apply a patch, enter the patch in the left editor and the data to patch in the right editor.
194-
""";
195-
196-
public const string PatchGenerate =
197-
"""
198-
To generate a patch, enter the starting data in the left editor and the target data in the right editor.
199-
200-
Patch generation follows an iterative strategy, preferring multiple small changes. This may result in
201-
larger patches than expected.
5+
public const string Intro =
6+
"""
7+
Welcome to _Learn `json-everything`_: your personal training grounds for learning how to
8+
use the `json-everything` libraries to their full potential!
9+
10+
Inside, you'll find a collection of lessons, each of which highlight a specific feature
11+
provided by one of the libraries. For each lesson, you'll be given some background information,
12+
possibly some links to various documentation, and a coding challenge along with some test
13+
cases. To move on to the next lesson, your code will need to make all test cases pass.
14+
15+
Want to skip ahead and work on a particular lesson? No problem: simply select the lesson
16+
you'd like to work on from the pane on the left. The navigation buttons will activate as
17+
needed to provide a guided experience, but you're free to work on any lessons you want at
18+
any time.
19+
20+
To assist you on your journey, the site will keep track of the lessons you've completed
21+
as well as your solutions to them so that you can take a break and come back at any time
22+
either to continue learning or to review the work you've done.
23+
24+
**This site is 100% client-side. All operations are performed in your browser. There
25+
is no server to send any of your data to.**
26+
27+
---
28+
29+
These lessons are about learning the libraries, not the technologies they implement.
30+
For information on the technologies themselves, please see the following sites:
31+
32+
|||
33+
|:-|:-|
34+
|JSON Schema|[https://json-schema-org.github.io/tour/](https://json-schema-org.github.io/tour/)|
35+
|JSON-e|[https://json-e.js.org/](https://json-e.js.org/)|
36+
|JSON Logic|[https://jsonlogic.com/](https://jsonlogic.com/)|
37+
|JSON Patch|[https://jsonpatch.com/](https://jsonpatch.com/)|
20238
""";
20339
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Nodes;
3+
using Json.More;
4+
5+
namespace LearnJsonEverything.Services;
6+
7+
public static class InstructionsBuilder
8+
{
9+
private const string Instructions =
10+
$"""
11+
### /* TITLE */
12+
13+
#### Background
14+
15+
/* BACKGROUND */
16+
/* REFERENCE */
17+
#### Task
18+
19+
/* INSTRUCTIONS */
20+
21+
#### Code template
22+
23+
```csharp
24+
/* CONTEXT CODE */
25+
```
26+
27+
#### Tests
28+
/* TESTS */
29+
30+
""";
31+
32+
public static string BuildInstructions(LessonData lesson) => Instructions
33+
.Replace("/* TITLE */", lesson.Title)
34+
.Replace("/* INSTRUCTIONS */", lesson.Instructions)
35+
.Replace("/* BACKGROUND */", lesson.Background)
36+
.Replace("/* REFERENCE */", BuildReferenceLinks(lesson))
37+
.Replace("/* CONTEXT CODE */", lesson.ContextCode)
38+
.Replace("/* TESTS */", BuildTestList(lesson.Tests));
39+
40+
private static string BuildReferenceLinks(LessonData lesson)
41+
{
42+
var links = string.Empty;
43+
44+
if (!string.IsNullOrWhiteSpace(lesson.Docs))
45+
links += BuildDocsLink(lesson);
46+
47+
if (!string.IsNullOrWhiteSpace(lesson.Api))
48+
links += BuildApiLink(lesson);
49+
50+
//if (!string.IsNullOrWhiteSpace(lesson.SchemaDocs))
51+
// links += BuildSchemaLink(lesson);
52+
53+
if (string.IsNullOrWhiteSpace(links)) return string.Empty;
54+
55+
return $"\n{links}\n";
56+
}
57+
58+
private static string BuildDocsLink(LessonData lesson) =>
59+
$"[[Documentation](https://docs.json-everything.net/{lesson.Docs})] ";
60+
61+
private static string BuildApiLink(LessonData lesson) =>
62+
$"[[API Reference](https://docs.json-everything.net/{lesson.Api})] ";
63+
64+
//private static string BuildSchemaLink(LessonData lesson) =>
65+
// $"[[JSON Schema Reference](https://www.learnjsonschema.com/{lesson.SchemaDocs})] ";
66+
67+
private static string BuildTestList(JsonArray testData)
68+
{
69+
var tests = testData.Deserialize(SerializerContext.Default.SchemaTestArray)!;
70+
string[] lines =
71+
[
72+
"| Instance | Is Valid |",
73+
"|:-|:-:|",
74+
.. tests.Select(test => $"|`{test.Instance.AsJsonString()}`|{test.IsValid}|")
75+
];
76+
77+
return string.Join(Environment.NewLine, lines);
78+
}
79+
}

LearnJsonEverything/Services/LessonData.cs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public class LessonData
99
public int Index { get; set; }
1010
public Guid Id { get; set; }
1111
public string Title { get; set; }
12+
public string Background { get; set; }
13+
public string Docs { get; set; }
14+
public string Api { get; set; }
15+
public string SchemaDocs { get; set; }
1216
public string Instructions { get; set; }
1317
public string ContextCode { get; set; }
1418
public JsonArray Tests { get; set; }

0 commit comments

Comments
 (0)