Skip to content

Commit

Permalink
docs(samples)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Selman <[email protected]>
  • Loading branch information
dselman committed Jul 20, 2023
1 parent f8b5a46 commit b38f66b
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import TemplateModel from './TemplateModel';
import useAppStore from './store';
import Header from './Header';
import Footer from './Footer';
import SampleDropdown from './SampleDropdown';

function App() {
const init = useAppStore((state) => state.init);
Expand All @@ -20,7 +19,6 @@ function App() {
return (
<div>
<Header/>
<SampleDropdown/>
<Errors/>
<div className="row">
<TemplateMarkdown/>
Expand Down
4 changes: 4 additions & 0 deletions src/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './App.css';
import SampleDropdown from './SampleDropdown';

function Header() {
return (
Expand All @@ -12,6 +13,9 @@ function Header() {
<div className="column">
<h2>Template Playground (Beta)</h2>
</div>
<div className="column">
<SampleDropdown/>
</div>
<div className="column">
<p></p>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/samples/clause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ concept Customer {
o Address address
}`;

const TEMPLATE = `{{#clause address}}
const TEMPLATE = `
> Renders an object using the \`#clause\` block.
{{#clause address}}
#### Address
{{line1}},
{{city}}, {{state}},
Expand Down
34 changes: 34 additions & 0 deletions src/samples/clausecondition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const MODEL = `namespace [email protected]
concept Address {
o String line1
o String city
o String state
o String country
}
@template
concept Customer {
o Address address optional
}`;

const TEMPLATE = `
> Renders an optional object using the \`#clause\` block with a conditional expression.
{{#clause address condition="return address!==undefined"}}
#### Address
{{line1}},
{{city}}, {{state}},
{{country}}
{{/clause}}
Done.
`;

const DATA = {
"$class" : "[email protected]"
};

const NAME = 'Clause with Condition';
export {NAME, MODEL,DATA,TEMPLATE};
21 changes: 21 additions & 0 deletions src/samples/formula.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const MODEL = `namespace [email protected]
@template
concept HelloWorld {
o String name
}`;

const TEMPLATE = `> Includes a TypeScript formula.
### Welcome {{name}}!
Your name has {{% return name.length %}} characters.
`;

const DATA = {
"$class" : "[email protected]",
"name": "John Doe"
};

const NAME = 'Formula';
export {NAME, MODEL,DATA,TEMPLATE};
2 changes: 1 addition & 1 deletion src/samples/formulanow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ concept HelloWorld {
o String name
}`;

const TEMPLATE = `Hello {{name}}!
const TEMPLATE = `> Includes a TypeScript formula that references the implicit \`now\` variable.
Today is **{{% return now.toISOString() %}}**.
`;
Expand Down
4 changes: 3 additions & 1 deletion src/samples/helloworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ concept HelloWorld {
o String name
}`;

const TEMPLATE = `### Welcome {{name}}!
const TEMPLATE = `> The one, the only...
### Hello {{name}}!
`;

const DATA = {
Expand Down
4 changes: 4 additions & 0 deletions src/samples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as clause from './clause';
import * as list from './list';
import * as optional from './optional';
import * as markdown from './markdown';
import * as formula from './formula';
import * as clausecondition from './clausecondition';

export type Sample = {
NAME: string,
Expand All @@ -17,9 +19,11 @@ export type Sample = {
export const SAMPLES:Array<Sample> = [
playground,
helloworld,
formula,
formulanow,
join,
clause,
clausecondition,
list,
optional,
markdown
Expand Down
4 changes: 3 additions & 1 deletion src/samples/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ concept Insurance {
o ItemType[] items
}`;

const TEMPLATE = `## en Locale
const TEMPLATE = `> Joins lists using formatting options
## en Locale
## Style
Expand Down
12 changes: 11 additions & 1 deletion src/samples/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ concept Person {
o String[] middleNames
}`;

const TEMPLATE = `## Middle Names
const TEMPLATE = `> Ordered and unorded list expansion
## Lists
Ordered:
{{#olist middleNames}}
- {{this}}
{{/olist}}
Unordered:
{{#ulist middleNames}}
- {{this}}
{{/ulist}}
`;

const DATA = {
Expand Down
2 changes: 1 addition & 1 deletion src/samples/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MODEL = `namespace [email protected]
concept Empty {
}`;

const TEMPLATE = `
const TEMPLATE = `> Most markdown can be used in a template.
# h1 Heading 8-)
## h2 Heading
Expand Down
10 changes: 8 additions & 2 deletions src/samples/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ concept TemplateData {
o LoyaltyStatus loyaltyStatus optional
}`;

const TEMPLATE = `{{#optional loyaltyStatus}}Your loyalty status: {{level}}{{else}}You do not have a loyalty status.{{/optional}}
const TEMPLATE = `> The \`{{#optional}}\` block is used with optional content.
{{#optional loyaltyStatus}}You have loyalty status.{{else}}You do not have a loyalty status.{{/optional}}
Done.
`;

const DATA = {
"$class" : "[email protected]"
"$class" : "[email protected]",
"loyaltyStatus" : {
$class: "[email protected]",
level: "Gold"
}
};

const NAME = 'Optional';
Expand Down
3 changes: 2 additions & 1 deletion src/samples/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ concept TemplateData {
o Order order
}`;

const TEMPLATE = `### Welcome {{name}}!
const TEMPLATE = `> A general sample that uses a range of features
### Welcome {{name}}!
![AP Logo](https://avatars.githubusercontent.com/u/29445438?s=64)
Expand Down
2 changes: 1 addition & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TemplateMarkTransformer } from '@accordproject/markdown-template';
import { transform } from '@accordproject/markdown-transform';

import {SAMPLES, Sample} from './samples';
import * as playground from './samples/helloworld';
import * as playground from './samples/playground';

interface AppState {
templateMarkdown: string
Expand Down

0 comments on commit b38f66b

Please sign in to comment.