0.0.3 • Published 2 years ago

be-restated v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

be-restated

be-restated is one of a trio of element decorators / behaviors that takes advantage of the buried treasure that is XSLT, built into the browser.

The differences are summarized in the table below.

Bottom line, be-restated focuses on the following problem statements:

  1. Extracting the data from server-rendered HTML, in partnership with obj-xml.
  2. Providing derived content from other content. For example, generating a table of contents based on the contents of the page.

Syntax

<table-of-contents be-restated='{
    "from": "main",
    "xslt": "toc.xslt"
}'>
</table-of-contents>
...
<main>
    <h1>Heading 1</h1>
    <section>
        <h2>Heading 2</h2>
    </section>
    <section>...</section>
    <template be-a-beacon></template>
</main>

What this does:

  1. If be-restated can't locate main, it attaches an event handler to the host or document.body, listening for the event be-a-beacon emits: "i-am-here". Every time such an event occurs, searches the host's Shadow DOM, or document.body for element "main".
  2. Once element "main" is found, moves the beacon event listener to the main element.
  3. If the templatebe-a-beacon element is found, xslt is performed with the content of the main element, and the table-of-contents light children are populated from the result.
  4. If the event handler on the main element picks up "i-am-here" messages going forward, it re-does step 3.