clapton 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -7
  3. data/lib/clapton/javascripts/dist/client.js +12 -4
  4. data/lib/clapton/javascripts/dist/components-for-test.js +49 -45
  5. data/lib/clapton/javascripts/dist/components.js +49 -45
  6. data/lib/clapton/javascripts/src/channel/clapton-channel.js +1 -1
  7. data/lib/clapton/javascripts/src/client.ts +9 -2
  8. data/lib/clapton/javascripts/src/components/block-quote.spec.ts +6 -6
  9. data/lib/clapton/javascripts/src/components/block-quote.ts +2 -2
  10. data/lib/clapton/javascripts/src/components/bold.spec.ts +3 -3
  11. data/lib/clapton/javascripts/src/components/bold.ts +2 -2
  12. data/lib/clapton/javascripts/src/components/box.spec.ts +6 -6
  13. data/lib/clapton/javascripts/src/components/box.ts +2 -2
  14. data/lib/clapton/javascripts/src/components/button.spec.ts +5 -5
  15. data/lib/clapton/javascripts/src/components/button.ts +2 -2
  16. data/lib/clapton/javascripts/src/components/checkbox.spec.ts +3 -3
  17. data/lib/clapton/javascripts/src/components/checkbox.ts +1 -1
  18. data/lib/clapton/javascripts/src/components/code.spec.ts +6 -6
  19. data/lib/clapton/javascripts/src/components/code.ts +2 -2
  20. data/lib/clapton/javascripts/src/components/component.ts +8 -4
  21. data/lib/clapton/javascripts/src/components/datetime-field.spec.ts +3 -3
  22. data/lib/clapton/javascripts/src/components/datetime-field.ts +1 -1
  23. data/lib/clapton/javascripts/src/components/element.spec.ts +6 -6
  24. data/lib/clapton/javascripts/src/components/element.ts +2 -2
  25. data/lib/clapton/javascripts/src/components/embed.spec.ts +1 -1
  26. data/lib/clapton/javascripts/src/components/embed.ts +1 -1
  27. data/lib/clapton/javascripts/src/components/emphasis.spec.ts +6 -6
  28. data/lib/clapton/javascripts/src/components/emphasis.ts +2 -2
  29. data/lib/clapton/javascripts/src/components/form.spec.ts +6 -6
  30. data/lib/clapton/javascripts/src/components/form.ts +2 -2
  31. data/lib/clapton/javascripts/src/components/heading.spec.ts +6 -6
  32. data/lib/clapton/javascripts/src/components/heading.ts +2 -2
  33. data/lib/clapton/javascripts/src/components/image.spec.ts +2 -2
  34. data/lib/clapton/javascripts/src/components/image.ts +1 -1
  35. data/lib/clapton/javascripts/src/components/link.spec.ts +6 -6
  36. data/lib/clapton/javascripts/src/components/link.ts +2 -2
  37. data/lib/clapton/javascripts/src/components/list-item.spec.ts +6 -6
  38. data/lib/clapton/javascripts/src/components/list-item.ts +2 -2
  39. data/lib/clapton/javascripts/src/components/list.spec.ts +6 -6
  40. data/lib/clapton/javascripts/src/components/list.ts +2 -2
  41. data/lib/clapton/javascripts/src/components/ordered-list.spec.ts +6 -6
  42. data/lib/clapton/javascripts/src/components/ordered-list.ts +2 -2
  43. data/lib/clapton/javascripts/src/components/paragraph.spec.ts +6 -6
  44. data/lib/clapton/javascripts/src/components/paragraph.ts +2 -2
  45. data/lib/clapton/javascripts/src/components/presets.ts +1 -1
  46. data/lib/clapton/javascripts/src/components/quote.spec.ts +6 -6
  47. data/lib/clapton/javascripts/src/components/quote.ts +2 -2
  48. data/lib/clapton/javascripts/src/components/radio-button.spec.ts +3 -3
  49. data/lib/clapton/javascripts/src/components/radio-button.ts +1 -1
  50. data/lib/clapton/javascripts/src/components/select.spec.ts +6 -6
  51. data/lib/clapton/javascripts/src/components/select.ts +2 -2
  52. data/lib/clapton/javascripts/src/components/span.spec.ts +6 -6
  53. data/lib/clapton/javascripts/src/components/span.ts +2 -2
  54. data/lib/clapton/javascripts/src/components/text-area.spec.ts +3 -3
  55. data/lib/clapton/javascripts/src/components/text-area.ts +1 -1
  56. data/lib/clapton/javascripts/src/components/text-field.spec.ts +3 -3
  57. data/lib/clapton/javascripts/src/components/text-field.ts +1 -1
  58. data/lib/clapton/javascripts/src/components/text.spec.ts +2 -2
  59. data/lib/clapton/javascripts/src/components/text.ts +1 -1
  60. data/lib/clapton/javascripts/src/dom/update-component.ts +1 -1
  61. data/lib/clapton/test_helper/base.rb +1 -1
  62. data/lib/clapton/version.rb +1 -1
  63. data/lib/rails/generators/clapton_generator.rb +2 -0
  64. metadata +1 -1
