npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@titsoft/dry-html

v0.5.0

Published

DRY html

Downloads

320

Readme

dry-html

dry-html script use the template element

  • avoiding to copy and paste identical portion of HTML,
  • changing in one place (the template) any HTML modifications.

see also layout-m for creating flows of template instances.

Example

<!-- declare a template  with a dashed id and placeholders (t-*) -->
// class attribute is transfered to the custom-element
<template id="group-two" class="a-class">
    <label>{t-field}</label>
    <input type="{t-type}" />
</template>
<!--
write the template instance elements
 - based on template id (group-two)
 - with placeholders as attributes (t-field and t-type)
 - with template class attribute if no class is defined
 -->
 <form>
    <group-two
      t-field="Name"
      t-type="text"
    ></group-two>
    <!-- another-class replaces a-class -->
    <group-two
      class="another-class" 
      t-field="Birthday"
      t-type="datetime-local">
    </group-two>
</form>

Rules

  • template id must have at least one dash with no leading dash,
  • template placeholders t-* can be
    • either any elements attributes (except events),
    • or elements content,
  • template attributes or content must contain solely the placeholder
    • <span>${t-label}</span>
    • ❌ : <span>before${t-label}after</span>
  • template placeholders must be placed inside HTML elements (attributes or content) not outside
    • ❌: <template>{t-outside}<span>{t-inside}</span></template>
  • template instance should be written with respect to HTML standard with closing tags
    • <my-element></my-element>
    • ❌: <my-element />
  • template instance elements have a display:block style,

Installation

Either place a script tag in your HTML file like this (corresponding to src/auto.js)

  <script src="dry-html.js"></script>

This script will detect, once DOMContentLoaded triggered, the dashed-ids templates and do the job with no additional Javascript code.

Or via npm i @titsoft/dry-html with the following exports

import { defineCustomElements, defineCustomElement, getAttributes } from '@titsoft/dry-html'

defineCustomElements() // defines custom-elements for all templates based on their id
defineCustomElement(id) // defines a custom-element for one template id
getAttributes(id) // gives all placeholders/attributes for one template id

Tests

To get the technical scope, see

  • test/auto/index.html
  • test/module/index.html