Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Fix some bugs with folder fullpath
Browse files Browse the repository at this point in the history
  • Loading branch information
jhm-ciberman committed Aug 14, 2019
1 parent 105c549 commit fccdb66
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/doc_models/DocFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default class DocFolder extends DocResource {
* Returns the fullpath of the resource
*/
get fullpath(): string {
if (this.project && this.project.root === this) {
return "";
}
return this.parent ? this.parent.fullpath + this.name + "/" : this.name + "/";
}

Expand Down
23 changes: 14 additions & 9 deletions src/renderer/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@ export default class Renderer implements IRenderer {
const compiler = new NunjucksCompiler(template.folder);

outputFolder = path.resolve(outputFolder);
this._reporter.info(`Output folder: ${outputFolder}`);
this._reporter.info(`Rendering documentation to output folder: ${outputFolder}`);

for (const page of queue.pages) {
const filename = page.getFilename();
this._reporter.info(`Rendering ${filename}`);

const linkResolver = new LinkResolver(queue, page);
compiler.addGlobal("linkTo", (resource: DocResource) => linkResolver.linkTo(resource));
compiler.addGlobal("asset", (assetName: string) => linkResolver.asset(assetName));
try {
const linkResolver = new LinkResolver(queue, page);
compiler.addGlobal("linkTo", (resource: DocResource) => linkResolver.linkTo(resource));
compiler.addGlobal("asset", (assetName: string) => linkResolver.asset(assetName));

const templatePath = template.getTemplatePathFor(page.type);
const html = compiler.render(templatePath, page.getContext());
const templatePath = template.getTemplatePathFor(page.type);
const html = compiler.render(templatePath, page.getContext());

const fullPath = path.resolve(outputFolder, filename);
await fse.outputFile(fullPath, html);
} catch (e) {
this._reporter.error(`Error rendering ${filename}`);
throw e;
}

const fullPath = path.resolve(outputFolder, filename);
await fse.outputFile(fullPath, html);
}
}
}
13 changes: 6 additions & 7 deletions tests/unit/config/ConfigManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { TYPES } from "../../../src/types";

/* tslint:disable:max-classes-per-file completed-docs */

@TestFixture("GMScript")
@TestFixture()
export class GMS1ProjectFactoryFixture {

public input: TempDir;
Expand All @@ -45,29 +45,28 @@ export class GMS1ProjectFactoryFixture {
TempDir.removeAll();
}

@Test("exportConfig")
@Test()
public async exportConfig() {
await this.configManager.exportConfig(this.output.dir);
Expect(this.output.exists("docs_gm.json")).toBe(true);
}

@Test("exportConfig from dir")
@Test()
public async loadConfig_fromDir() {
const conf = await this.configManager.loadConfig(this.input.dir);
Expect(conf).toBeDefined();
Expect((conf as IProjectConfig).output.template).toBe("my_template_foo");
}

@Test("exportConfig from json")
@Test()
public async loadConfig_fromJson() {
const conf = await this.configManager.loadConfig(this.input.join("datafiles/docs_gm.json"));
Expect(conf).toBeDefined();
Expect((conf as IProjectConfig).output.template).toBe("my_template_foo");
}

@Test("exportConfig invalid json")
@Test()
public async loadConfig_invalid() {
const conf = await this.configManager.loadConfig(this.input.join("invalid.json"));
Expect(conf).not.toBeDefined();
Expect(() => this.configManager.loadConfig(this.input.join("invalid.json"))).toThrowAsync();
}
}
2 changes: 1 addition & 1 deletion tests/unit/renderer/LinkResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ export class LinkResolverFixture {

@Test()
public asset() {
Expect(this._linkResolver.asset("css/my_css.css")).toBe("../css/my_css.css");
Expect(this._linkResolver.asset("css/my_css.css")).toBe("css/my_css.css");
}
}
2 changes: 1 addition & 1 deletion tests/unit/renderer/Renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class RendererFixture {

await this._getRenderer().render(template, queue, this.outputFolder.dir);

const htmlScript = this.outputFolder.read("my_folder/my_script.html");
const htmlScript = this.outputFolder.read("my_script.html");
Expect(htmlScript).toContain("my_script");
Expect(htmlScript).toContain("my project");

Expand Down

0 comments on commit fccdb66

Please sign in to comment.