Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
⬆️ Upgrade to Asciidoctor 1.5.6.1 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Aug 22, 2017
1 parent b42be03 commit 3638145
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 38 deletions.
19 changes: 11 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ Here’s the list of currently supported backends:

In this example we are using the https://github.com/asciidoctor/asciidoctor-reveal.js[Reveal.js backend]:


```
npm install asciidoctor.js
npm install asciidoctor-template.js
npm install asciidoctor-reveal.js
```

```javascript
var asciidoctor = require('asciidoctor.js')();

require('asciidoctor-template.js');
require('asciidoctor-template.js')();

var options = {safe: 'safe', backend: 'revealjs'};
var content = '= Title\n\n' +
'== Slide 1\n\n' +
'Content 1\n\n' +
'== Slide 2\n\n' +
'Content 2';
var result = asciidoctor.convert(content, options);
const options = {safe: 'safe', backend: 'revealjs'};
const content = `= Title\n\n\
== Slide 1\n\n\
Content 1\n\n\
== Slide 2\n\n\
Content 2`;
const result = asciidoctor.convert(content, options);
console.log(result);
```
51 changes: 31 additions & 20 deletions npm/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Builder.prototype.build = function(callback) {
async.series([
function(callback) { builder.clean(callback); }, // clean
function(callback) { builder.compile(callback); }, // compile
function(callback) { builder.generateUMD(callback); }, // UMD
function(callback) { builder.uglify(callback); } // uglify (optional)
], function() {
log.success('Done in ' + process.hrtime(start)[0] + 's');
Expand Down Expand Up @@ -61,40 +62,50 @@ Builder.prototype.release = function(releaseVersion) {
function(callback) { builder.prepareRelease(releaseVersion, callback); },
function(callback) { builder.build(callback); },
function(callback) { builder.copyToDist(callback); },
function(callback) { builder.commit(releaseVersion, callback); },
function(callback) { builder.publish(callback); },
function(callback) { builder.prepareNextIteration(callback); },
function(callback) { builder.completeRelease(releaseVersion, callback); }
], function() {
log.success('Done in ' + process.hrtime(start)[0] + 's');
});
};

const parseTemplate = function (templateFile, templateModel) {
return fs.readFileSync(templateFile, 'utf8')
.replace(/\r\n/g, '\n')
.split('\n')
.map(line => {
if(line in templateModel){
return templateModel[line];
} else {
return line;
}
})
.join('\n');
};

Builder.prototype.generateUMD = function (callback) {
log.task('generate UMD');

const templateModel = {
'//#{asciidoctorTemplateCode}': fs.readFileSync('build/asciidoctor-backend-template.js', 'utf8')
};

const content = parseTemplate('src/template-asciidoctor-template.js', templateModel);
fs.writeFileSync('build/asciidoctor-template.js', content, 'utf8');
callback();
};

Builder.prototype.prepareRelease = function(releaseVersion, callback) {
log.task('Release version: ' + releaseVersion);

if (process.env.DRY_RUN) {
log.warn('Dry run! To perform the release, run the command again without DRY_RUN environment variable');
} else {
bfs.updateFileSync('package.json', /"version": "(.*?)"/g, '"version": "' + releaseVersion + '"');
this.execSync(`npm version ${releaseVersion}`);
}
callback();
};

Builder.prototype.commit = function(releaseVersion, callback) {
this.execSync('git add -A .');
this.execSync('git commit -m "Release ' + releaseVersion + '"');
this.execSync('git tag v' + releaseVersion);
callback();
};

Builder.prototype.prepareNextIteration = function(callback) {
this.removeDistDirSync();
this.execSync('git add -A .');
this.execSync('git commit -m "Prepare for next development iteration"');
callback();
};

Builder.prototype.publish = function(callback) {
if (process.env.SKIP_PUBLISH) {
log.info('SKIP_PUBLISH environment variable is defined, skipping "publish" task');
Expand Down Expand Up @@ -144,7 +155,7 @@ Builder.prototype.uglify = function(callback) {
var uglify = require('bestikk-uglify');
log.task('uglify');
var files = [
{source: 'build/asciidoctor-backend-template.js', destination: 'build/asciidoctor-backend-template.min.js' }
{source: 'build/asciidoctor-template.js', destination: 'build/asciidoctor-template.min.js' }
];

var tasks = [];
Expand All @@ -162,8 +173,8 @@ Builder.prototype.copyToDist = function(callback) {

log.task('copy to dist/');
builder.removeDistDirSync();
bfs.copySync('build/asciidoctor-backend-template.js', 'dist/main.js');
bfs.copySync('build/asciidoctor-backend-template.min.js', 'dist/main.min.js');
bfs.copySync('build/asciidoctor-template.js', 'dist/main.js');
bfs.copySync('build/asciidoctor-template.min.js', 'dist/main.min.js');
typeof callback === 'function' && callback();
};

Expand Down
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Generic template backend for Asciidoctor.js ",
"main": "dist/main.min.js",
"engines": {
"node": ">=0.12"
"node": ">=4",
"npm": ">=3.0.0"
},
"files": [
"dist/main.js",
Expand All @@ -13,7 +14,8 @@
"README.adoc"
],
"scripts": {
"build": "node npm/build.js",
"test": "mocha",
"build": "node npm/build.js && npm run test",
"dist": "cross-env MINIFY=1 node npm/dist.js",
"package": "cross-env MINIFY=1 node npm/build.js",
"release": "cross-env MINIFY=1 node npm/release.js"
Expand Down Expand Up @@ -41,16 +43,18 @@
},
"homepage": "https://github.com/asciidoctor/asciidoctor-template.js",
"dependencies": {
"jade": "1.11.0",
"asciidoctor.js": "1.5.5-4"
"jade": "1.11.0"
},
"devDependencies": {
"async": "^1.5.0",
"bestikk-fs": "^0.1.0",
"bestikk-log": "^0.1.0",
"bestikk-uglify": "^0.1.1",
"async": "1.5.2",
"asciidoctor.js": "1.5.6-preview.3",
"asciidoctor-reveal.js": "1.0.2",
"bestikk-fs": "0.1.0",
"bestikk-log": "0.1.0",
"bestikk-uglify": "0.1.1",
"colors": "1.1.2",
"cross-env": "^1.0.8",
"opal-compiler": "0.10.1-integration2"
"cross-env": "1.0.8",
"mocha": "3.5.0",
"opal-compiler": "0.11.0-integration8"
}
}
24 changes: 24 additions & 0 deletions src/template-asciidoctor-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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/template', ['asciidoctor'], function () {
return factory();
});
} else {
// Browser globals (root is window)
if (typeof root.Asciidoctor === 'undefined') {
throw new Error('Asciidoctor.js should be loaded before Asciidoctor Template.js');
}
root.Asciidoctor.Template = factory;
}
}(this, function () {
//#{asciidoctorTemplateCode}

return {};
}));
8 changes: 8 additions & 0 deletions test/fixtures/simple_presentation.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= Title

