diff options
-rw-r--r-- | .github/workflows/jsdoc.yml | 33 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | docs/README.md | 5 | ||||
-rw-r--r-- | jsdoc/c-transpiler.js | 58 | ||||
-rw-r--r-- | jsdoc/conf.json | 29 | ||||
-rw-r--r-- | package.json | 10 |
6 files changed, 137 insertions, 0 deletions
diff --git a/.github/workflows/jsdoc.yml b/.github/workflows/jsdoc.yml new file mode 100644 index 0000000..b2eaefe --- /dev/null +++ b/.github/workflows/jsdoc.yml @@ -0,0 +1,33 @@ +name: GitHub pages + +on: + push: + branches: + - master + +jobs: + deploy: + if: github.repository == 'jow-/ucode' + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install + run: npm install + + - name: Build + run: npm run doc + + - name: Archive docs as artifact + uses: actions/upload-artifact@v2 + with: + name: docs + path: ./docs/ + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/ + enable_jekyll: true @@ -14,3 +14,5 @@ contrib/lemon tests/cram/*.t.err tests/cram/.venv examples/ +docs/* +!docs/*.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..17fffbe --- /dev/null +++ b/docs/README.md @@ -0,0 +1,5 @@ +# ucode Documentation + +## Module Reference + + - [ucode module documentation](index.html) diff --git a/jsdoc/c-transpiler.js b/jsdoc/c-transpiler.js new file mode 100644 index 0000000..55bc617 --- /dev/null +++ b/jsdoc/c-transpiler.js @@ -0,0 +1,58 @@ +/* + * c-transpiler.js - transpile C to JS while retaining line numbers. + * + * Copyright (C) 2023 Jo-Philipp Wich <jo@mein.io> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +'use strict'; + +exports.handlers = { + beforeParse: function(e) { + if (!e.filename.match(/\.(c|h)$/)) + return; + + let chunks = [ { start: 0, end: -1, comment: false } ]; + let chunk = chunks[0]; + let i = 0; + + for (i = 0; i < e.source.length; i++) { + if (!chunk.comment && e.source[i] == '\n' && e.source[i+1] == '/' && e.source[i+2] == '*' && e.source[i+3] == '*') { + chunk.end = i; + chunk = { start: i, end: -1, comment: true }; + chunks.push(chunk); + i += 3; + } + else if (chunk.comment && e.source[i] == '*' && e.source[i+1] == '/') { + chunk.end = i + 1; + chunk = { start: i + 1, end: -1, comment: false }; + chunks.push(chunk); + i += 1; + } + } + + chunk.end = i; + + let source = ''; + + for (chunk of chunks) { + if (chunk.comment) + source += e.source.substring(chunk.start, chunk.end); + else + source += e.source.substring(chunk.start, chunk.end).replace(/(^|\n)/g, '$1//'); + } + + e.source = source; + } +}; diff --git a/jsdoc/conf.json b/jsdoc/conf.json new file mode 100644 index 0000000..50be361 --- /dev/null +++ b/jsdoc/conf.json @@ -0,0 +1,29 @@ +{ + "tags": { + "allowUnknownTags": true, + "dictionaries": ["jsdoc","closure"] + }, + "source": { + "include": ["."], + "exclude": ["CMakeFiles"], + "includePattern": ".+\\.c$" + }, + "plugins": [ + "plugins/markdown", + "jsdoc/c-transpiler" + + ], + "templates": { + "referenceTitle": "OpenWrt ucode library reference", + "disableSort": false, + "collapse": true, + "resources_": { + "OpenWrt": "https://openwrt.org/" + } + }, + "opts": { + "destination": "docs", + "recurse": true, + "readme": "docs/README.md" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..477ef4a --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "scripts": { + "doc": "LC_ALL=C jsdoc -c jsdoc/conf.json -t node_modules/braintree-jsdoc-template" + }, + "devDependencies": { + "braintree-jsdoc-template": "^3.3.0", + "jsdoc": "^4.0.2", + "taffydb": "^2.7.2" + } +} |