Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/chokidar-as-cli/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions examples/chokidar-as-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "chokidar-as-cli",
"version": "1.0.0",
"description": "",
"license": "Tattooine",
"author": "you",
"type": "module",
"scripts": {
"test": "echo \"Hello, world!\" && exit 1"
},
"dependencies": {
"chokidar": "^5.0.0"
},
"bedoc": {
"output": "../output/wikitext/",
"language": "lpc",
"format": "wikitext",
"hooks": "./hooks/lpc-wikitext-hooks.js",
"maxConcurrent": 5
}
}
4 changes: 2 additions & 2 deletions examples/chokidar-as-npm/hooks/lpc-wikitext-hooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const Hooks = {
parse: {},
parser: {},

print: {
formatter: {
async enter(section) {
const {sectionName, sectionContent} = section

Expand Down
44 changes: 44 additions & 0 deletions examples/chokidar-as-npm/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/chokidar-as-npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "chokidar-as-npm",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"license": "Unlicense",
"author": "you",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"chokidar": "^4.0.3"
"chokidar": "^5.0.0"
},
"bedoc": {
"output": "../output/wikitext/",
Expand Down
8 changes: 8 additions & 0 deletions examples/config/config-lpc-to-markdown-combined.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
parser: "examples/node_modules_test/bedoc-lpc-markdown-combined/bedoc-lpc-markdown-combined.js",
formatter: "examples/node_modules_test/bedoc-lpc-markdown-combined/bedoc-lpc-markdown-combined.js",
input: [
"examples/source/lpc/arrays.c",
"examples/source/lpc/base64.c",
],
}
10 changes: 10 additions & 0 deletions examples/config/config-lpc-to-markdown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"language": "lpc",
"format": "markdown",
"output": "output/markdown",
"input": [
"examples/source/lpc/arrays.c",
"examples/source/lpc/base64.c"
],
"hooks": "examples/hooks/lpc-wikitext-hooks.js"
}
10 changes: 10 additions & 0 deletions examples/config/config-lpc-to-markdown.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"language": "lpc",
"format": "markdown",
"output": "examples/output/markdown",
"input": [
"examples/source/lpc/arrays.c",
"examples/source/lpc/base64.c"
],
"hooks": "examples/hooks/lpc-wikitext-hooks.js"
}
7 changes: 7 additions & 0 deletions examples/config/config-lpc-to-wikitext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"language": "lpc",
"format": "wikitext",
"output": "output/",
"input": ["wip/sample/arrays.c", "wip/sample/base64.c"],
"hooks": "wip/wikitext-hooks.js"
}
110 changes: 46 additions & 64 deletions examples/hooks/lpc-markdown-hooks.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,65 @@
export const Hooks = {
parse: {},
export class Parse {
after$extractTags = ctx => {
// NO EXAMPLES! Figure it out on your own.

print: {

name: "lpc-markdown-hooks",
jokes: [],

async setup({log}) {
this.log = log
this.debug = log.newDebug()

this.log.debug("Init hooks for: %o", 2, this.name)
},

async start(document) {
const debug = this.debug

const {moduleName,moduleContent} = document

debug("Start hook for %s (%d functions)", 2,
moduleName, moduleContent.length
)

const result = await this.getDadJokes(moduleContent.length)
const {status, jokes} = result
delete ctx.tag.example
}
}

if(status === "error")
throw new Error(`Failed to fetch jokes: ${result.error}`)
export class Format {
jokes = []

debug("Fetched %o jokes", 2, jokes.length)
setup = async ctx => {
const result = await this.getDadJokes(ctx.length)
const {status, jokes} = result

this.jokes = jokes.map(joke => joke.joke)
},
if(status === "error")
throw new Error(`Failed to fetch jokes: ${result.error}`)

async enter(section) {
const {sectionName, sectionContent} = section
this.jokes = jokes.map(joke => joke.joke)
}

if(sectionName === "description") {
const joke = this.jokes.pop()
before$formatFunction = async ctx => {
const joke = this.jokes.pop()

return joke
? [...sectionContent, joke]
: sectionContent
}
},
if(joke)
ctx.description.push("", joke)
}

/**
/**
* Fetches a dad joke from the icanhazdadjoke API.
*
* @param {number} number - The number of jokes to fetch.
* @returns {Promise<object>} The result of the fetch operation.
*/
async getDadJokes(number = 1) {
const url = `https://icanhazdadjoke.com/search?limit=${number}`
getDadJokes = async(number = 1) => {
const url = `https://icanhazdadjoke.com/search?limit=${number}`

try {
const headers = new Headers()
headers.append("Accept", "application/json")
headers.append("User-Agent", "BeDoc Sample API Usage " +
try {
const headers = new Headers()
headers.append("Accept", "application/json")
headers.append("User-Agent", "BeDoc Sample API Usage " +
"(https://github.com/gesslar/BeDoc)")
const response = await fetch(url, {
method: "GET",
headers: headers,
})
if(!response.ok)
throw new Error(`HTTP error! status: ${response.status}: `+
const response = await fetch(url, {
method: "GET",
headers: headers,
})
if(!response.ok)
throw new Error(`HTTP error! status: ${response.status}: `+
`${response.statusText}`)

const data = await response.json()
return {
status: "success",
message: "Jokes fetched successfully",
jokes: data.results
}
} catch(error) {
return {
status: "error",
error: error,
}
const data = await response.json()

return {
status: "success",
message: "Jokes fetched successfully",
jokes: data.results
}
} catch(error) {
return {
status: "error",
error: error,
}
}
},
}
}
Loading