-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add semantic versioning, add better demo.
- Loading branch information
1 parent
515441d
commit c12ca8e
Showing
12 changed files
with
11,463 additions
and
5,818 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
addExample('example 1', () => { | ||
var grammar = { | ||
origin: ['#name.capitalize# loves #food.pluralize#'], | ||
name: ['bob', 'mary'], | ||
food: ['banana', 'apple'] | ||
}; | ||
|
||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
|
||
console.log(output); | ||
|
||
const rootEl = document.createElement('div'); | ||
const textEl = document.createElement('pre'); | ||
const codeEl = document.createElement('pre'); | ||
const outputEl = document.createElement('div'); | ||
|
||
textEl.classList.add('output-text'); | ||
codeEl.classList.add('output-code'); | ||
outputEl.classList.add('output-json'); | ||
|
||
codeEl.innerText =`${'```js'} | ||
var grammar = { | ||
origin: ['#name.capitalize# loves #food.pluralize#'], | ||
name: ['bob', 'mary'], | ||
food: ['banana', 'apple'] | ||
}; | ||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
console.log(output); | ||
${'```'} | ||
`; | ||
|
||
outputEl.innerHTML = `<pre>${JSON.stringify(output, null, 2)}</pre>`; | ||
textEl.innerText = output.output; | ||
|
||
rootEl.appendChild(textEl); | ||
rootEl.appendChild(codeEl); | ||
rootEl.appendChild(outputEl); | ||
|
||
return rootEl; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
addExample('random function', () => { | ||
var grammar = { | ||
numberOfPeople: ['#random(50,100)#'], | ||
origin: ['There are #numberOfPeople# people in the village.'] | ||
}; | ||
|
||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
|
||
console.log(output); | ||
|
||
const rootEl = document.createElement('div'); | ||
const textEl = document.createElement('pre'); | ||
const codeEl = document.createElement('pre'); | ||
const outputEl = document.createElement('div'); | ||
|
||
textEl.classList.add('output-text'); | ||
codeEl.classList.add('output-code'); | ||
outputEl.classList.add('output-json'); | ||
|
||
codeEl.innerText =`${'```js'} | ||
var grammar = { | ||
numberOfPeople: ['#random(50,100)#'], | ||
origin: ['There are #numberOfPeople# people in the village.'] | ||
}; | ||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
console.log(output); | ||
${'```'} | ||
`; | ||
|
||
outputEl.innerHTML = `<pre>${JSON.stringify(output, null, 2)}</pre>`; | ||
textEl.innerText = output.output; | ||
|
||
rootEl.appendChild(textEl); | ||
rootEl.appendChild(codeEl); | ||
rootEl.appendChild(outputEl); | ||
|
||
return rootEl; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
addExample('switch function', () => { | ||
var grammar = { | ||
'origin': ['#[char_heritage:heritage]##[char_name:name]##char#'], | ||
'char': ['#char_name# the #char_heritage#'], | ||
'heritage': ['elf', 'dwarf'], | ||
'elfNames': ['legolas', 'eldrin', 'lilli'], | ||
'dwarfNames': ['gak', 'bar', 'norn'], | ||
'name': ['#switch(char_heritage, elf=>elfNames, dwarf=>dwarfNames)#'] | ||
}; | ||
|
||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
|
||
console.log(output); | ||
|
||
const rootEl = document.createElement('div'); | ||
const textEl = document.createElement('pre'); | ||
const codeEl = document.createElement('pre'); | ||
const outputEl = document.createElement('div'); | ||
|
||
textEl.classList.add('output-text'); | ||
codeEl.classList.add('output-code'); | ||
outputEl.classList.add('output-json'); | ||
|
||
codeEl.innerText =`${'```js'} | ||
var grammar = { | ||
'origin': ['#[char_heritage:heritage]##[char_name:name]##char#'], | ||
'char': ['#char_name# the #char_heritage#'], | ||
'heritage': ['elf', 'dwarf'], | ||
'elfNames': ['legolas', 'eldrin', 'lilli'], | ||
'dwarfNames': ['gak', 'bar', 'norn'], | ||
'name': ['#switch(char_heritage, elf=>elfNames, dwarf=>dwarfNames)#'] | ||
}; | ||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
console.log(output); | ||
${'```'} | ||
`; | ||
|
||
outputEl.innerHTML = `<pre>${JSON.stringify(output, null, 2)}</pre>`; | ||
textEl.innerText = output.output; | ||
|
||
rootEl.appendChild(textEl); | ||
rootEl.appendChild(codeEl); | ||
rootEl.appendChild(outputEl); | ||
|
||
return rootEl; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
addExample('custom function', () => { | ||
// gen is always passed as first arg. | ||
Functions.set('subtract', (gen, args) => { | ||
var firstArg = args[0]; | ||
var secondArg = args[1]; | ||
|
||
// Function implementation goes here. | ||
return secondArg - firstArg; | ||
}); | ||
|
||
var grammar = { | ||
origin: ['#subtract(5, 6)#'] // "firstArg" will be 5, secondArg will be 6, will be replaced with 1 (from function return above.) | ||
}; | ||
|
||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
|
||
console.log(output); | ||
|
||
const rootEl = document.createElement('div'); | ||
const textEl = document.createElement('pre'); | ||
const codeEl = document.createElement('pre'); | ||
const outputEl = document.createElement('div'); | ||
|
||
textEl.classList.add('output-text'); | ||
codeEl.classList.add('output-code'); | ||
outputEl.classList.add('output-json'); | ||
|
||
codeEl.innerText =`${'```js'} | ||
Functions.set('subtract', (gen, args) => { | ||
var firstArg = args[0]; | ||
var secondArg = args[1]; | ||
// Function implementation goes here. | ||
return secondArg - firstArg; | ||
}); | ||
var grammar = { | ||
origin: ['#subtract(5, 6)#'] // "firstArg" will be 5, secondArg will be 6, will be replaced with 1 (from function return above.) | ||
}; | ||
var gen = new Generator(grammar); | ||
var output = gen.runAdvanced('#origin#'); | ||
console.log(output); | ||
${'```'} | ||
`; | ||
|
||
outputEl.innerHTML = `<pre>${JSON.stringify(output, null, 2)}</pre>`; | ||
textEl.innerText = output.output; | ||
|
||
rootEl.appendChild(textEl); | ||
rootEl.appendChild(codeEl); | ||
rootEl.appendChild(outputEl); | ||
|
||
return rootEl; | ||
}); |
Oops, something went wrong.