Skip to content

Commit

Permalink
feat(CodeChunk): Add support for caption & label fields
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ketch committed Aug 28, 2020
1 parent bda1e36 commit 3d78d9d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions py/stencila/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ class CodeChunk(CodeBlock):
assigns: Optional[Array[Union[str, "Variable"]]] = None
"""Variables that the code chunk assigns to."""

caption: Optional[Union[str, Array["Node"]]] = None
"""A caption for the CodeChunk."""

declares: Optional[Array[Union[str, "Variable", "Function"]]] = None
"""Variables that the code chunk declares."""

Expand All @@ -280,6 +283,9 @@ class CodeChunk(CodeBlock):
imports: Optional[Array[Union[str, "SoftwareSourceCode", "SoftwareApplication"]]] = None
"""Software packages that the code chunk imports"""

label: Optional[str] = None
"""A short label for the CodeChunk."""

outputs: Optional[Array["Node"]] = None
"""Outputs from executing the chunk."""

Expand All @@ -295,6 +301,7 @@ def __init__(
text: str,
alters: Optional[Array[str]] = None,
assigns: Optional[Array[Union[str, "Variable"]]] = None,
caption: Optional[Union[str, Array["Node"]]] = None,
declares: Optional[Array[Union[str, "Variable", "Function"]]] = None,
duration: Optional[float] = None,
errors: Optional[Array["CodeError"]] = None,
Expand All @@ -303,6 +310,7 @@ def __init__(
id: Optional[str] = None,
importTo: Optional[str] = None,
imports: Optional[Array[Union[str, "SoftwareSourceCode", "SoftwareApplication"]]] = None,
label: Optional[str] = None,
meta: Optional[Dict[str, Any]] = None,
outputs: Optional[Array["Node"]] = None,
programmingLanguage: Optional[str] = None,
Expand All @@ -322,6 +330,8 @@ def __init__(
self.alters = alters
if assigns is not None:
self.assigns = assigns
if caption is not None:
self.caption = caption
if declares is not None:
self.declares = declares
if duration is not None:
Expand All @@ -330,6 +340,8 @@ def __init__(
self.errors = errors
if imports is not None:
self.imports = imports
if label is not None:
self.label = label
if outputs is not None:
self.outputs = outputs
if reads is not None:
Expand Down
6 changes: 6 additions & 0 deletions r/R/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ CodeBlock <- function(
#' @param text The text of the code. \bold{Required}.
#' @param alters Names of variables that the code chunk alters.
#' @param assigns Variables that the code chunk assigns to.
#' @param caption A caption for the CodeChunk.
#' @param declares Variables that the code chunk declares.
#' @param duration Duration in seconds of the last execution of the chunk.
#' @param errors Errors when compiling or executing the chunk.
Expand All @@ -231,6 +232,7 @@ CodeBlock <- function(
#' @param id The identifier for this item.
#' @param importTo A compilation directive giving the name of the variable to import the content of the code block as.
#' @param imports Software packages that the code chunk imports
#' @param label A short label for the CodeChunk.
#' @param meta Metadata associated with this item.
#' @param outputs Outputs from executing the chunk.
#' @param programmingLanguage The programming language of the code.
Expand All @@ -242,6 +244,7 @@ CodeChunk <- function(
text,
alters,
assigns,
caption,
declares,
duration,
errors,
Expand All @@ -250,6 +253,7 @@ CodeChunk <- function(
id,
importTo,
imports,
label,
meta,
outputs,
programmingLanguage,
Expand All @@ -268,10 +272,12 @@ CodeChunk <- function(
self$type <- as_scalar("CodeChunk")
self[["alters"]] <- check_property("CodeChunk", "alters", FALSE, missing(alters), Array("character"), alters)
self[["assigns"]] <- check_property("CodeChunk", "assigns", FALSE, missing(assigns), Array(Union("character", Variable)), assigns)
self[["caption"]] <- check_property("CodeChunk", "caption", FALSE, missing(caption), Union("character", Array(Node)), caption)
self[["declares"]] <- check_property("CodeChunk", "declares", FALSE, missing(declares), Array(Union("character", Variable, Function)), declares)
self[["duration"]] <- check_property("CodeChunk", "duration", FALSE, missing(duration), "numeric", duration)
self[["errors"]] <- check_property("CodeChunk", "errors", FALSE, missing(errors), Array(CodeError), errors)
self[["imports"]] <- check_property("CodeChunk", "imports", FALSE, missing(imports), Array(Union("character", SoftwareSourceCode, SoftwareApplication)), imports)
self[["label"]] <- check_property("CodeChunk", "label", FALSE, missing(label), "character", label)
self[["outputs"]] <- check_property("CodeChunk", "outputs", FALSE, missing(outputs), Array(Node), outputs)
self[["reads"]] <- check_property("CodeChunk", "reads", FALSE, missing(reads), Array("character"), reads)
self[["uses"]] <- check_property("CodeChunk", "uses", FALSE, missing(uses), Array(Union("character", Variable)), uses)
Expand Down
15 changes: 15 additions & 0 deletions schema/CodeChunk.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ status: unstable
category: code
description: A executable chunk of code.
properties:
caption:
'@id': schema:caption
description: A caption for the CodeChunk.
$comment: |
An array of nodes or, to be compatible with https://schema.org/caption,
a string.
anyOf:
- type: string
- type: array
items:
$ref: Node
label:
'@id': stencila:label
description: A short label for the CodeChunk.
type: string
imports:
'@id': stencila:imports
description: Software packages that the code chunk imports
Expand Down

0 comments on commit 3d78d9d

Please sign in to comment.