@@ -21,13 +21,20 @@ const initializeComponents = async () => {
21
21
  };
22
22
 
23
23
  const createAndAppendComponent = async (component: ComponentDefinition, element: HTMLElement) => {
24
+ if (!element) {
25
+ return;
26
+ }
24
27
  const componentDom = document.createElement('div');
25
28
  const module = await import(`${component.component}`);
26
29
  const instance = new (module[component.component] as any)(component.state);
27
- componentDom.innerHTML = instance.render;
30
+ componentDom.innerHTML = instance.renderWrapper;
28
31
  const firstChild = componentDom.firstChild as HTMLElement;
29
32
  if (firstChild) {
30
- element.appendChild(firstChild);
33
+ if (element.children.length > 0) {
34
+ element.appendChild(firstChild);
35
+ } else {
36
+ element.outerHTML = firstChild.outerHTML;
37
+ }
31
38
  }
32
39
  };
33
40
 
@@ -4,23 +4,23 @@ import { Text } from "./text"
4
4
 
5
5
  describe("BlockQuote", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new BlockQuote().render).toBe("<blockquote ></blockquote>")
7
+ expect(new BlockQuote().renderWrapper).toBe("<blockquote ></blockquote>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new BlockQuote({ id: "1", "data-foo": "bar" }).render).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
11
+ expect(new BlockQuote({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new BlockQuote({ id: "1", data: { foo: "bar" } }).render).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
16
- expect(new BlockQuote({ id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<blockquote id='1' data-foo='bar' data-baz='qux'></blockquote>`)
17
- expect(new BlockQuote({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<blockquote id='1' data-foo-baz='qux' data-foo-quux='corge'></blockquote>`)
15
+ expect(new BlockQuote({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
16
+ expect(new BlockQuote({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar' data-baz='qux'></blockquote>`)
17
+ expect(new BlockQuote({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<blockquote id='1' data-foo-baz='qux' data-foo-quux='corge'></blockquote>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
21
  const text = new Text("Hello")
22
22
  const blockQuote = new BlockQuote()
23
23
  blockQuote.add(text)
24
- expect(blockQuote.render).toBe(`<blockquote >Hello</blockquote>`)
24
+ expect(blockQuote.renderWrapper).toBe(`<blockquote >Hello</blockquote>`)
25
25
  })
26
26
  })
@@ -9,8 +9,8 @@ export class BlockQuote {
9
9
  this.attributes = attributes;
10
10
  }
11
11
 
12
- get render(): string {
13
- return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</blockquote>`;
12
+ get renderWrapper(): string {
13
+ return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
14
14
  }
15
15
 
16
16
  add(child: any): BlockQuote {
@@ -4,11 +4,11 @@ import { Bold } from "./bold"
4
4
 
5
5
  describe("Bold", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Bold().render).toBe("<strong ></strong>")
7
+ expect(new Bold().renderWrapper).toBe("<strong ></strong>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Bold({ id: "1", "data-foo": "bar" }).render).toBe(`<strong id='1' data-foo='bar'></strong>`)
11
+ expect(new Bold({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<strong id='1' data-foo='bar'></strong>`)
12
12
  })
13
13
 
14
14
 
@@ -16,6 +16,6 @@ describe("Bold", () => {
16
16
  const text = new Text("Hello")
17
17
  const bold = new Bold()
18
18
  bold.add(text)
19
- expect(bold.render).toBe(`<strong >Hello</strong>`)
19
+ expect(bold.renderWrapper).toBe(`<strong >Hello</strong>`)
20
20
  })
21
21
  })
@@ -9,8 +9,8 @@ export class Bold {
9
9
  this.attributes = attributes;
10
10
  }
11
11
 
12
- get render(): string {
13
- return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</strong>`;
12
+ get renderWrapper(): string {
13
+ return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</strong>`;
14
14
  }
15
15
 
16
16
  add(child: any): Bold {
@@ -4,20 +4,20 @@ import { Text } from "./text"
4
4
 
5
5
  describe("Box", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Box().render).toBe("<div ></div>")
7
+ expect(new Box().renderWrapper).toBe("<div ></div>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Box({ id: "1", "data-foo": "bar" }).render).toBe(`<div id='1' data-foo='bar'></div>`)
11
+ expect(new Box({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Box({ id: "1", data: { foo: "bar" } }).render).toBe(`<div id='1' data-foo='bar'></div>`)
16
- expect(new Box({ id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<div id='1' data-foo='bar' data-baz='qux'></div>`)
17
- expect(new Box({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<div id='1' data-foo-baz='qux' data-foo-quux='corge'></div>`)
15
+ expect(new Box({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
16
+ expect(new Box({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<div id='1' data-foo='bar' data-baz='qux'></div>`)
17
+ expect(new Box({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<div id='1' data-foo-baz='qux' data-foo-quux='corge'></div>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
- expect(new Box().add(new Text("Hello, world!")).render).toBe(`<div >Hello, world!</div>`)
21
+ expect(new Box().add(new Text("Hello, world!")).renderWrapper).toBe(`<div >Hello, world!</div>`)
22
22
  })
23
23
  })
@@ -14,8 +14,8 @@ export class Box {
14
14
  return this;
15
15
  }
16
16
 
17
- get render(): string {
18
- return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</div>`;
17
+ get renderWrapper(): string {
18
+ return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
19
19
  }
20
20
 
21
21
  add_action(eventType: string, stateName: string, fnName: string, options: Record<string, any> = {}): this {
@@ -3,16 +3,16 @@ import { Button } from "./button"
3
3
 
4
4
  describe("Button", () => {
5
5
  it("returns empty string if no params", () => {
6
- expect(new Button().render).toBe("<button ></button>")
6
+ expect(new Button().renderWrapper).toBe("<button ></button>")
7
7
  })
8
8
 
9
9
  it("returns attributes and data attributes", () => {
10
- expect(new Button({ id: "1", "data-foo": "bar" }).render).toBe(`<button id='1' data-foo='bar'></button>`)
10
+ expect(new Button({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<button id='1' data-foo='bar'></button>`)
11
11
  })
12
12
 
13
13
  it("returns attributes and data attributes with custom data attributes", () => {
14
- expect(new Button({ id: "1", data: { foo: "bar" } }).render).toBe(`<button id='1' data-foo='bar'></button>`)
15
- expect(new Button({ id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<button id='1' data-foo='bar' data-baz='qux'></button>`)
16
- expect(new Button({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<button id='1' data-foo-baz='qux' data-foo-quux='corge'></button>`)
14
+ expect(new Button({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<button id='1' data-foo='bar'></button>`)
15
+ expect(new Button({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<button id='1' data-foo='bar' data-baz='qux'></button>`)
16
+ expect(new Button({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<button id='1' data-foo-baz='qux' data-foo-quux='corge'></button>`)
17
17
  })
18
18
  })
@@ -14,8 +14,8 @@ export class Button {
14
14
  return this;
15
15
  }
16
16
 
17
- get render(): string {
18
- return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</button>`;
17
+ get renderWrapper(): string {
18
+ return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</button>`;
19
19
  }
20
20
 
21
21
  add_action(event: string, klass: string, fn: string, options: Record<string, any> = {}): Button {
@@ -3,14 +3,14 @@ import { Checkbox } from "./checkbox"
3
3
 
4
4
  describe("Checkbox", () => {
5
5
  it("returns empty string if no params", () => {
6
- expect(new Checkbox({}, "foo").render).toBe("<input type='checkbox' data-attribute='foo' value=''/>")
6
+ expect(new Checkbox({}, "foo").renderWrapper).toBe("<input type='checkbox' data-attribute='foo' value=''/>")
7
7
  })
8
8
 
9
9
  it("returns attributes and data attributes", () => {
10
- expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", "data-foo": "bar" }).render).toBe(`<input type='checkbox' id='1' data-foo='bar' data-attribute='foo' value='bar'/>`)
10
+ expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<input type='checkbox' id='1' data-foo='bar' data-attribute='foo' value='bar'/>`)
11
11
  })
12
12
 
13
13
  it("returns attributes and data attributes with custom data attributes", () => {
14
- expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<input type='checkbox' id='1' data-attribute='foo' data-foo-baz='qux' data-foo-quux='corge' value='bar'/>`)
14
+ expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<input type='checkbox' id='1' data-attribute='foo' data-foo-baz='qux' data-foo-quux='corge' value='bar'/>`)
15
15
  })
16
16
  })
@@ -12,7 +12,7 @@ export class Checkbox {
12
12
  this.attributes["data-attribute"] = attribute;
13
13
  }
14
14
 
15
- get render(): string {
15
+ get renderWrapper(): string {
16
16
  return `<input type='checkbox' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
17
17
  }
18
18
 
@@ -4,23 +4,23 @@ import { Text } from "./text"
4
4
 
5
5
  describe("Code", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Code().render).toBe("<code ></code>")
7
+ expect(new Code().renderWrapper).toBe("<code ></code>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Code({ id: "1", "data-foo": "bar" }).render).toBe(`<code id='1' data-foo='bar'></code>`)
11
+ expect(new Code({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<code id='1' data-foo='bar'></code>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Code({ id: "1", data: { foo: "bar" } }).render).toBe(`<code id='1' data-foo='bar'></code>`)
16
- expect(new Code({ id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<code id='1' data-foo='bar' data-baz='qux'></code>`)
17
- expect(new Code({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<code id='1' data-foo-baz='qux' data-foo-quux='corge'></code>`)
15
+ expect(new Code({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<code id='1' data-foo='bar'></code>`)
16
+ expect(new Code({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<code id='1' data-foo='bar' data-baz='qux'></code>`)
17
+ expect(new Code({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<code id='1' data-foo-baz='qux' data-foo-quux='corge'></code>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
21
  const text = new Text("Hello")
22
22
  const code = new Code()
23
23
  code.add(text)
24
- expect(code.render).toBe(`<code >Hello</code>`)
24
+ expect(code.renderWrapper).toBe(`<code >Hello</code>`)
25
25
  })
26
26
  })
@@ -9,8 +9,8 @@ export class Code {
9
9
  this.attributes = attributes;
10
10
  }
11
11
 
12
- get render(): string {
13
- return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</code>`;
12
+ get renderWrapper(): string {
13
+ return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</code>`;
14
14
  }
15
15
 
16
16
  add(child: any): Code {
@@ -5,18 +5,22 @@ export class Component {
5
5
  id: string;
6
6
  _state: any;
7
7
  _errors: any[];
8
- _root: Box;
9
8
  _c: Presets;
10
9
 
11
10
  constructor(state: any = {}, id: string = Math.random().toString(36).substring(2, 10), errors: any[] = []) {
12
11
  this._state = state;
13
12
  this.id = id;
14
13
  this._errors = errors;
15
- this._root = new Box({ data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } });
16
14
  this._c = new Presets()
17
15
  }
18
16
 
19
- get render(): string {
20
- return this._root.render;
17
+ get render(): any {
18
+ return new Box({});
19
+ }
20
+
21
+ get renderWrapper(): string {
22
+ const root = this.render;
23
+ root.attributes = { ...root.attributes, data: { ...root.attributes.data, component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } };
24
+ return root.renderWrapper;
21
25
  }
22
26
  }
@@ -3,14 +3,14 @@ import { DateTimeField } from "./datetime-field"
3
3
 
4
4
  describe("DateTimeField", () => {
5
5
  it("returns empty string if no params", () => {
6
- expect(new DateTimeField({}, "foo").render).toBe("<input type='datetime-local' data-attribute='foo' value=''/>")
6
+ expect(new DateTimeField({}, "foo").renderWrapper).toBe("<input type='datetime-local' data-attribute='foo' value=''/>")
7
7
  })
8
8
 
9
9
  it("returns attributes and data attributes", () => {
10
- expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", "data-foo": "bar" }).render).toMatch(/<input type='datetime-local' id='1' data-foo='bar' data-attribute='foo' value='.+'\/>/)
10
+ expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", "data-foo": "bar" }).renderWrapper).toMatch(/<input type='datetime-local' id='1' data-foo='bar' data-attribute='foo' value='.+'\/>/)
11
11
  })
12
12
 
13
13
  it("returns attributes and data attributes with custom data attributes", () => {
14
- expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toMatch(/<input type='datetime-local' id='1' data-attribute='foo' data-foo-baz='qux' data-foo-quux='corge' value='.+'\/>/)
14
+ expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toMatch(/<input type='datetime-local' id='1' data-attribute='foo' data-foo-baz='qux' data-foo-quux='corge' value='.+'\/>/)
15
15
  })
16
16
  })
@@ -12,7 +12,7 @@ export class DateTimeField {
12
12
  this.attributes["data-attribute"] = attribute;
13
13
  }
14
14
 
15
- get render(): string {
15
+ get renderWrapper(): string {
16
16
  const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
17
17
  return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
18
18
  }
@@ -5,23 +5,23 @@ import { Text } from "./text"
5
5
 
6
6
  describe("Element", () => {
7
7
  it("returns empty string if no params", () => {
8
- expect(new Element("blockquote").render).toBe("<blockquote ></blockquote>")
8
+ expect(new Element("blockquote").renderWrapper).toBe("<blockquote ></blockquote>")
9
9
  })
10
10
 
11
11
  it("returns attributes and data attributes", () => {
12
- expect(new Element("blockquote", { id: "1", "data-foo": "bar" }).render).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
12
+ expect(new Element("blockquote", { id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
13
13
  })
14
14
 
15
15
  it("returns attributes and data attributes with custom data attributes", () => {
16
- expect(new Element("blockquote", { id: "1", data: { foo: "bar" } }).render).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
17
- expect(new Element("blockquote", { id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<blockquote id='1' data-foo='bar' data-baz='qux'></blockquote>`)
18
- expect(new Element("blockquote", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<blockquote id='1' data-foo-baz='qux' data-foo-quux='corge'></blockquote>`)
16
+ expect(new Element("blockquote", { id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
17
+ expect(new Element("blockquote", { id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar' data-baz='qux'></blockquote>`)
18
+ expect(new Element("blockquote", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<blockquote id='1' data-foo-baz='qux' data-foo-quux='corge'></blockquote>`)
19
19
  })
20
20
 
21
21
  it("adds children", () => {
22
22
  const text = new Text("Hello")
23
23
  const blockQuote = new Element("blockquote")
24
24
  blockQuote.add(text)
25
- expect(blockQuote.render).toBe(`<blockquote >Hello</blockquote>`)
25
+ expect(blockQuote.renderWrapper).toBe(`<blockquote >Hello</blockquote>`)
26
26
  })
27
27
  })
@@ -11,8 +11,8 @@ export class Element {
11
11
  this.attributes = attributes;
12
12
  }
13
13
 
14
- get render(): string {
15
- return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</${this.type}>`;
14
+ get renderWrapper(): string {
15
+ return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</${this.type}>`;
16
16
  }
17
17
 
18
18
  add(child: any): Element {
@@ -3,6 +3,6 @@ import { Embed } from "./embed"
3
3
 
4
4
  describe("Embed", () => {
5
5
  it("returns empty string if no params", () => {
6
- expect(new Embed("<blockquote></blockquote>").render).toBe("<blockquote></blockquote>")
6
+ expect(new Embed("<blockquote></blockquote>").renderWrapper).toBe("<blockquote></blockquote>")
7
7
  })
8
8
  })
@@ -5,7 +5,7 @@ export class Embed {
5
5
  this.html = html;
6
6
  }
7
7
 
8
- get render(): string {
8
+ get renderWrapper(): string {
9
9
  return this.html;
10
10
  }
11
11
  }
@@ -4,23 +4,23 @@ import { Text } from "./text"
4
4
 
5
5
  describe("Emphasis", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Emphasis().render).toBe("<em ></em>")
7
+ expect(new Emphasis().renderWrapper).toBe("<em ></em>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Emphasis({ id: "1", "data-foo": "bar" }).render).toBe(`<em id='1' data-foo='bar'></em>`)
11
+ expect(new Emphasis({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<em id='1' data-foo='bar'></em>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Emphasis({ id: "1", data: { foo: "bar" } }).render).toBe(`<em id='1' data-foo='bar'></em>`)
16
- expect(new Emphasis({ id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<em id='1' data-foo='bar' data-baz='qux'></em>`)
17
- expect(new Emphasis({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<em id='1' data-foo-baz='qux' data-foo-quux='corge'></em>`)
15
+ expect(new Emphasis({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<em id='1' data-foo='bar'></em>`)
16
+ expect(new Emphasis({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<em id='1' data-foo='bar' data-baz='qux'></em>`)
17
+ expect(new Emphasis({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<em id='1' data-foo-baz='qux' data-foo-quux='corge'></em>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
21
  const text = new Text("Hello")
22
22
  const emphasis = new Emphasis()
23
23
  emphasis.add(text)
24
- expect(emphasis.render).toBe(`<em >Hello</em>`)
24
+ expect(emphasis.renderWrapper).toBe(`<em >Hello</em>`)
25
25
  })
26
26
  })
@@ -9,8 +9,8 @@ export class Emphasis {
9
9
  this.attributes = attributes;
10
10
  }
11
11
 
12
- get render(): string {
13
- return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</em>`;
12
+ get renderWrapper(): string {
13
+ return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</em>`;
14
14
  }
15
15
 
16
16
  add(child: any): Emphasis {
@@ -4,23 +4,23 @@ import { Text } from "./text"
4
4
 
5
5
  describe("Form", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Form().render).toBe("<form ></form>")
7
+ expect(new Form().renderWrapper).toBe("<form ></form>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Form({ id: "1", "data-foo": "bar" }).render).toBe(`<form id='1' data-foo='bar'></form>`)
11
+ expect(new Form({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<form id='1' data-foo='bar'></form>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Form({ id: "1", data: { foo: "bar" } }).render).toBe(`<form id='1' data-foo='bar'></form>`)
16
- expect(new Form({ id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<form id='1' data-foo='bar' data-baz='qux'></form>`)
17
- expect(new Form({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<form id='1' data-foo-baz='qux' data-foo-quux='corge'></form>`)
15
+ expect(new Form({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<form id='1' data-foo='bar'></form>`)
16
+ expect(new Form({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<form id='1' data-foo='bar' data-baz='qux'></form>`)
17
+ expect(new Form({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<form id='1' data-foo-baz='qux' data-foo-quux='corge'></form>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
21
  const text = new Text("Hello")
22
22
  const form = new Form()
23
23
  form.add(text)
24
- expect(form.render).toBe(`<form >Hello</form>`)
24
+ expect(form.renderWrapper).toBe(`<form >Hello</form>`)
25
25
  })
26
26
  })
@@ -9,8 +9,8 @@ export class Form {
9
9
  this.attributes = attributes;
10
10
  }
11
11
 
12
- get render(): string {
13
- return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</form>`;
12
+ get renderWrapper(): string {
13
+ return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</form>`;
14
14
  }
15
15
 
16
16
  add(child: any): Form {
@@ -4,20 +4,20 @@ import { Text } from "./text"
4
4
 
5
5
  describe("Heading", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Heading(1).render).toBe("<h1 ></h1>")
7
+ expect(new Heading(1).renderWrapper).toBe("<h1 ></h1>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Heading(1, { id: "1", "data-foo": "bar" }).render).toBe(`<h1 id='1' data-foo='bar'></h1>`)
11
+ expect(new Heading(1, { id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<h1 id='1' data-foo='bar'></h1>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Heading(1, { id: "1", data: { foo: "bar" } }).render).toBe(`<h1 id='1' data-foo='bar'></h1>`)
16
- expect(new Heading(1, { id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<h1 id='1' data-foo='bar' data-baz='qux'></h1>`)
17
- expect(new Heading(1, { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<h1 id='1' data-foo-baz='qux' data-foo-quux='corge'></h1>`)
15
+ expect(new Heading(1, { id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<h1 id='1' data-foo='bar'></h1>`)
16
+ expect(new Heading(1, { id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<h1 id='1' data-foo='bar' data-baz='qux'></h1>`)
17
+ expect(new Heading(1, { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<h1 id='1' data-foo-baz='qux' data-foo-quux='corge'></h1>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
- expect(new Heading(1).add(new Text("Hello")).render).toBe(`<h1 >Hello</h1>`)
21
+ expect(new Heading(1).add(new Text("Hello")).renderWrapper).toBe(`<h1 >Hello</h1>`)
22
22
  })
23
23
  })
@@ -10,8 +10,8 @@ export class Heading {
10
10
  this.attributes = attributes;
11
11
  }
12
12
 
13
- get render(): string {
14
- return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</h${this.level}>`;
13
+ get renderWrapper(): string {
14
+ return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</h${this.level}>`;
15
15
  }
16
16
 
17
17
  add(child: any): Heading {
@@ -3,10 +3,10 @@ import { Image } from "./image"
3
3
 
4
4
  describe("Image", () => {
5
5
  it("returns empty string if no params", () => {
6
- expect(new Image("https://example.com/image.png", "").render).toBe("<img src='https://example.com/image.png' alt='' />")
6
+ expect(new Image("https://example.com/image.png", "").renderWrapper).toBe("<img src='https://example.com/image.png' alt='' />")
7
7
  })
8
8
 
9
9
  it("returns attributes and data attributes", () => {
10
- expect(new Image("https://example.com/image.png", "test", { id: "1", "data-foo": "bar" }).render).toBe(`<img src='https://example.com/image.png' alt='test' id='1' data-foo='bar'/>`)
10
+ expect(new Image("https://example.com/image.png", "test", { id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<img src='https://example.com/image.png' alt='test' id='1' data-foo='bar'/>`)
11
11
  })
12
12
  })
@@ -13,7 +13,7 @@ export class Image {
13
13
  this.alt = alt;
14
14
  }
15
15
 
16
- get render(): string {
16
+ get renderWrapper(): string {
17
17
  return `<img src='${this.src}' alt='${this.alt}' ${htmlAttributes(this.attributes)}/>`;
18
18
  }
19
19
  }
@@ -4,20 +4,20 @@ import { Text } from "./text"
4
4
 
5
5
  describe("Link", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Link("").render).toBe("<a href='' ></a>")
7
+ expect(new Link("").renderWrapper).toBe("<a href='' ></a>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Link("#").add(new Text("")).render).toBe(`<a href='#' ></a>`)
11
+ expect(new Link("#").add(new Text("")).renderWrapper).toBe(`<a href='#' ></a>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Link("#", { id: "1", data: { foo: "bar" } }).render).toBe(`<a href='#' id='1' data-foo='bar'></a>`)
16
- expect(new Link("#", { id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<a href='#' id='1' data-foo='bar' data-baz='qux'></a>`)
17
- expect(new Link("#", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<a href='#' id='1' data-foo-baz='qux' data-foo-quux='corge'></a>`)
15
+ expect(new Link("#", { id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<a href='#' id='1' data-foo='bar'></a>`)
16
+ expect(new Link("#", { id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<a href='#' id='1' data-foo='bar' data-baz='qux'></a>`)
17
+ expect(new Link("#", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<a href='#' id='1' data-foo-baz='qux' data-foo-quux='corge'></a>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
- expect(new Link("#").add(new Text("Hello")).render).toBe(`<a href='#' >Hello</a>`)
21
+ expect(new Link("#").add(new Text("Hello")).renderWrapper).toBe(`<a href='#' >Hello</a>`)
22
22
  })
23
23
  })
@@ -10,8 +10,8 @@ export class Link {
10
10
  this.href = href;
11
11
  }
12
12
 
13
- get render(): string {
14
- return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</a>`;
13
+ get renderWrapper(): string {
14
+ return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</a>`;
15
15
  }
16
16
 
17
17
  add(child: any): Link {
@@ -4,21 +4,21 @@ import { Text } from "./text"
4
4
 
5
5
  describe("ListItem", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new ListItem().render).toBe("<li ></li>")
7
+ expect(new ListItem().renderWrapper).toBe("<li ></li>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new ListItem({ id: "1", "data-foo": "bar" }).render).toBe(`<li id='1' data-foo='bar'></li>`)
11
+ expect(new ListItem({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<li id='1' data-foo='bar'></li>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new ListItem({ id: "1", data: { foo: "bar" } }).render).toBe(`<li id='1' data-foo='bar'></li>`)
16
- expect(new ListItem({ id: "1", data: { foo: "bar", baz: "qux" } }).render).toBe(`<li id='1' data-foo='bar' data-baz='qux'></li>`)
17
- expect(new ListItem({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).render).toBe(`<li id='1' data-foo-baz='qux' data-foo-quux='corge'></li>`)
15
+ expect(new ListItem({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<li id='1' data-foo='bar'></li>`)
16
+ expect(new ListItem({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<li id='1' data-foo='bar' data-baz='qux'></li>`)
17
+ expect(new ListItem({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<li id='1' data-foo-baz='qux' data-foo-quux='corge'></li>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
21
  const text = new Text("Hello, world!")
22
- expect(new ListItem().add(text).render).toBe(`<li >Hello, world!</li>`)
22
+ expect(new ListItem().add(text).renderWrapper).toBe(`<li >Hello, world!</li>`)
23
23
  })
24
24
  })
@@ -14,7 +14,7 @@ export class ListItem {
14
14
  return this;
15
15
  }
16
16
 
17
- get render(): string {
18
- return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</li>`;
17
+ get renderWrapper(): string {
18
+ return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</li>`;
19
19
  }
20
20
  }