-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c771218
Showing
10 changed files
with
211 additions
and
0 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 @@ | ||
node_modules | ||
test/fixtures/**/build |
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,3 @@ | ||
## 1.0.0 | ||
|
||
- :+1: |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Nathan Houle | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,14 @@ | ||
NPM = $(shell which npm) | ||
MOCHA = ./node_modules/.bin/mocha | ||
|
||
MOCHA_OPTS = \ | ||
--check-leaks \ | ||
--reporter spec | ||
|
||
node_modules: package.json | ||
$(NPM) install | ||
|
||
test: node_modules | ||
$(MOCHA) $(MOCHA_OPTS) test/index.js | ||
|
||
.PHONY: test |
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,54 @@ | ||
# metalsmith-asciidoc | ||
|
||
A Metalsmith plugin to convert asciidoc files. | ||
|
||
|
||
## Installation | ||
|
||
```sh | ||
$ npm install metalsmith-asciidoc | ||
``` | ||
|
||
|
||
## CLI Usage | ||
|
||
Install via `npm`, then add `metalsmith-asciidoc` key to your `metalsmith.json` plugins section: | ||
|
||
```json | ||
{ | ||
"plugins": { | ||
"metalsmith-asciidoc": {} | ||
} | ||
} | ||
``` | ||
|
||
|
||
## API Usage | ||
|
||
Install via `npm` and require `metalsmith-asciidoc`, then pass to Metalsmith using the `use` method: | ||
|
||
```js | ||
var asciidoc = require('metalsmith-asciidoc'); | ||
|
||
metalsmith.use(asciidoc()); | ||
``` | ||
|
||
## Development | ||
|
||
Clone the repo and install dependencies: | ||
|
||
```sh | ||
git clone https://github.com/ndhoule/metalsmith-asciidoc.git | ||
npm install | ||
``` | ||
|
||
Running tests: | ||
|
||
```sh | ||
make test | ||
``` | ||
|
||
|
||
## License | ||
|
||
Code copyright 2014 [Nathan Houle](mailto:[email protected]). Released under the [MIT license](LICENSE.md). |
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,54 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var asciidoc = ( require('asciidoctor.js')() ).Asciidoctor(true); | ||
|
||
var rAsciidoc = /\.(txt|adoc|asciidoc)$/; | ||
|
||
/** | ||
* A function that | ||
* | ||
* @param {string} filename The filename to test. | ||
* @return {boolean} Returns `true` if the file has a recognized Asciidoc extension, otherwise | ||
* `false`. | ||
*/ | ||
var isAsciidoc = function(filename) { | ||
return rAsciidoc.test(filename); | ||
}; | ||
|
||
/** | ||
* Metalsmith plugin that converts Asciidoc documents to HTML files. | ||
* | ||
* @param {Object} [options] A list of options to pass to the Asciidoctor compiler. | ||
* TODO: Currently unused, to be implemented in the future. | ||
* @return {Function} A plugin function, to be consumed by Metalsmith. | ||
*/ | ||
module.exports = function plugin(options) { | ||
options = options || {}; | ||
|
||
return function(files, metalsmith, done) { | ||
setImmediate(done); | ||
|
||
Object.keys(files).forEach(function(filename) { | ||
if (!isAsciidoc(filename)) { | ||
return; | ||
} | ||
|
||
var data = files[filename]; | ||
var dir = path.dirname(filename); | ||
// The name of the file, without its path or file extension. | ||
var baseFilename = path.basename(filename, path.extname(filename)); | ||
// The name of the output file. | ||
var outpath = (dir !== '.' ? path.join(dir, baseFilename) : baseFilename) +'.html'; | ||
|
||
// Convert the input Asciidoc to HTML and replace the file's contents | ||
data.contents = new Buffer(asciidoc.$convert(data.contents.toString())); | ||
|
||
// Remove the old filename from the output list | ||
delete files[filename]; | ||
|
||
// Add the new file to the output list | ||
files[outpath] = data; | ||
}); | ||
}; | ||
}; |
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,30 @@ | ||
{ | ||
"name": "metalsmith-asciidoc", | ||
"version": "1.0.0", | ||
"description": "A Metalsmith plugin to convert asciidoc files.", | ||
"author": "Nathan Houle <[email protected]> (http://nathanhoule.com)", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ndhoule/metalsmith-asciidoc.git" | ||
}, | ||
"bugs": "https://github.com/ndhoule/metalsmith-asciidoc/issues", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"keywords": [ | ||
"metalsmith", | ||
"metalsmith-plugin", | ||
"plugin" | ||
], | ||
"dependencies": { | ||
"asciidoctor.js": "^1.5.0" | ||
}, | ||
"devDependencies": { | ||
"assert": "^1.1.2", | ||
"assert-dir-equal": "^1.0.1", | ||
"metalsmith": "^0.11.0", | ||
"mocha": "^1.21.4" | ||
} | ||
} |
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,8 @@ | ||
<div class="sect1"> | ||
<h2 id="_asciidoc_roolz">Asciidoc Roolz</h2> | ||
<div class="sectionbody"> | ||
<div class="paragraph"> | ||
<p>OMG it’s <em>WAY</em> better than <strong>Markdown</strong>, or any of those other markup languages.</p> | ||
</div> | ||
</div> | ||
</div> |
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,3 @@ | ||
== Asciidoc Roolz | ||
|
||
OMG it's _WAY_ better than *Markdown*, or any of those other markup languages. |
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,22 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var equal = require('assert-dir-equal'); | ||
var Metalsmith = require('metalsmith'); | ||
var asciidoc = require('..'); | ||
|
||
describe('metalsmith-asciidoc', function() { | ||
it('should convert asciidoc files', function(done) { | ||
Metalsmith('test/fixtures/basic') | ||
.use(asciidoc()) | ||
.build(function(err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
equal('test/fixtures/basic/expected', 'test/fixtures/basic/build'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |