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

reshape-component

v1.0.6

Published

Include components in reshape templates

Downloads

7

Readme

Reshape Component

[See also: reshape-components for a more Web Component style API]

This plugin is based on reshape-include and supports the same functionality. In addition it provides more component-like paramaterized includes by copying attributes and content from the component tag to the template.

For example, in the following use of component:

<component src="components/Card/Card.html" id="card1" class="active"></component>

The id and class attributes will be copied to the first top-level node in the components/Card/Card.html file.

Usage

While this plugin does everything reshape-include does and more, it is recommended for clarity's sake to use reshape-include for simple includes. In case both plugins are in use, this plugin should be loaded after reshape-include.

Using with Spike

Spike uses reshape-standard to configure Reshape. Configuration options for Reshape are passed from app.js, so to add reshape-component to a Spike project:

  1. npm install reshape-component
  2. Require reshape-component in app.js and add it to the config:
// ..
const htmlStandards = require('reshape-standard');
const reshapeComponent = require('reshape-component');

module.exports = {
    // ...
    reshape: htmlStandards({
    // ...
        appendPlugins: [
            reshapeComponent()
        ]
    })
};

Attributes

  • The src and type attributes are used by the reshape-component plugin and will not be copied
  • The class attribute will be appended to any existing class attribute
  • All other attributes will be destructively copied

The type attribute

This attribute provides a convenience for specifying component types by a short name, e.g.:

<component type="Card" id="card1" class="active"></component>

is equivalent to:

<component src="components/Card/Card.html" id="card1" class="active"></component>

The path is configurable in the options passed to the plugin via the componentPath property.

Options

Name | Default | Description ----------------- | ------- | ----------- componentPath | 'components/$type/$type.html' | Specifies the path to use to include components specified by the type attribute. Any occurrences of $type in the path will be replaced with the value of the type attribute. preserveType | false | If true the type attribute will be copied from the component tag to the first top-level node in the template. If a string value is provided it will be used as the name of the target attribute. This can be useful for JavaScript that wants to query the DOM for component nodes.

preserveType example

// configuring reshape-component:
reshapeComponent({ preserveType: 'data-component-type' })
<!-- defining a component template: -->
<div>
	<p>${content}</p>
</div>

<!-- using a component -->
<component type="Card">
	<content>Card One</content>
</component>

<!-- result -->
<div data-component-type="Card">
	<p>Card One</p>
</div>

Token substitution

Tokens can be used as placeholders in a template and will be substituted with content from the component. Tokens can be used for both plain text values and node trees as well.

Card template:

<div class="card" title="${card-name}">
	<h1>${card-title}</h1>
	<div>${card-body}</div>
</div>

Component that uses the template:

<component type="Card" class="active">
	<card-name>Card One</card-name>
	<card-title><span class="title">My Title</span></card-title>
	<card-body>My Body Content</card-body>
</component>

Result:

<div class="card active" title="Card One">
	<h1><span class="title">My Title</span></h1>
	<div>My Body Content</div>
</div>

Default values

Tokens can specify default values with the = character. It works a little differently depending on if the token is in the content of a node or if it is an attribute.

Card template:

<div class="card" title="${card-name}" ${hidden}="true">
	<h1>${card-title=Default title}</h1>
	<div>${card-body}</div>
</div>
  • ${hidden}: since this is an attribute the = character must appear after the token. If <hidden> is not defined in the component then the result will be hidden="true"
  • ${card-title}: the = character must appear inside the token. If <card-title> is not defined in the component then the result will be <h1>Default title</h1>

Notes

  • The default parser converts tag names to lower case, so it is recommended to use token names that are all lower case
  • If node content (as opposed to text content) is specified for a token that is used in an attribute, the result will simply be the string value, e.g. [Object object]