[examples] Add compilable code snippets (#7909)

This enables frc-docs to use RLIs for things that are currently in-line
code blocks, and ensures they compile, which is important with the 2027
breaking changes coming. They are kept separate from the examples to
ensure they don't polute the VSCode examples finder.

Adds the Encoder snippets used in the frc-docs Encoder article as the
first instance of this.
This commit is contained in:
sciencewhiz
2025-04-22 14:26:26 -07:00
committed by GitHub
parent 26e299115f
commit 21d921184a
9 changed files with 366 additions and 14 deletions

View File

@@ -103,6 +103,24 @@ task checkExamples(type: Task) {
}
}
task checkSnippets(type: Task) {
doLast {
def parsedJson = new groovy.json.JsonSlurper().parseText(snippetsFile.text)
fileCheck(parsedJson, snippetsDirectory)
parsedJson.each {
assert it.name != null
assert it.description != null
assert it.tags != null
assert it.tags.findAll { !tagList.contains(it) }.empty
assert it.foldername != null
assert it.gradlebase != null
if (it.gradlebase == 'java') {
assert it.mainclass != null
}
}
}
}
task checkCommands(type: Task) {
doLast {
def parsedJson = new groovy.json.JsonSlurper().parseText(commandFile.text)
@@ -127,3 +145,4 @@ task checkCommands(type: Task) {
check.dependsOn checkTemplates
check.dependsOn checkExamples
check.dependsOn checkCommands
check.dependsOn checkSnippets