== Slide 1
Content 1

== Slide 2
Content 2

18 changes: 18 additions & 0 deletions test/fixtures/simple_presentation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

<section>
<section id="_slide_1" data-transition="" data-transition-speed="" data-background="" data-background-size="" data-background-repeat="" data-background-transition="">
<h2>Slide 1</h2>
<div id="" class="paragraph $$id apply call">
<p>Content 1</p>
</div>
</section>
</section>

<section>
<section id="_slide_2" data-transition="" data-transition-speed="" data-background="" data-background-size="" data-background-repeat="" data-background-transition="">
<h2>Slide 2</h2>
<div id="" class="paragraph $$id apply call">
<p>Content 2</p>
</div>
</section>
</section>
20 changes: 20 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const asciidoctor = require('asciidoctor.js')();
require('../build/asciidoctor-template.js')(); // Asciidoctor Template
const assert = require('assert');
const fs = require('fs');
const path = require('path');

describe('Rendering', function () {

const readFixtureSync = function (fileName) {
return fs.readFileSync(path.join('test', 'fixtures', fileName), 'utf-8');
};

it('should produce a simple Reveal.js presententation when backend=revealjs', function () {
const options = {safe: 'safe', backend: 'revealjs'};
const file = 'simple_presentation';
const content = readFixtureSync('simple_presentation.adoc');
const html = asciidoctor.convert(content, options);
assert.equal(html, readFixtureSync('simple_presentation.html'));
});
});

0 comments on commit 3638145

Please sign in to comment.