Permalink
Switch branches/tags
components dev greenkeeper-babel-register-6.11.5 greenkeeper-babel-register-6.11.6 greenkeeper-babel-register-6.14.0 greenkeeper-bluebird-3.4.7 greenkeeper-bluebird-3.5.0 greenkeeper-body-parser-1.15.1 greenkeeper-bookshelf-0.9.3 greenkeeper-bookshelf-0.9.4 greenkeeper-bookshelf-0.9.5 greenkeeper-chai-3.5.0 greenkeeper-chai-4.0.0 greenkeeper-chalk-1.1.2 greenkeeper-chalk-1.1.3 greenkeeper-compression-1.6.2 greenkeeper-connect-assets-5.1.1 greenkeeper-connect-assets-5.2.0 greenkeeper-connect-assets-5.2.1 greenkeeper-connect-mongo-1.2.0 greenkeeper-cookie-parser-1.4.2 greenkeeper-cookie-parser-1.4.3 greenkeeper-express-redis-cache-0.5.1 greenkeeper-express-validator-2.20.3 greenkeeper-express-validator-2.20.4 greenkeeper-express-validator-2.20.5 greenkeeper-github-api-1.0.0 greenkeeper-github-api-1.1.0 greenkeeper-github-api-1.2.0 greenkeeper-github-api-1.2.1 greenkeeper-github-api-1.3.0 greenkeeper-github-api-2.0.0 greenkeeper-github-api-2.1.0 greenkeeper-github-api-2.2.0 greenkeeper-github-api-2.3.0 greenkeeper-github-api-2.4.0 greenkeeper-gulp-image-resize-0.7.2 greenkeeper-gulp-image-resize-0.8.0 greenkeeper-gulp-imagemin-3.0.0 greenkeeper-gulp-imagemin-3.0.1 greenkeeper-husky-0.11.4 greenkeeper-knex-0.11.0 greenkeeper-knex-0.11.1 greenkeeper-knex-0.11.2 greenkeeper-knex-0.11.3 greenkeeper-knex-0.11.4 greenkeeper-knex-0.11.5 greenkeeper-knex-0.12.3 greenkeeper-knex-0.12.4 greenkeeper-knex-0.12.5 greenkeeper-knex-0.12.6 greenkeeper-knex-0.12.7 greenkeeper-knex-0.12.8 greenkeeper-knex-0.12.9 greenkeeper-knex-0.13.0 greenkeeper-lodash-4.16.0 greenkeeper-lodash-4.16.1 greenkeeper-lodash-4.16.2 greenkeeper-lodash-4.16.3 greenkeeper-lodash-4.16.4 greenkeeper-lodash-4.16.5 greenkeeper-lodash-4.16.6 greenkeeper-lodash-4.17.0 greenkeeper-lodash-4.17.1 greenkeeper-lodash-4.17.2 greenkeeper-lodash-4.17.3 greenkeeper-lodash-4.17.4 greenkeeper-lusca-1.4.0 greenkeeper-lusca-1.4.1 greenkeeper-mailgun-js-0.7.8 greenkeeper-mailgun-js-0.7.9 greenkeeper-mailgun-js-0.7.10 greenkeeper-mailgun-js-0.7.11 greenkeeper-mailgun-js-0.7.12 greenkeeper-mailgun-js-0.7.13 greenkeeper-markdown-it-8.0.1 greenkeeper-markdown-it-8.1.0 greenkeeper-markdown-it-8.2.0 greenkeeper-markdown-it-8.2.1 greenkeeper-markdown-it-8.3.0 greenkeeper-method-override-2.3.6 greenkeeper-mocha-2.5.0 greenkeeper-mocha-2.5.1 greenkeeper-mocha-2.5.2 greenkeeper-mocha-2.5.3 greenkeeper-mocha-3.0.0 greenkeeper-mocha-3.0.2 greenkeeper-mocha-3.1.0 greenkeeper-mocha-3.1.1 greenkeeper-mocha-3.2.0 greenkeeper-mocha-3.3.0 greenkeeper-mocha-3.4.0 greenkeeper-mocha-3.4.1 greenkeeper-mocha-3.4.2 greenkeeper-moment-2.15.1 greenkeeper-moment-2.15.2 greenkeeper-moment-2.16.0 greenkeeper-moment-2.17.0 greenkeeper-moment-2.17.1 greenkeeper-moment-2.18.0 greenkeeper-moment-2.18.1 greenkeeper-mongoose-4.4.8 greenkeeper-mongoose-4.4.9 greenkeeper-mongoose-4.4.10 greenkeeper-mongoose-4.4.11 greenkeeper-mongoose-4.4.12 greenkeeper-mongoose-4.4.13 greenkeeper-mongoose-4.4.14 greenkeeper-mongoose-4.4.15 greenkeeper-mongoose-4.4.16 greenkeeper-mongoose-4.4.17 greenkeeper-mongoose-4.4.18 greenkeeper-mongoose-4.4.19 greenkeeper-mysql-2.12.0 greenkeeper-mysql-2.13.0 greenkeeper-redis-2.5.2 greenkeeper-redis-2.5.3 greenkeeper-rss-1.2.2 greenkeeper-sqlite3-3.1.5 greenkeeper-sqlite3-3.1.6 greenkeeper-sqlite3-3.1.7 greenkeeper-sqlite3-3.1.8 greenkeeper-superagent-2.3.0 greenkeeper-supertest-2.0.0 greenkeeper-supertest-2.0.1 greenkeeper-supertest-3.0.0 greenkeeper-twitter-1.3.0 greenkeeper-twitter-1.4.0 greenkeeper-twitter-1.5.0 greenkeeper-twitter-1.6.0 greenkeeper-twitter-1.7.0 greenkeeper-type-is-1.6.14 greenkeeper-type-is-1.6.15 greenkeeper-uglify-js-2.6.3 greenkeeper-uglify-js-2.6.4 greenkeeper-uglify-js-2.7.0 greenkeeper-uglify-js-2.7.1 greenkeeper-uglify-js-2.7.2 greenkeeper-uglify-js-2.7.3 greenkeeper-update-all greenkeeper-validator-5.2.0 greenkeeper-validator-5.3.0 greenkeeper-widget-cms-0.3.7 greenkeeper-widget-cms-0.3.8 greenkeeper-widget-cms-1.0.0 greenkeeper-widget-cms-1.0.1 greenkeeper-widget-cms-1.1.0 greenkeeper-widget-cms-1.1.1 greenkeeper-widget-cms-1.2.1 greenkeeper-widget-cms-1.2.2 greenkeeper-widget-cms-1.2.3 greenkeeper-widget-cms-1.3.0 greenkeeper-widget-cms-1.3.1 greenkeeper-widget-cms-1.3.2 greenkeeper-widget-knex-schema-1.0.3 greenkeeper-widget-knex-schema-1.0.4 greenkeeper-widget-knex-schema-1.0.5 greenkeeper-winston-2.3.0 greenkeeper-winston-daily-rotate-file-1.4.0 greenkeeper-winston-daily-rotate-file-1.4.1 greenkeeper-winston-daily-rotate-file-1.4.2 greenkeeper/initial handlebars master meetups redesign routing
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
85 lines (67 sloc) 2.51 KB

