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

ractive-load

v0.7.0

Published

Component loader plugin for Ractive.js

Downloads

230

Readme

Ractive.js load plugin

Find more Ractive.js plugins at docs.ractivejs.org/latest/plugins

The ractive-load plugin allows you to load Ractive components from HTML files that contain all their markup, CSS and JavaScript. See here for an introduction to components and component files, or visit the demo page.

Installation

This plugin works as an AMD module, as a CommonJS module, or as a regular script (it will be exposed as Ractive.load).

Include ractive-load.js on your page below Ractive, e.g:

<script src='lib/ractive.js'></script>
<script src='lib/ractive-load.js'></script>

To get ractive-load.min.js you can:

Usage

To load a component, along with any sub-components it depends on:

Ractive.load( 'my-components/foo.html' ).then( function ( FooComponent ) {
  var ractive = new FooComponent({
    el: 'body',
    data: { ... }
  });
}).catch( handleError );

If all your components are located in a single folder, you can set the baseUrl property and the plugin will look for them there:

Ractive.load.baseUrl = 'my-components/';
Ractive.load( 'foo.html' ).then( function ( FooComponent ) {
  // use component
}).catch( handleError );

You can load multiple components simultaneously, like so:

Ractive.load({
  Foo: 'my-components/foo.html',
  Bar: 'my-components/bar.html'
}).then( function ( components ) {
  var foo = new components.Foo({
    el: 'body',
    data: { ... }
  });

  var bar = new components.Bar({
    el: 'body',
    data: { ... }
  });
}).catch( handleError );

Defining module dependencies

Ideally, components should not care what environment they're being used in - an AMD app, node.js, or a standard browser environment without module loaders.

So if a component has external dependencies, there's a standard way to use them. Suppose you have some app config that sits outside your component:

<p>foo: {{config.foo}}</p>

<script>
  var config = require( 'config' );
  component.exports = {
    data: { config: config }
  };
</script>

Here, we're importing the app config with require('config'). If this component was being used in an AMD app, or if it was being transformed by browserify, it would defer to the AMD or browserify implementation of require.

But outside of AMD, browserify and node, require doesn't mean anything. So, inside a component, ractive-load provides a specialised require function. Using our config example, require will first look for Ractive.load.modules.config, then for window.config (if we're in a browser), and then will fall back to using an existing require implementation (e.g. if we're in node.js).

In other words, this is the easiest way to make config available to a component:

Ractive.load.modules.config = myConfig;

Using ractive-load in node.js

Many components will work in node.js environments without any changes. This allows you to render HTML from components using the same templates and data as you use on the client.

Install it in the usual way:

$ npm i ractive-load

Then, in your app, use it in the normal way:

var load = require( 'ractive-load' );
load( 'my-components/foo.html' ).then( function ( FooComponent ) {
  var ractive = new FooComponent({
    data: { ... }
  });

  // generate some HTML so that we can save it, or serve to a client
  var renderedHTML = ractive.toHTML();
}).catch( handleError );

License

Licensed MIT.

Created with the Ractive.js plugin template for Grunt.