Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Feb 15, 2024
1 parent 8b48587 commit 0944b51
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 83 deletions.
2 changes: 1 addition & 1 deletion dist/document.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export declare class Document extends Element {
id: string;
root: string;
title: string;
file: string;
filename: string;
section_id?: number;
snippets?: {};
parser?: {
Expand Down
8 changes: 4 additions & 4 deletions dist/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export class Document extends Element {
constructor(el) {
super(el);
this.id = "";
this.file = "module.md";
this.filename = "module.md";
this.root = el.root;
this.title = el.title;
this.parser = el.parser;
this.file = el.file;
if (this.file === undefined) {
this.file = "module.md";
this.filename = el.file;
if (this.filename === undefined) {
this.filename = "module.md";
}
this.id = el.id ? el.id : uuidv4();
this.nodes = el.nodes;
Expand Down
2 changes: 1 addition & 1 deletion dist/element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Node } from "./node";
export declare class Element implements Node {
atom: string;
type: string;
file?: string;
filename?: string;
nodes: Node[];
attributes: {};
constructor(el: any);
Expand Down
2 changes: 1 addition & 1 deletion dist/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class Element {
this.attributes = {};
this.atom = el.atom;
this.type = el.type;
this.file = el.file;
this.filename = el.file;
this.nodes = el.nodes ? el.nodes : [];
this.attributes = el.attributes ? el.attributes : {};
if (this.attributes === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion dist/empty_mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function EmptyModule() {
mod.id = "";
mod.doc.id = "";
mod.dir = "";
mod.file = "empty.md";
mod.filepath = "empty.md";
mod.name = "empty.md";
return mod;
}
49 changes: 28 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Element {
this.attributes = {};
this.atom = el.atom;
this.type = el.type;
this.file = el.file;
this.filename = el.file;
this.nodes = el.nodes ? el.nodes : [];
this.attributes = el.attributes ? el.attributes : {};
if (this.attributes === undefined) {
Expand Down Expand Up @@ -100,13 +100,13 @@ class Document extends Element {
constructor(el) {
super(el);
this.id = "";
this.file = "module.md";
this.filename = "module.md";
this.root = el.root;
this.title = el.title;
this.parser = el.parser;
this.file = el.file;
if (this.file === undefined) {
this.file = "module.md";
this.filename = el.file;
if (this.filename === undefined) {
this.filename = "module.md";
}
this.id = el.id ? el.id : v4();
this.nodes = el.nodes;
Expand Down Expand Up @@ -804,28 +804,35 @@ function newElement(n) {
}

class Module {
constructor(mod, parser) {
constructor(doc, parser) {
this.id = "";
this.file = "";
this.filepath = "";
this.dir = ""; // calculated from file
this.name = ""; // calculated from file
this.id = v4();
if (mod.id) {
this.id = mod.id;
this.parser = new Parser();
if (doc.id === undefined) {
doc.id = v4();
}
if (mod.file === undefined) {
mod.file = "module.md";
this.id = doc.id;
if (doc.root === undefined) {
doc.root = "";
}
if (mod.root === undefined) {
mod.root = "";
if (doc.filename === undefined) {
doc.filename = "module.md";
}
this.file = path.join(mod.root, mod.file);
this.dir = mod.root;
this.name = path.basename(mod.file);
this.parser = parser ? parser : new Parser();
this.doc = this.parser.parse(mod.doc ? mod.doc : mod);
this.filepath = path.join(doc.root, doc.filename);
this.dir = doc.root;
this.name = doc.filename;
this.doc = this.parser.parse(doc);
this.toc = new Toc();
this.toc.perform(this.doc);
// this.file = path.join(doc.root, doc.file);
// this.dir = doc.root
// this.name = path.basename(doc.file)
// this.parser = parser ? parser : new Parser();
// this.doc = this.parser.parse(doc.doc ? doc.doc : doc);
// this.toc = new Toc();
// this.toc.perform(this.doc);
}
title() {
if (this.doc === undefined) {
Expand Down Expand Up @@ -853,7 +860,7 @@ function EmptyModule() {
mod.id = "";
mod.doc.id = "";
mod.dir = "";
mod.file = "empty.md";
mod.filepath = "empty.md";
mod.name = "empty.md";
return mod;
}
Expand All @@ -864,7 +871,7 @@ class Modules {
this.mods = {};
}
add(mod) {
this.mods[mod.file] = mod;
this.mods[mod.filepath] = mod;
this.current = mod;
return this.list();
}
Expand Down
4 changes: 2 additions & 2 deletions dist/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Toc } from "./toc";
import { Parser } from "./parser";
export declare class Module {
id: string;
file: string;
filepath: string;
dir: string;
name: string;
parser: Parser;
doc: Document;
toc: Toc;
constructor(mod: any, parser?: Parser);
constructor(doc: any, parser?: Parser);
title(): string;
toString(): string;
}
35 changes: 21 additions & 14 deletions dist/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ import { v4 as uuid } from "uuid";
import path from "path-browserify";
import { Parser } from "./parser";
export class Module {
constructor(mod, parser) {
constructor(doc, parser) {
this.id = "";
this.file = "";
this.filepath = "";
this.dir = ""; // calculated from file
this.name = ""; // calculated from file
this.id = uuid();
if (mod.id) {
this.id = mod.id;
this.parser = new Parser();
if (doc.id === undefined) {
doc.id = uuid();
}
if (mod.file === undefined) {
mod.file = "module.md";
this.id = doc.id;
if (doc.root === undefined) {
doc.root = "";
}
if (mod.root === undefined) {
mod.root = "";
if (doc.filename === undefined) {
doc.filename = "module.md";
}
this.file = path.join(mod.root, mod.file);
this.dir = mod.root;
this.name = path.basename(mod.file);
this.parser = parser ? parser : new Parser();
this.doc = this.parser.parse(mod.doc ? mod.doc : mod);
this.filepath = path.join(doc.root, doc.filename);
this.dir = doc.root;
this.name = doc.filename;
this.doc = this.parser.parse(doc);
this.toc = new Toc();
this.toc.perform(this.doc);
// this.file = path.join(doc.root, doc.file);
// this.dir = doc.root
// this.name = path.basename(doc.file)
// this.parser = parser ? parser : new Parser();
// this.doc = this.parser.parse(doc.doc ? doc.doc : doc);
// this.toc = new Toc();
// this.toc.perform(this.doc);
}
title() {
if (this.doc === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion dist/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class Modules {
this.mods = {};
}
add(mod) {
this.mods[mod.file] = mod;
this.mods[mod.filepath] = mod;
this.current = mod;
return this.list();
}
Expand Down
2 changes: 1 addition & 1 deletion dist/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface Node {
atom: string;
nodes: Node[];
type: string;
file?: string;
filename?: string;
toString(): string;
toHtml(): string;
}
Expand Down
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ interface Node {
atom: string;
nodes: Node[];
type: string;
file?: string;
filename?: string;
toString(): string;
toHtml(): string;
}

declare class Element implements Node {
atom: string;
type: string;
file?: string;
filename?: string;
nodes: Node[];
attributes: {};
constructor(el: any);
Expand Down Expand Up @@ -42,7 +42,7 @@ declare class Document extends Element {
id: string;
root: string;
title: string;
file: string;
filename: string;
section_id?: number;
snippets?: {};
parser?: {
Expand Down Expand Up @@ -71,13 +71,13 @@ declare class Parser {

declare class Module {
id: string;
file: string;
filepath: string;
dir: string;
name: string;
parser: Parser;
doc: Document;
toc: Toc;
constructor(mod: any, parser?: Parser);
constructor(doc: any, parser?: Parser);
title(): string;
toString(): string;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gopherguides/hypejs",
"version": "0.2.1",
"version": "0.2.2",
"author": "Gopher Guides <[email protected]>",
"description": "kA TypeScript/JavaScript client for Hype JSON",
"license": "CC-BY-NC-SA-4.0",
Expand Down
8 changes: 4 additions & 4 deletions src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class Document extends Element {
id: string = "";
root: string;
title: string;
file: string = "module.md"
filename: string = "module.md"

section_id?: number;
snippets?: {};
Expand All @@ -21,10 +21,10 @@ export class Document extends Element {
this.root = el.root;
this.title = el.title;
this.parser = el.parser;
this.file = el.file;
this.filename = el.file;

if (this.file === undefined) {
this.file = "module.md"
if (this.filename === undefined) {
this.filename = "module.md"
}

this.id = el.id ? el.id : uuidv4();
Expand Down
4 changes: 2 additions & 2 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { gotypes } from "./gotypes";
export class Element implements Node {
atom: string
type: string;
file?: string;
filename?: string;
nodes: Node[];
attributes: {} = {}

constructor(el: any) {
this.atom = el.atom;
this.type = el.type;
this.file = el.file;
this.filename = el.file;
this.nodes = el.nodes ? el.nodes : [];
this.attributes = el.attributes ? el.attributes : {};

Expand Down
2 changes: 1 addition & 1 deletion src/empty_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function EmptyModule(): Module {
mod.id = "";
mod.doc.id = "";
mod.dir = "";
mod.file = "empty.md";
mod.filepath = "empty.md";
mod.name = "empty.md";

return mod;
Expand Down
3 changes: 3 additions & 0 deletions src/module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import exp from "constants";
import path from "path-browserify"
import { Document } from "./document"
import { Module } from "./module"
import { Toc } from "./toc"
Expand All @@ -14,6 +15,8 @@ describe('module', () => {
expect(mod.id).toBeDefined();
expect(mod.name).toEqual("module.md");
expect(mod.title()).toEqual("Context");
expect(mod.dir).toEqual(data.root);
expect(mod.filepath).toEqual(path.join(data.root, data.filename));

let doc: Document = mod.doc;
expect(doc).toBeDefined();
Expand Down
Loading

0 comments on commit 0944b51

Please sign in to comment.