Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* global Opal, Asciidoctor, ASCIIDOCTOR_JS_VERSION */
const Opal = require('asciidoctor-opal-runtime').Opal
// Node module
;(function (root, factory) {
module.exports = factory
}(this, function (moduleConfig) {
//{{asciidoctorCode}}
//{{asciidoctorAPI}}
//{{asciidoctorVersion}}
/**
* Get Asciidoctor.js version number.
*
* @memberof Asciidoctor
* @returns {string} - returns the version number of Asciidoctor.js.
if (typeof Opal === 'undefined' && typeof module === 'object' && module.exports) {
Opal = require('asciidoctor-opal-runtime').Opal
}
if (typeof Opal === 'undefined') {
//{{opalCode}}
}
// UMD Module
(function (root, factory) {
if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory
} else if (typeof define === 'function' && define.amd) {
// AMD. Register a named module.
define('asciidoctor', ['module'], function (module) {
const includeHttpsSpec = require('../share/asciidoctor-include-https-spec')
const semVer = require('../share/semver')
const config = {
runtime: {
platform: 'node',
engine: 'v12',
framework: 'lollipop'
}
}
const isWin = process.platform === 'win32'
const asciidoctor = require('../../build/asciidoctor-node.js')(config)
const Opal = require('asciidoctor-opal-runtime').Opal // for testing purpose only
const packageJson = require('../../package.json')
const asciidoctorCoreSemVer = semVer(asciidoctor.getCoreVersion())
const testOptions = {
platform: 'Node.js',
baseDir: path.join(__dirname, '..', '..'),
coreVersion: asciidoctorCoreSemVer
}
shareSpec(testOptions, asciidoctor, expect)
includeHttpsSpec(testOptions, asciidoctor, expect)
function fileExists (path) {
try {
fs.statSync(path)
return true
it('should be able to configure Asciidoctor module', () => {
/** @namespace Opal.JAVASCRIPT_PLATFORM.JAVASCRIPT_IO_MODULE.JAVASCRIPT_ENGINE.JAVASCRIPT_FRAMEWORK */
expect(Opal.JAVASCRIPT_IO_MODULE).to.equal('node')
expect(Opal.JAVASCRIPT_PLATFORM).to.equal('node')
expect(Opal.JAVASCRIPT_ENGINE).to.equal('v12')
expect(Opal.JAVASCRIPT_FRAMEWORK).to.equal('lollipop')
const runtime = asciidoctor.getRuntime()
expect(runtime.ioModule).to.equal('node')
expect(runtime.platform).to.equal('node')
expect(runtime.engine).to.equal('v12')
expect(runtime.framework).to.equal('lollipop')
})
})
it('should be able to configure Asciidoctor module', () => {
/** @namespace Opal.JAVASCRIPT_PLATFORM.JAVASCRIPT_IO_MODULE.JAVASCRIPT_ENGINE.JAVASCRIPT_FRAMEWORK */
expect(Opal.JAVASCRIPT_IO_MODULE).to.equal('node')
expect(Opal.JAVASCRIPT_PLATFORM).to.equal('node')
expect(Opal.JAVASCRIPT_ENGINE).to.equal('v12')
expect(Opal.JAVASCRIPT_FRAMEWORK).to.equal('lollipop')
const runtime = asciidoctor.getRuntime()
expect(runtime.ioModule).to.equal('node')
expect(runtime.platform).to.equal('node')
expect(runtime.engine).to.equal('v12')
expect(runtime.framework).to.equal('lollipop')
})
})
it('should be able to configure Asciidoctor module', () => {
/** @namespace Opal.JAVASCRIPT_PLATFORM.JAVASCRIPT_IO_MODULE.JAVASCRIPT_ENGINE.JAVASCRIPT_FRAMEWORK */
expect(Opal.JAVASCRIPT_IO_MODULE).to.equal('node')
expect(Opal.JAVASCRIPT_PLATFORM).to.equal('node')
expect(Opal.JAVASCRIPT_ENGINE).to.equal('v12')
expect(Opal.JAVASCRIPT_FRAMEWORK).to.equal('lollipop')
const runtime = asciidoctor.getRuntime()
expect(runtime.ioModule).to.equal('node')
expect(runtime.platform).to.equal('node')
expect(runtime.engine).to.equal('v12')
expect(runtime.framework).to.equal('lollipop')
})
})
it('should be able to configure Asciidoctor module', () => {
/** @namespace Opal.JAVASCRIPT_PLATFORM.JAVASCRIPT_IO_MODULE.JAVASCRIPT_ENGINE.JAVASCRIPT_FRAMEWORK */
expect(Opal.JAVASCRIPT_IO_MODULE).to.equal('node')
expect(Opal.JAVASCRIPT_PLATFORM).to.equal('node')
expect(Opal.JAVASCRIPT_ENGINE).to.equal('v12')
expect(Opal.JAVASCRIPT_FRAMEWORK).to.equal('lollipop')
const runtime = asciidoctor.getRuntime()
expect(runtime.ioModule).to.equal('node')
expect(runtime.platform).to.equal('node')
expect(runtime.engine).to.equal('v12')
expect(runtime.framework).to.equal('lollipop')
})
})
it('should use the built-in Logger', () => {
const pipe = Opal.StringIO.$new()
const logger = Opal.Logger.$new(pipe)
const now = new Date()
logger.$add(2, 'hello', 'asciidoctor')
const message = pipe.$string()
expect(message).to.contain('WARN -- asciidoctor: hello')
expect(message).to.contain('W, [')
const datetime = /W, \[([^\]]+)].*/g.exec(message)[1]
const datetimeRegexp = new RegExp(/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})\.([0-9]{6})/)
const result = datetimeRegexp.exec(datetime)
const year = parseInt(result[1])
const month = parseInt(result[2])
const day = parseInt(result[3])
const hours = parseInt(result[4])
const minutes = parseInt(result[5])
const seconds = parseInt(result[6])
const nowYear = now.getFullYear()
const nowMonth = now.getMonth()
it('should use the built-in Logger', () => {
const pipe = Opal.StringIO.$new()
const logger = Opal.Logger.$new(pipe)
const now = new Date()
logger.$add(2, 'hello', 'asciidoctor')
const message = pipe.$string()
expect(message).to.contain('WARN -- asciidoctor: hello')
expect(message).to.contain('W, [')
const datetime = /W, \[([^\]]+)].*/g.exec(message)[1]
const datetimeRegexp = new RegExp(/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})\.([0-9]{6})/)
const result = datetimeRegexp.exec(datetime)
const year = parseInt(result[1])
const month = parseInt(result[2])
const day = parseInt(result[3])
const hours = parseInt(result[4])
const minutes = parseInt(result[5])
const seconds = parseInt(result[6])
const nowYear = now.getFullYear()
//{{asciidoctorCode}}
//{{asciidoctorAPI}}
//{{asciidoctorVersion}}
/**
* Get Asciidoctor.js version number.
*
* @memberof Asciidoctor
* @returns {string} - returns the version number of Asciidoctor.js.
*/
Asciidoctor.prototype.getVersion = function () {
return ASCIIDOCTOR_JS_VERSION
}
return Opal.Asciidoctor
}))