Skip to content

Commit

Permalink
Merge pull request #6 from Capibara-Tools/add-example-support
Browse files Browse the repository at this point in the history
Add example support
  • Loading branch information
JustinWoodring authored Sep 28, 2023
2 parents 058f5bf + fadd9f8 commit 6931a5b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
12 changes: 11 additions & 1 deletion capibara-website/app/models/Function.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ object Parameter {
implicit val parameterFormatter = Json.format[Parameter];
}

object Example {
implicit val exampleFormatter = Json.format[Example];
}

object Function {
implicit val functionFormatter = Json.format[Function];
}
Expand All @@ -20,6 +24,7 @@ case class Function(
returns: Return,
parameters: Seq[Parameter],
description: String,
examples: Seq[Example],
associated: Seq[String],
os_affinity: Seq[String]
)
Expand All @@ -33,4 +38,9 @@ case class Parameter(
name: String,
`type`: String,
description: String,
)
)

case class Example(
title: String,
code: String,
)
12 changes: 11 additions & 1 deletion capibara-website/app/models/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ object MacroParameter {
implicit val parameterFormatter = Json.format[MacroParameter];
}

object MacroExample {
implicit val parameterFormatter = Json.format[MacroExample];
}

object MacroFunction {
implicit val functionFormatter = Json.format[MacroFunction];
}
Expand Down Expand Up @@ -43,7 +47,8 @@ case class MacroKind(

case class MacroFunction(
returns: MacroReturn,
parameters: Seq[MacroParameter]
parameters: Seq[MacroParameter],
examples: Seq[MacroExample]
)

case class MacroReturn(
Expand All @@ -55,3 +60,8 @@ case class MacroParameter(
name: String,
description: String
)

case class MacroExample(
title: String,
code: String,
)
15 changes: 15 additions & 0 deletions clientapp/src/pages/capi/definitions/CapiFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export default function CapiFunction({ fn }) {
);
});

const examples = fn.examples.map((e) => {
return (
<>
<h4>{e.title}</h4>
<div className="example">
<ReactMarkdown children={capiMdLinkReplace("```"+e.code+"```")} />
</div>
</>
);
});

return (
<>
<h4 className="breadcrumbs">
Expand Down Expand Up @@ -48,6 +59,10 @@ export default function CapiFunction({ fn }) {
<ReactMarkdown children={capiMdLinkReplace(fn.description)} />
</div>
</div>
<div className="attribute-group">
<h3>examples</h3>
{examples}
</div>
</div>
</>
);
Expand Down
19 changes: 19 additions & 0 deletions clientapp/src/pages/capi/definitions/CapiMacro.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReactMarkdown } from "react-markdown/lib/react-markdown.js";

export default function CapiMacro({ mo }) {
var parameters = [];
var examples = [];

if (!!mo.kind?.function) {
parameters = mo.kind.function.parameters.map((p) => {
Expand All @@ -18,6 +19,17 @@ export default function CapiMacro({ mo }) {
</>
);
});

examples = mo.kind.function.examples.map((e) => {
return (
<>
<h4>{e.title}</h4>
<div className="example">
<ReactMarkdown children={capiMdLinkReplace("```"+e.code+"```")} />
</div>
</>
);
});
}

return (
Expand Down Expand Up @@ -72,6 +84,13 @@ export default function CapiMacro({ mo }) {
<ReactMarkdown children={capiMdLinkReplace(mo.description)} />
</div>
</div>
{!!mo.kind?.function && (
<>
<div className="attribute-group">
<h3>examples</h3>
<ul>{examples}</ul>
</div>
</>)}
</div>
</>
);
Expand Down

0 comments on commit 6931a5b

Please sign in to comment.