|
|
@@ -12,14 +12,14 @@ export default class RefsContext extends TagContext {
|
|
|
/**
|
|
|
* @param {object|TagContext|RefsContext} initArgs
|
|
|
*/
|
|
|
- constructor(initArgs) {
|
|
|
+ constructor(initArgs, fromPagePath) {
|
|
|
super(initArgs);
|
|
|
|
|
|
- this.fromPagePath = null;
|
|
|
+ this.fromPagePath = fromPagePath;
|
|
|
|
|
|
// initialized after parse()
|
|
|
- this.isParsed = null;
|
|
|
this.pagePath = null;
|
|
|
+ this.isParsed = null;
|
|
|
this.options = {};
|
|
|
}
|
|
|
|
|
|
@@ -28,32 +28,62 @@ export default class RefsContext extends TagContext {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const parsedResult = ArgsParser.parse(this.args);
|
|
|
- this.options = parsedResult.options;
|
|
|
-
|
|
|
- // determine specifiedPath
|
|
|
- // order:
|
|
|
- // 1: refs(prefix=..., ...)
|
|
|
- // 2: refs(firstArgs, ...)
|
|
|
- // 3: fromPagePath
|
|
|
- const specifiedPath = this.options.prefix
|
|
|
- || ((parsedResult.firstArgsValue === true) ? parsedResult.firstArgsKey : undefined)
|
|
|
- || this.fromPagePath;
|
|
|
-
|
|
|
- // resolve pagePath
|
|
|
- // when `fromPagePath`=/hoge and `specifiedPath`=./fuga,
|
|
|
- // `pagePath` to be /hoge/fuga
|
|
|
- // when `fromPagePath`=/hoge and `specifiedPath`=/fuga,
|
|
|
- // `pagePath` to be /fuga
|
|
|
- // when `fromPagePath`=/hoge and `specifiedPath`=undefined,
|
|
|
- // `pagePath` to be /hoge
|
|
|
- this.pagePath = (specifiedPath !== undefined)
|
|
|
- ? decodeURIComponent(url.resolve(pathUtils.addTrailingSlash(this.fromPagePath), specifiedPath))
|
|
|
- : this.fromPagePath;
|
|
|
+ const parsedArgs = ArgsParser.parse(this.args);
|
|
|
+ this.options = parsedArgs.options;
|
|
|
+
|
|
|
+ if (this.method.match(/^(ref|refimg)$/)) {
|
|
|
+ this.parseForSingle(parsedArgs);
|
|
|
+ }
|
|
|
+ else if (this.method.match(/^(refs|refsimg)$/)) {
|
|
|
+ this.parseForMulti(parsedArgs);
|
|
|
+ }
|
|
|
|
|
|
this.isParsed = true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * parse method for 'ref' and 'refimg'
|
|
|
+ */
|
|
|
+ parseForSingle(parsedArgs) {
|
|
|
+ this.pagePath = this.resolvePath(this.options.page || this.fromPagePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * parse method for 'refs' and 'refsimg'
|
|
|
+ */
|
|
|
+ parseForMulti(parsedArgs) {
|
|
|
+ console.log(parsedArgs);
|
|
|
+ if (this.options.prefix) {
|
|
|
+ this.prefix = this.resolvePath(this.options.prefix);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // determine pagePath
|
|
|
+ // order:
|
|
|
+ // 1: ref(page=..., ...)
|
|
|
+ // 2: refs(firstArgs, ...)
|
|
|
+ // 3: constructor argument
|
|
|
+ const specifiedPath = this.options.page
|
|
|
+ || ((parsedArgs.firstArgsValue === true) ? parsedArgs.firstArgsKey : undefined)
|
|
|
+ || this.fromPagePath;
|
|
|
+
|
|
|
+ this.pagePath = (specifiedPath !== undefined)
|
|
|
+ ? decodeURIComponent(url.resolve(pathUtils.addTrailingSlash(this.fromPagePath), specifiedPath))
|
|
|
+ : this.fromPagePath;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // resolve pagePath
|
|
|
+ // when `fromPagePath`=/hoge and `specifiedPath`=./fuga,
|
|
|
+ // `pagePath` to be /hoge/fuga
|
|
|
+ // when `fromPagePath`=/hoge and `specifiedPath`=/fuga,
|
|
|
+ // `pagePath` to be /fuga
|
|
|
+ // when `fromPagePath`=/hoge and `specifiedPath`=undefined,
|
|
|
+ // `pagePath` to be /hoge
|
|
|
+ resolvePath(pagePath) {
|
|
|
+ return decodeURIComponent(url.resolve(pathUtils.addTrailingSlash(this.fromPagePath), pagePath));
|
|
|
+ }
|
|
|
+
|
|
|
getOptDepth() {
|
|
|
if (this.options.depth === undefined) {
|
|
|
return undefined;
|