Skip to content

Commit

Permalink
add object generators as separate subsection; work on geneontology/am…
Browse files Browse the repository at this point in the history
  • Loading branch information
kltm committed Mar 16, 2016
1 parent bea819f commit 0acaa21
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 1 deletion.
112 changes: 112 additions & 0 deletions lib/generators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

var us = require('underscore');
var bbop = require('bbop-core');

var html = require('./html');

var generators = {};

/*
* Method: clickable_object
*
* Generator for a clickable object.
*
* TODO: May eventually expand it to include making a jQuery button.
*
* Arguments:
* label - *[optional]* the text to use for the span or label (defaults to '')
* source - *[optional]* the URL source of the image (defaults to '')
* id - *[optional]* the id for the object (defaults to generate_id: true)
*
* Returns:
* html.span or html.image
*/
generators.clickable_object = function(label, source, id){
//this._is_a = 'bbop-widget-set.display.clickable_object';
//var anchor = this;
// // Per-UI logger.
// var logger = new bbop.logger();
// logger.DEBUG = true;
// function ll(str){ logger.kvetch('W (clickable_object): ' + str); }

// Default args.
if( ! label ){ label = ''; }
if( ! source ){ source = ''; }

// Decide whether we'll use an incoming id or generate our own.
var args = {};
if( id ){
args['id'] = id;
}else{
args['generate_id'] = true;
}

// Figure out an icon or a label.
var obj = null;
if( source === '' ){
obj = new html.span(label, args);
}else{
args['src'] = source;
args['title'] = label;
obj = new html.image(args);
}

return obj;
};

/*
* Package: text_buttom_sim.js
*
* Namespace: bbop-widget-set.display.text_button_sim
*
* BBOP object to produce a clickable text span, that in conjunction with the local CSS, should make an awfully button looking creature.
*
* It uses the class: "bbop-js-text-button-sim".
*
* Note: this is a method, not a constructor.
*/

/*
* Method: text_button_sim_generator
*
* Generator for a text span for use for buttons.
*
* Arguments:
* label - *[optional]* the text to use for the span or (defaults to 'X')
* title - *[optional]* the hover text (defaults to 'X')
* id - *[optional]* the id for the object (defaults to generate_id: true)
* add_attrs - *[optional]* more attributes to be folded in to the span as hash
*
* Returns:
* html.span
*/
generators.text_button_sim = function(label, title, id, add_attrs){

// Default args.
if( ! label ){ label = 'X'; }
if( ! title ){ title = 'X'; }
if( ! add_attrs ){ add_attrs = {}; }

// Decide whether we'll use an incoming id or generate our own.
var args = {
'class': "bbop-js-text-button-sim",
'title': title
};
if( id ){
args['id'] = id;
}else{
args['generate_id'] = true;
}

// Addtional optional atrributes and overrides.
args = bbop.merge(args, add_attrs);

var obj = new html.span(label, args);
return obj;
};

///
/// Exportable body.
///

module.exports = generators;
6 changes: 5 additions & 1 deletion lib/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ module.exports.set = set;

// html subsection is safe.
module.exports.html = require('./html');
module.exports.generators = require('./generators');

try {
module.exports.autocomplete_simple = require('./autocomplete_simple');
// not so safe subsets
module.exports.display = require('./display');
// actual final widgets
//module.exports.autocomplete_simple = require('./autocomplete_simple');
module.exports.live_filters = require('./live_filters');
module.exports.live_pager = require('./live_pager');
module.exports.live_results = require('./live_results');
Expand Down
33 changes: 33 additions & 0 deletions tests/clickable_object.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
////
//// Some testing for the clickable thingy.
////

var assert = require('chai').assert;

var bbop = require('bbop-core');
var us = require('underscore');
var each = us.each;

var bbop_widgets = require('..');
var generators = bbop_widgets.generators;

///
/// Start testing.
///

describe('generators', function(){

it('part 1', function(){

var i = new generators.clickable_object('foo', 'bar', 'bib');
assert.equal(i.to_string(),
'<img id="bib" src="bar" title="foo" />',
"same image");

var s = new generators.clickable_object('foo', '', 'bib');
assert.equal(s.to_string(),
'<span id="bib">foo</span>',
"same span");

});
});

0 comments on commit 0acaa21

Please sign in to comment.