-
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: register this as an antora extension
- Loading branch information
Showing
18 changed files
with
289 additions
and
615 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:icons: font | ||
:source-highlighter: highlightjs |
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 |
---|---|---|
|
@@ -8,5 +8,4 @@ | |
}, | ||
"asciidoc.extensions.registerWorkspaceExtensions": true, | ||
"asciidoc.preview.refreshInterval": 500, | ||
|
||
} |
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 @@ | ||
<link rel="stylesheet" href="{{{uiRootPath}}}/css/treeview.css"> |
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,5 @@ | ||
name: treeview | ||
title: TreeView Example | ||
version: ~ | ||
nav: | ||
- modules/ROOT/nav.adoc |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
* xref:index.adoc[] |
File renamed without changes.
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,59 @@ | ||
'use strict' | ||
|
||
const ospath = require('path') | ||
const { name: packageName } = require('../../package.json') | ||
const { assetFile, partialFile } = require('./utils/asset-utils') | ||
|
||
module.exports = function (context, { playbook, config }) { | ||
const logger = context.getLogger(packageName) | ||
|
||
logger.info('Start extension') | ||
logger.info(' > Register asciidoctor-treeview as asciidoc extension') | ||
playbook.asciidoc.extensions.push('asciidoctor-treeview') | ||
|
||
context.on('uiLoaded', async ({ playbook, uiCatalog }) => { | ||
logger.info('Handle UICatalog files ...') | ||
|
||
const extensionContext = { | ||
logger, | ||
} | ||
|
||
const { uiOutputDir, cacheDir = './.cache/antora' } = getDirectories(playbook) | ||
extensionContext.playbook = playbook | ||
extensionContext.uiCatalog = uiCatalog | ||
extensionContext.uiOutputDir = uiOutputDir | ||
extensionContext.cacheDir = cacheDir | ||
extensionContext.extensionCacheDir = ospath.join(cacheDir, '..', packageName) | ||
|
||
await processAssets(extensionContext) | ||
}) | ||
|
||
function getDirectories (playbook) { | ||
return { | ||
uiOutputDir: playbook.ui.outputDir, | ||
cacheDir: playbook.runtime.cacheDir, | ||
} | ||
} | ||
|
||
async function processAssets (extensionContext) { | ||
copyTreeViewStyleCss(extensionContext) | ||
copyTreeViewStyleHbs(extensionContext) | ||
} | ||
|
||
function copyTreeViewStyleCss (extensionContext) { | ||
const { uiCatalog, uiOutputDir, logger } = extensionContext | ||
|
||
const basename = 'treeview.css' | ||
const cssDir = 'css' | ||
assetFile(packageName, uiCatalog, logger, uiOutputDir, cssDir, basename) | ||
} | ||
|
||
function copyTreeViewStyleHbs (extensionContext) { | ||
const { uiCatalog, uiOutputDir, logger } = extensionContext | ||
|
||
const basename = 'treeview-styles.hbs' | ||
const assetDir = 'partials' | ||
|
||
partialFile(packageName, uiCatalog, logger, uiOutputDir, assetDir, basename) | ||
} | ||
} |
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,90 @@ | ||
const LazyReadable = require('./lazy-readable') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const ASSET_TYPE = 'asset' | ||
const PARTIAL_TYPE = 'partial' | ||
const DATA_DIR = path.join(__dirname, '../../../data') | ||
|
||
function handleFile ( | ||
type, | ||
packageName, | ||
uiCatalog, | ||
logger, | ||
uiOutputDir, | ||
assetDir, | ||
basename, | ||
createContents, | ||
overwrite | ||
) { | ||
const assetPath = path.join(assetDir, basename) | ||
const outputDir = path.join(uiOutputDir, assetDir) | ||
const existingFiles = uiCatalog.findByType(type) | ||
const existingFile = existingFiles.find((file) => file.path === assetPath) | ||
|
||
if (existingFile) { | ||
if (overwrite) { | ||
logger.warn(` > Please remove the following file from your UI since it is managed by ${packageName}: ${assetPath}`) | ||
existingFile.contents = createContents(assetPath) | ||
delete existingFile.stat | ||
} else { | ||
logger.warn(' > The following file already exists in your UI => skipping ...') | ||
|
||
const isUIBundle = !existingFile._cwd.endsWith('/supplemental-ui') | ||
|
||
logger.info(` > ${assetPath} from ${existingFile._cwd} ${isUIBundle ? '(UI Bundle)' : ''}`) | ||
} | ||
} else { | ||
const fileDetails = { | ||
contents: createContents(assetPath), | ||
type: type, | ||
path: assetPath, | ||
out: { dirname: outputDir, path: path.join(outputDir, basename), basename }, | ||
} | ||
|
||
if (type === PARTIAL_TYPE) { | ||
fileDetails.stem = basename.replace('.hbs', '') | ||
} | ||
|
||
logger.info(` > Copying ${assetPath} to ${outputDir}`) | ||
uiCatalog.addFile(fileDetails) | ||
} | ||
} | ||
|
||
function assetFile (packageName, uiCatalog, logger, uiOutputDir, assetDir, basename, overwrite = false) { | ||
handleFile( | ||
ASSET_TYPE, | ||
packageName, | ||
uiCatalog, | ||
logger, | ||
uiOutputDir, | ||
assetDir, | ||
basename, | ||
(assetPath) => new LazyReadable(() => fs.createReadStream(path.join(DATA_DIR, assetPath))), | ||
overwrite | ||
) | ||
} | ||
|
||
function partialFile (packageName, uiCatalog, logger, uiOutputDir, assetDir, basename, overwrite = false) { | ||
handleFile( | ||
PARTIAL_TYPE, | ||
packageName, | ||
uiCatalog, | ||
logger, | ||
uiOutputDir, | ||
assetDir, | ||
basename, | ||
(assetPath) => Buffer.from(fs.readFileSync(path.join(DATA_DIR, assetPath))), | ||
overwrite | ||
) | ||
} | ||
|
||
function getPartialFileContent (packageName, uiCatalog, logger, uiOutputDir, assetDir, basename) { | ||
const assetPath = path.join(assetDir, basename) | ||
const existingFiles = uiCatalog.findByType(PARTIAL_TYPE) | ||
const existingFile = existingFiles.find((file) => file.path === assetPath) | ||
|
||
return existingFile.contents.toString() | ||
} | ||
|
||
module.exports = { assetFile, partialFile, getPartialFileContent } |
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,10 @@ | ||
const fs = require('fs') | ||
|
||
function createFolder (folderPath, logger) { | ||
if (!fs.existsSync(folderPath)) { | ||
logger.debug(' > Create folder: ' + folderPath) | ||
fs.mkdirSync(folderPath, { recursive: true }) | ||
} | ||
} | ||
|
||
module.exports = { createFolder } |
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,18 @@ | ||
'use strict' | ||
|
||
const { PassThrough } = require('stream') | ||
|
||
// adapted from https://github.com/jpommerening/node-lazystream/blob/master/lib/lazystream.js | license: MIT | ||
class LazyReadable extends PassThrough { | ||
constructor (fn, options) { | ||
super(options) | ||
this._read = function () { | ||
delete this._read // restores original method | ||
fn.call(this, options).on('error', this.emit.bind(this, 'error')).pipe(this) | ||
return this._read.apply(this, arguments) | ||
} | ||
this.emit('readable') | ||
} | ||
} | ||
|
||
module.exports = LazyReadable |
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
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
Oops, something went wrong.