Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #15 Upgrade to Asciidoctor 2.2.0 #17

Merged
merged 13 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# gulp-asciidoctor

[![Build](https://github.com/asciidoctor/gulp-asciidoctor/workflows/Build/badge.svg)](https://github.com/asciidoctor/gulp-asciidoctor/actions?query=workflow%3ABuild)
[![npm version](https://img.shields.io/npm/v/gulp-asciidoctor.svg)](https://www.npmjs.org/package/gulp-asciidoctor)

A [gulp](https://gulpjs.com) plugin to support Asciidoctor processing in gulp tasks.

## Installation

### Requirements

You need [Node](https://nodejs.org) installed on your machine to install and run the gulp-asciidoctor plugin.

You need [gulp](https://gulpjs.com) installed globally or in your project directory.

### Install gulp-asciidoctor via npm

```
$ npm install gulp-asciidoctor --save
```

### Install gulp-asciidoctor via yarn

```
$ yarn add gulp-asciidoctor
```

## Documentation

More information can be found in the [documentation](./doc/documentation.adoc) an Github.
40 changes: 32 additions & 8 deletions readme.adoc → doc/documentation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[source,javascript]
----
gulp.pipe(asciidoctor({
header_footer: false,
standalone: true,
attributes: ['showtitle']
}));
----
Expand All @@ -15,15 +15,23 @@ gulp.pipe(asciidoctor({
[source,javascript]
----
gulp.pipe(asciidoctor({
header_footer: false,
safe: 'secure', // unsafe, safe, server or secure
doctype: 'article', // book, inline
header_footer: true, // true or false
standalone: true, // true or false
attributes: ['showtitle'],
extension: '.htm'
}));
----

.With templates
[source,javascript]
----
var path = require('path')

gulp.pipe(asciidoctor({
template_dirs: path.join(__dirname, 'templates')
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
}));
----

=== install

Expand All @@ -37,23 +45,39 @@ npm install gulp-asciidoctor --save
The following options can be used to configure the Gulp-Plugin

extension:: Sets the output extension of the plugin. Defaults to '.html'
converter:: Sets the converter to use by the underlying AsciiDoctor. If not set, the default converter for the backeend is used

=== AsciiDoctor Options
The following options of the underlying AsciiDoctor can be set
All options of the underlying AsciiDoctor can be set.

However, the options

* mkdirs
* to_dir
* to_file

will be removed, since they do not make sense in a gulp processing chain.

If not set, the following options will be set to the default values described here

attributes:: Sets additional document attributes, which override equivalently-named attributes defined in the document
backed:: Sets the converter ot use. Defaults to 'html5'
base_dir:: The base directory for resolving relative resources
base_dir:: The base directory for resolving relative resources. Defaults to the directory of the currently processed file
doctype:: The doctype. May be 'article', 'book' or 'inline'. Defaults to 'article'
header_footer:: If true, include header and footer in the output. Defaults to 'true'
safe:: The safemode to use. May be 'unsafe', 'safe', 'server' or 'secure'. Defaults to 'unsafe'
standalone:: Should headers and footers be included. Defaults to 'true'

=== Important

==== Base Directory
Do not forget to set the AsciiDoctor option `base_dir` if you want to include
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Do not forget to set the AsciiDoctor option `base_dir` if you want to include
Do not forget to set the Asciidoctor option `base_dir` if you want to include

files from locations that are non-relative to the currently proecssed file.

==== Obsolete option 'header_footer'
The 'old' option 'header_footer' will be skipped in favor of the new option 'standalone'.
If 'header_footer' is set and 'standalone' is not set, the processor will receive 'standalone' = value of 'header_footer' and the option 'header_footer' will be stripped.
If both 'header_footer' and 'standalone' are set, the option 'header_footer' will be stripped.

=== Change Log
- V2.2.0: upgrade to asciidoctor 2.2.0
- V2.1.1: upgrade to asciidoctor 2.1.1, mocha 7.1.0 and replaced gulp-util with replace-ext and plugin-error
- v1.5.5-4: upgrade asciidoctor.js to version 1.5.5-4 and use version consistent with asciidoctor.js.
- v1.0.8: upgrade asciidoctor.js to version 1.5.5-1 and other deps to latest.
Expand Down
42 changes: 13 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,36 @@
var through = require('through-gulp')
var PluginError = require('plugin-error')
var replaceExt = require('replace-ext')
var asciidoctor = require('asciidoctor')()

/**
* Test is the given object is a class
* @param {object} obj The object to test
*/
function isClass (obj) {
return typeof obj === 'function' && obj.name !== 'Object'
}
var asciidoctor = require('@asciidoctor/core')()

module.exports = function (theOptions = {}) {
var options = theOptions || {}
var asciidoctorOptions = {}
var asciidoctorOptions = { ...theOptions }

// default config
var extension = options.extension || '.html'
// var extensionRegistry = asciidoctor.Extensions

// AsciiDoctor options
asciidoctorOptions.safe = options.safe || 'unsafe' // unsafe, safe, server or secure
asciidoctorOptions.doctype = options.doctype || 'article' // book,inline
asciidoctorOptions.attributes = options.attributes || ['showtitle']
asciidoctorOptions.backend = options.backed || 'html5' // defaults to html5
asciidoctorOptions.doctype = options.doctype || 'article' // defaults to article
asciidoctorOptions.header_footer = (options.header_footer === undefined
? true : options.header_footer)

// If user overrides extension registry, use his registry
// if (options.extension_registry !== undefined) {
// extensionRegistry = options.extension_registry
// }

// Load converter if option is set
if (options.converter !== undefined) {
var cnv = options.converter
if (isClass(options.converter)) {
const CnvClass = options.converter
cnv = new CnvClass()
}

if (typeof cnv.convert === 'function') {
asciidoctor.ConverterFactory.register(cnv, asciidoctorOptions.backend)
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
if (asciidoctorOptions.standalone === undefined) {
if (asciidoctorOptions.header_footer !== undefined) {
asciidoctorOptions.standalone = asciidoctorOptions.header_footer
} else {
throw new PluginError('gulp-asciidoctor', 'Provided custom converter must implement a convert() method')
asciidoctorOptions.standalone = true // standalone defaults to true
}
}
delete asciidoctorOptions.header_footer

// Extension is only used by gulp
delete asciidoctorOptions.extension
delete asciidoctorOptions.to_file
delete asciidoctorOptions.to_dir
delete asciidoctorOptions.mkdirs

// creating a stream through which each file will pass
var stream = through(function (file, encoding, callback) {
Expand Down
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "@asciidoctor/gulp-asciidoctor",
"version": "2.1.1",
"description": "Gulp AsciiDoctor plugin",
"version": "2.2.0",
"description": "Gulp Asciidoctor plugin",
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
"license": "MIT",
"repository": "https://github.com/asciidoctor/gulp-asciidoctor",
"author": {
"name": "John Dong",
"email": "dongwqs@sina.com",
"url": "https://github.com/dongwq/gulp-asciidoctor"
},
"contributors": [
"authors": [
"https://github.com/jeremy889988",
"John Dong <dongwqs@sina.com>",
"Armin Pfarr <arp@henriette-einstein.com>"
],
"engines": {
"node": ">=0.10.0"
"node": ">=8.11",
"npm": ">5.0.0"
},
"standard": {
"env": [
"mocha"
]
},
"scripts": {
"test": "mocha spec/*.spec.js"
"test": "mocha spec/*.spec.js",
"lint": "npm run code:lint",
"code:lint": "standard spec/**/*.js index.js"
},
"files": [
"index.js"
Expand All @@ -36,13 +36,16 @@
"html"
],
"dependencies": {
"asciidoctor": "^2.1.1",
"@asciidoctor/core": "^2.2.0",
"plugin-error": "^1.0.1",
"replace-ext": "^1.0.0",
"through-gulp": "^0.5.0"
},
"devDependencies": {
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"mocha": "^7.1.0",
"nunjucks": "^3.2.1",
"prettier-standard": "^16.2.1",
"standard": "^14.3.1",
"vinyl": "^2.2.0"
Expand Down
17 changes: 0 additions & 17 deletions spec/extensions/testConverterExportsClass.js

This file was deleted.

19 changes: 0 additions & 19 deletions spec/extensions/testConverterExportsFunction.js

This file was deleted.

Loading