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

active-menu

v0.1.2

Published

Facilitates the creation of menus in Node applications.

Downloads

2

Readme

Active Menu

About

Active Menu is a module for NodeJS that facilitates the creation of menus in Node applications, specifically (but not limited to) Express.

Inspired by the CMenu widget for the PHP framework Yii (viewable here) as well as the menu markup from Magento's top menu system.

The menu, when rendered will apply the proper active classes depending on the current route of the application. For example, when the user is on the route /admin/posts, the <a> tag and all parents of that tag (<ul> and <li>) will also be given the active class. This makes applying CSS for menu items which relate to the current route quite simple.

Example

A simple example using Active Menu for a blog's admin panel:

// Require Active Menu
var activeMenu = require('active-menu');
// Create a New Instance
var adminMenu = new activeMenu('adminMenu');
// Set HTML Attributes for the Top <ul> element
adminMenu.setAttributes({class : 'menu', id : 'admin-menu'});

// Home Node
var homeNode = adminMenu.addMenuNode('Home', '/admin');
homeNode.setAttributes({class : 'home home-icon', id : 'home-link'});

// Posts Node and Children
var postsNode = adminMenu.addMenuNode('Posts', '/admin/posts');
postsNode.setAttributes({class : 'posts posts-icon'});

var newPostNode = postsNode.addMenuNode('New Post', '/admin/posts/new');
newPostNode.setAttributes({class : 'new-post new-icon'});

// Settings Node
var settingsNode = adminMenu.addMenuNode('Settings', '/admin/settings');
settingsNode.setAttributes({class : 'settings cog-icon'});

// Use Menu
app.use(adminMenu.menu);

When app.use(...) is called for adminMenu.menu, it adds the menu instance to res.locals which is then accessible through the Jade templating engine. Simple put !=adminMenu in your template and it will render the menu as part of the HTML.

You can also get the HTML for the menu by calling adminMenu.toString().

Result

The above example would produce the following output:

<ul class="menu" id="admin-menu">
    <li class="home home-icon level-0 first" id="home-link">
        <a href="/admin">Home</a>
    </li>
    <li class="posts posts-icon level-0 parent">
        <a href="/admin/posts">Posts</a>
        <ul class="level-1">
            <li class="new-post new-icon level-1 only">
                <a href="/admin/posts/new">New Post</a>
            </li>
        </ul>
    </li>
    <li class="settings cog-icon level-0 last">
        <a href="/admin/settings">Settings</a>
    </li>
</ul>