Allow values from microdata and form elements and host properties to be combined together (interpolated).
Example 1:
<form>
<div itemscope>
<meta itemprop=protocol content=https>
<meta itemprop=domain content=docs.joshatz.com>
<meta itemprop=articleType content=cheatsheets>
<!-- <meta itemprop=language content=js> -->
<input id=language value=js>
<!-- <meta itemprop=topic content=classes> -->
<input name=topic value=classes>
<meta itemprop=section content=basic-improved---prototype-definition>
<a -href="{$protocol}://{$domain}/{@articleType}/{#language}/{#language}-{@topic}/#{$section}" be-joined
>Basic, Improved - Prototype Definition</a>
</div>
</form>
results in:
<a href=https://docs.joshuatz.com/cheatsheets/js/js-classes/#basic-improved---prototype-definition>Basic, Improved - Prototype Definition</a>
Note
From a performance point of view, this enhancement works best with dynamic (client-side) content that derives from a template (for example, for a repeating web component) as opposed to server-rendered content. To work effectively with server-rendered content, see be-itemized, which (may, tbd) use be-joined behind the scenes.
As we've seen above, we will encounter special symbols used in order to keep the statements small. A summary of those symbols is shown below
Symbol | Meaning | Notes |
---|---|---|
/propName | "Hostish" | Pulls in values from the "host". |
@propName | Name attribute | Pulls in values from form elements using name attribute. |
$propName | Itemprop attribute | Pulls in values from microdata elements with itemprop attribute. |
#propName | Id attribute | Pulls in values from elements identified ia the id. |
-prop-name | Marker indicates prop | Pulls in values from nearest "upsearch" element matching the attribute. |
"Hostish" means:
- First, do a "closest" for an element with attribute itemscope, where the tag name has a dash in it. Do that search recursively.
- If no match found, use getRootNode().host.
To be HTML5 compliant, use data-derive-*-from instead:
<form>
<div itemscope>
<meta itemprop=protocol content=https>
<meta itemprop=domain content=docs.joshatz.com>
<meta itemprop=articleType content=cheatsheets>
<!-- <meta itemprop=language content=js> -->
<input id=language value=js>
<!-- <meta itemprop=topic content=classes> -->
<input name=topic value=classes>
<meta itemprop=section content=basic-improved---prototype-definition>
<a data-derive-href-from="{$protocol}://{$domain}/{@articleType}/{#language}/{#language}-{@topic}/#{$section}" be-joined
>Basic, Improved - Prototype Definition</a>
</div>
</form>
<div itemscope>
<link itemprop="isVegetarian" href="https://schema.org/True">
<input -disabled=$isVegetarian be-joined>
</div>
<my-custom-element>
#shadow
<a -href="{protocol}://{domain}/{articleType}/{language}/{language}-{topic}/#{section}" be-joined
>Basic, Improved - Prototype Definition</a>
</my-custom-element>
In this example, when no symbols are provided (or slash is used), we assume the property values should come from the host (ish)
Any web server that can serve static files will do, but...
- Install git.
- Fork/clone this repo.
- Install node.js.
- Open command window to folder where you cloned this repo.
-
npm install
-
npm run serve
- Open http://localhost:3030/demo/ in a modern browser.
> npm run test
import 'be-joined/be-joined.js';
<script type=module crossorigin=anonymous>
import 'https://esm.run/be-joined';
</script>