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

elem

v0.0.60

Published

An asset manager based on custom elements

Downloads

27

Readme

Elem

An tiny and easy to use web framework based on making custom HTML elements.

Creating Custom Elements

An elem is just a folder who's name is the tag name.

ui
  widget
    widget.js
    widget.html.jade
    widget.css.styl
    hello.txt
  window
    jquery.js
  • Files with extensions like widget.html.jade are caught by the pre-processor and become widget.html.

  • When a <widget> appears on the page elem/loader will pull down all of the files in the widget folder.

  • If there is a widget.html the element's inner html will be replaced with it.

  • If there is a widget.css the css will be added to the document.

  • If there is a widget.js it will be treated like a node module. Here we can export a function that applies the behavior. This function is called for every instance of <widget> and passed an object containing all of the file contents of the folder.

widget.js:

module.exports = function widget() {
  $(this).find('.hello').text('hello');
}

Giving the function two arguments makes it async, delaying rendering and loading child elements:

module.exports = function widget(done) {
  var self = this;

  $.get('/content.txt', function(text) {
    $(self).text(text);
    done();
  });
}

Special Folders

  • */lib is recursively pre-loaded before the element is applied. Put anything you want to require() in here so it is available when the element implementation.

  • */components are parsed as installed components and can be required globally.

  • */window is recursively pre-loaded but executed without a module.exports.

    This is where you would put classic global libraries like jQuery.

    You could also component install component/jquery and require('jquery'). But jQuery was always designed to extend window. Using it as a module breaks plugins.

    Everything in window is run in top-down order of directory depth. So to make jQuery plugins run after jQuery, you can put them in a window/jquery-plugins/ folder.

Express/Connect Middleware

var express = require('express');
var elem = require('elem');
var server = express();
var app = elem(__dirname+'/app');

var production = process.env.NODE_ENV == 'production';

server.use('/app', ui.loader({production: production}));

// Remove this route and include
// <script src="/app/loader.js">
// in a template if you don't want to use the bootloader.
app.get('*', ui.boot('/app'));

app.listen(3000);

Package Management

Elem has has built-in supports for component.

$ npm install -g component
$ component install visionmedia/page.js

body.js

var page = require('page');

You can use libraries from bower or npm if you need to by symlinking:

bower install jquery
ln -s bower_components/jquery/dist/jquery.js frontend/window/

Client-side templating

widget
  widget.js
  template.js.jade

widget.js

var template = require('template');

module.exports = function(render) {
  var locals = {};
  render( template(locals) );
}

Client-side routing

component install page
body.html
hello.js

body.html

<hello></hello>

hello.html

<h1>Hi!</h1>
<img src="reallybigimage.jpg">

hello.js

var page = require('page');

module.exports = function(files, render) {
  // hello.html will not be injected
  // until the route is matched
  page('/hello', render);
}

Page Layouts

... can be deleted. Try making a dynamic <body> element instead.

- app
  - frontend
    - body
      - body.html.jade
      - body.css.styl
    - header
      - header.html.jade
      - header.css.styl
      - header.js
    - page
      - page.css.styl
      - page.js
    - window
      - jquery.js

Pre-processor

The pre-processor keys off of sequential file extensions. e.g. any template.html.jade will envoke the .html.jade pre-processor and result in a static template.html build that is exposed to the element.

The standard pre-processors elem supports are:

  • .html.jade
  • .css.styl
  • .css.less

To add additional pre-processors, or override the built-in ones:

frontend.prep('.html.md', function(str, done){
  marked(str, done);
});

Note that if you override a built-in pre-processor, it will only apply to your own elements. Not installed ones.

By supporting these standard pre-processors element authors are able to use their templating language of choice without incuring a setup penalty. Since they are just pre-processors so there is no overhead.

If you think there is a pre-processor that should be standard make a pull request. The only requirement is that it be a well-known standard format.

No Headaches

Elem is built with the premise that your development and debugging workflow can never be impeded by the build process. In development mode, it actually enhances your workflow making it clear what code is responsible for what is happening on the page.

Development Mode:

  1. All files are requested independently.
  2. File names and line numbers are preserved.
  3. CSS is linked to the page, not injected.
  4. The final DOM is annotated with HTML comments that indicate how and where the markup was generated.
  5. Files are rebuilt on request, and only when they have changed.

elem(1)

elem(1) is provided as a convenience for developing isolated elements. It is not meant to be a real web server.

$ npm install -g elem
Usage: elem [options] <file ...>

Commands:

  index [options]        build index

Options:

  -h, --help     output usage information
  -V, --version  output the version number
elem create widget
elem run widget

License

MIT

Build Status