Widgets

A widget is a special kind of module. It is self contained and is completely decoupled from other parts of the application.

A widget comprises of 3 files, config.json, index.js, and template.hbs.

config.json contains the configuration.

index.js is the main program file.

template.hbs contains the handlebars template.

config.json

Config.json contains basic configuration and meta-data for the widget. You can turn the object on and off through the active property. The pages property is an array of paths telling the widget which pages it should be displayed on.

{
  "name": "name-of-widget",
  "title": "ui-title",
  "version": "0.0.1",
  "routes": [
    "/view",
    "/view/:any",
    "/view/subview/:any"
  ],
  "description": "widget description",
  "author": "Name of author",
  "authorEmail": "author email",
  "position": "ui-position",
  "order": Number,
  "active": Boolean,
  "repo": "repo-url"
}

index.js

This is the main program file. It loads the config file data, adds a method named exec and then exports it. The exec method accepts the main Application object and returns a promise that resolves with the config and collection data as a single object. Use the Application getCollection method to retrieve any particular collection found in the collections directory.

var config = require('./config.json');

/*
 * fetches a collection of data
 *
 * @param: {Object}App - main application object
 * @return: {Promise} - a promise that resolves with an object
**/
config.exec = function (App) {

  var categories = App.getCollection('Categories');

  return categories.fetch({columns: ['slug', 'name']})
  .then(function (collection) {
    config.collection = collection;
    
    return config;
  });
};

module.exports = config;

template.hbs

The application view uses handlebars and twitter bootstrap. The widget template has access to the collection fetched by the exec method.

<div class="panel panel-default">
  <div class="panel-heading">
    Categories
  </div>
  <div class="panel-body">
    <ul class="list-unstyled">
      {{#if collection}}
        {{#each collection}}
          <li>
            <a href="/blog/category/{{slug}}">
              {{name}}
            </a>
          </li>
        {{/each}}
      {{/if}}
    </ul>
  </div>
</div>