Skip to content

Structure of the library file

hobovsky edited this page Mar 13, 2023 · 2 revisions

The library.json file should conform to the schema present at library.schema.json file. General structure can be described as follows:

  • library - root element
    • polyglots - collection of snippets which present ideas which can be easily translated between languages
      • stencil - properties common to all translations of this polyglot
        • title - title of the snippet.
        • summary - short summary explaining the idea behind the snippet.
        • kataSnippets - a list of editors for which this snippet is relevant. See "Kata snippets" below.
        • content - a markdown string with content of the snippet. Mutually exclusive with contentUrl.
        • contentUrl - an URL which serves a markdown text with content of the snippet. Mutually exclusive with content. See "Content URL" below.
          Note that polyglots usually do not provide any code, because the language is not known. However, they can still provide some markdown with general remarks, pseudocode, etc. and it will be used by translations which do not provide their own content.
        • tags - an array of tags.
      • translations - collection of translations of the idea into specific languages
        • Properties from the sibling stencil - every translation in a polyglot inherits values of properties from the polyglot's stencil, and can explicitly override them if necessary. The contentUrl property is expected to be explicitly provided by majority of polyglot translations.
        • language - language of a kata this snippet is applicable for. See "Languages" below. Mutually exclusive with languages.
        • languages - a set of languages of a kata this snippet is applicable for. See "Languages" below. Mutually exclusive with language.
    • snippets
      • title - title of the snippet.
      • summary - short summary explaining the idea behind the snippet.
      • kataSnippets - a list of editors for which this snippet is relevant. See "Kata snippets" below.
      • language - language of a kata this snippet is applicable for. See "Languages" below. Mutually exclusive with languages.
      • languages - a set of languages of a kata this snippet is applicable for. See "Languages" below. Mutually exclusive with language.
      • content - a markdown string with content of the snippet. Mutually exclusive with contentUrl.
      • contentUrl - an URL which serves a markdown text with content of the snippet. Mutually exclusive with content. See "Content URL" below.
      • tags - an array of tags.
    • tags - Metadata of tags. An empty array, currently not used, reserved for future use.

Kata snippets

Valid values are: "preloaded", "description", "completeSolution", "solutionSetup", "sampleTests", "submissionTests".

Content URL

Currently, content URL is an URL relative to the hardcoded value of https://raw.githubusercontent.com/hobovsky/katasniplib/main/content/snippets/. It's planned to provide other sources of snippets in the future.

Tampermonkey user scripts can connect only to domains specified with @connect userscript attribute. Currently, the only @connect the script uses is raw.githubusercontent.com. If you want to modify the script to fetch snippets from different location, you need to allow your domain with a @connect parameter. See Tempermonkey documentation for details.

Languages

Allowed values are the same as language ids used by Codewars. You can find id used by every supported language in Codewars docs.

One special value is "all", which means that the snippet is applicable to all kata languages. This can be a snippet with some general remark, good practice advice, or related to a description.

Snippet languages should specify languages of a kata this snippet is relevant for, and not just a language of the snippet. Usually these two are the same, but there are exceptions: C is used for tests in C kata and in NASM kata, Ruby is used for tests in SQL kata, JavaScript is used for tests in Lambda Calculus kata. If a snippet contains a piece of C code which can be used in both C and NASM kata, it should list its languages as ["c", "nasm"] etc.

Clone this wiki locally