all files / src/ TestTemplate.ts

88.89% Statements 8/9
50% Branches 1/2
66.67% Functions 2/3
88.89% Lines 8/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                              
import {
  TemplateInfo,
  SerializedTemplateInfo,
  TemplateInfoFactory
} from "@opticss/template-api";
 
declare module "@opticss/template-api" {
  export interface TemplateTypes {
    "TestTemplate": TestTemplate;
  }
}
 
export class TestTemplate implements TemplateInfo<"TestTemplate"> {
  type: "TestTemplate";
  identifier: string;
  contents: string;
  plainHtml: boolean;
  constructor(identifier: string, contents: string, plainHtml?: boolean) {
    this.type = "TestTemplate";
    this.identifier = identifier;
    this.contents = contents;
    this.plainHtml = !!plainHtml;
  }
 
  static deserialize(identifier: string, ...data: any[]): TestTemplate {
    return new TestTemplate(identifier, data[0], data[1] === "true");
  }
  serialize(): SerializedTemplateInfo<"TestTemplate"> {
    return {
      type: "TestTemplate",
      identifier: this.identifier,
      data: [
        this.contents,
        this.plainHtml ? "true" : "false"
      ]
    };
  }
}
TemplateInfoFactory.constructors["TestTemplate"] = TestTemplate.deserialize;