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

@b-flower/bdn-ref

v0.2.3

Published

References manager for b-eden env

Downloads

12

Readme

bdn-ref

reference manager client/server with task loading

use mongoose, Marionette, grunt

client architecture is based on backbonerails

Short structure

Loading refs

grunt task defined loadref

Client side

use Marionette Application

Server side

use express node server with mongoose backend

Usage

Loading Ref in MongoDB

module.exports = function (grunt) {
  'use strict';

  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  grunt.loadNpmTasks('jab-ref');

  grunt.initConfig({
  , loadref: {
      options: {
        mongoose_db: 'mongodb://localhost/jab_ref_test'
      }
    , conf: {
        src: ['config/ref.conf.js']
      }
    }
  });

  grunt.registerTask('test', ['loadref']);
 };

Server

var express = require('express');
var app = express();
var mongoose = require('mongoose');
var config = require('../config/config.js');
var path = require('path');

mongoose.connect(config.db);

var db = mongoose.connection;

db.on('error', console.error.bind(console, 'mongoose connection error:'));
db.once('open', console.log.bind(console, 'mongoose connection done'));

app.use(express.logger());

app.use(app.router);

app.use(express.static( path.join(__dirname, '..', 'public') ));
app.use(express.errorHandler());

app.listen(config.port, function() {
  console.log('Running on http://localhost:'+config.port.toString());
});

var ref_ctrl = require('../controllers/ref')(mongoose);

// use your own routes
app.get('/ref/timestamp',   ref_ctrl.timestamp);
app.get('/ref',             ref_ctrl.used);

Client

using browserify

First step - initialize Marionette App & load Ref entities

require('./bower_components/jquery');
global.underscore = global._ = require('lodash');

//lodash need manual global registration (or maybe browserify shim ??)
global._ = global.underscore = require('lodash');
//backbone need manual global registration
global.Backbone = require('./bower_components/backbone/backbone.js');

//marionette needs manual global registration
global.Marionette = require('marionette');

var store = global.store = require('./bower_components/store2/dist/store2.js');

var App = global.JabberApp = new Backbone.Marionette.Application();

// see package.json browser key
var ref = require('jab-ref')(App, 'ref', store);

Second step - init Ref entities

  App.on('initialize:after', function() {
    App.vent.once('ref:entities:synced', function(refs) {
      this.startHistory();
      if (!this.getCurrentRoute()) {
        this.navigate(this.rootRoute, {trigger: true});
      }
    });
    // ref call - make ajax call or load from localStorage
    App.execute('ref:entities:init');
  });

Second step - init Ref entities with Deferred

easier to maintain more than one storage (eg: one for Ref, one, i18n, ...)

  function initRefs() {
    var q = new $.Deferred();
    App.addInitializer( function(options) {
      App.vent.once('ref:entities:synced', function(refs) {
        q.resolve(true);
      });

      App.vent.once('ref:entities:error', function() {
        q.reject();
      });

      App.execute('ref:entities:init');
    });

    return q.promise();
  }

  function initI18n() {
    var q = new $.Deferred();
    ...
    return q.promise();
  }

  var refs = initRefs(); // promise obj
  var i18n = initI18n(); // promise obj
  App.on('initialize:after', function() {
    $.when(refs , i18n).done(function() {
      this.startHistory();
      if (!this.getCurrentRoute()) {
        this.navigate(this.rootRoute, {trigger: true});
      }
    });

    // if refs only you can do
    // $.when(ref).done(...);

  });

File structure

  • assets
    • entities
      • ref.js : file loaded in client browser application
    • test.js : used to build bundle for karma test (should maybe done in test folder directly)
    • bower_components : list of bower components needed for making tests working (see test.js & bower.json)
  • config
    • config.js : default config for http server & mongodb conf
    • karma.conf.js : karma config
    • ref.conf.js : sample data for testing grunt load ref task
  • controllers:
    • ref.js : express controller for loading refs in browser
  • models
    • ref.js: mongoose model for ref collection serialization server side
  • public
    • bundle
      • bundle.js : created by browserify grunt task - used for karma test
  • tasks
    • load-ref-conf.js: grunt task for loading js file in mongodb ref collection
  • test

Other info

For loading jab-ref in the browser, the module expect use of browserify in conbination of package.json browser key.

var ref = require('jab-ref');

See package.json gist and browserify doc for more info.

In package.json file browser key allows this cool stuff:

"browser": "./assets/entities/ref.js"

License

(The MIT License)

Copyright (c) 2009-2012 A. Mélon <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.