Skip to content

Commit

Permalink
fix(plugin): rename onHandleTag to onHandleDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
h13i32maru committed Apr 22, 2017
1 parent 3a887e9 commit 82db7bc
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
12 changes: 6 additions & 6 deletions site/manual/advanced/api.md
Expand Up @@ -57,14 +57,14 @@ exports.onHandleAST = function(ev) {
ev.data.ast = ...;
};

exports.onHandleTag = function(ev) {
// modify tag
ev.data.tag = ...;
exports.onHandleDocs = function(ev) {
// modify docs
ev.data.docs = ...;
};

exports.onHandleHTML = function(ev) {
// modify HTML
ev.data.html = ...;
exports.onHandleContent = function(ev) {
// modify content
ev.data.content = ...;
};

exports.onComplete = function(ev) {
Expand Down
9 changes: 6 additions & 3 deletions site/plugin/site-plugin.js
@@ -1,13 +1,16 @@
const cheerio = require('cheerio');
const fs = require('fs-extra');
const path = require('path');

let config;
exports.onHandleConfig = function(ev) {
config = ev.data.config;
};

exports.onHandleHTML = function(ev) {
const $ = cheerio.load(ev.data.html);
exports.onHandleContent = function(ev) {
if (path.extname(ev.data.fileName) !== '.html') return;

const $ = cheerio.load(ev.data.content);

// title
$('head title').text('ESDoc - A Good Documentation Generator for JavaScript');
Expand Down Expand Up @@ -65,7 +68,7 @@ exports.onHandleHTML = function(ev) {
`);

// result
ev.data.html = $.html();
ev.data.content = $.html();
};

exports.onComplete = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/ESDoc.js
Expand Up @@ -101,7 +101,7 @@ export default class ESDoc {
results.push(...this._generateForManual(config));
}

results = Plugin.onHandleTag(results);
results = Plugin.onHandleDocs(results);

// cleanup
fs.removeSync(config.destination);
Expand Down
14 changes: 7 additions & 7 deletions src/Plugin/Plugin.js
Expand Up @@ -115,14 +115,14 @@ class Plugin {
}

/**
* handle tag.
* @param {Tag} tag - original tag(s).
* @returns {Tag} handled tag.
* handle docs.
* @param {Object[]} docs - docs.
* @returns {Object[]} handled docs.
*/
onHandleTag(tag) {
const ev = new PluginEvent({tag});
this._execHandler('onHandleTag', ev);
return ev.data.tag;
onHandleDocs(docs) {
const ev = new PluginEvent({docs});
this._execHandler('onHandleDocs', ev);
return ev.data.docs;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/package/plugin/MyPlugin1.js
Expand Up @@ -32,9 +32,9 @@ exports.onHandleAST = function(ev) {
ev.data.ast.program.body[0].declaration.id.name += '_ModifiedAST';
};

exports.onHandleTag = function(ev) {
callInfo.handlerNames.onHandleTag = ['MyPlugin1'];
ev.data.tag[1].name += '_ModifiedTag';
exports.onHandleDocs = function(ev) {
callInfo.handlerNames.onHandleDocs = ['MyPlugin1'];
ev.data.docs[1].name += '_ModifiedTag';
};

exports.onPublish = function(ev) {
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/package/plugin/MyPlugin2.js
Expand Up @@ -20,8 +20,8 @@ exports.onHandleAST = function(ev) {
callInfo.handlerNames.onHandleAST.push('MyPlugin2');
};

exports.onHandleTag = function(ev) {
callInfo.handlerNames.onHandleTag.push('MyPlugin2');
exports.onHandleDocs = function(ev) {
callInfo.handlerNames.onHandleDocs.push('MyPlugin2');
};

exports.onPublish = function(ev) {
Expand Down
4 changes: 2 additions & 2 deletions test/src/ConfigTest/PluginsTest.js
Expand Up @@ -18,7 +18,7 @@ describe('test config.plugins: [...]', ()=>{
assert(plugin.callInfo.handlerNames.onHandleCode);
assert(plugin.callInfo.handlerNames.onHandleCodeParser);
assert(plugin.callInfo.handlerNames.onHandleAST);
assert(plugin.callInfo.handlerNames.onHandleTag);
assert(plugin.callInfo.handlerNames.onHandleDocs);
assert(plugin.callInfo.handlerNames.onPublish);
assert(plugin.callInfo.handlerNames.onHandleContent);
assert(plugin.callInfo.handlerNames.onComplete);
Expand All @@ -44,7 +44,7 @@ describe('test config.plugins: [...]', ()=>{
assert.deepEqual(plugin.callInfo.handlerNames.onHandleCode, ['MyPlugin1', 'MyPlugin2']);
assert.deepEqual(plugin.callInfo.handlerNames.onHandleCodeParser, ['MyPlugin1', 'MyPlugin2']);
assert.deepEqual(plugin.callInfo.handlerNames.onHandleAST, ['MyPlugin1', 'MyPlugin2']);
assert.deepEqual(plugin.callInfo.handlerNames.onHandleTag, ['MyPlugin1', 'MyPlugin2']);
assert.deepEqual(plugin.callInfo.handlerNames.onHandleDocs, ['MyPlugin1', 'MyPlugin2']);
assert.deepEqual(plugin.callInfo.handlerNames.onPublish, ['MyPlugin1', 'MyPlugin2']);
assert.deepEqual(plugin.callInfo.handlerNames.onHandleContent, ['MyPlugin1', 'MyPlugin2']);
assert.deepEqual(plugin.callInfo.handlerNames.onComplete, ['MyPlugin1', 'MyPlugin2']);
Expand Down

0 comments on commit 82db7bc

Please sign in to comment.