Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sofware carpentry tags for greg wilson #12

Merged
merged 1 commit into from
Aug 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions custom.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ $([IPython.events]).on('app_initialized.NotebookApp', function(){
// // do stuff
// })

// software carpentry tags example.
/* require(['custom/swc/main'],function(m){
*
* // param1 : Name of the preset in the dropdown selector
* // param2 : namespace to use in metadata
* // param3 : list of tags name to use both in UI in front of checkboxes and in metadata
*
* m.new_tag_set('Software Carpentry Tags', 'swc' ,['instructor','learner','exercise'])
*
* console.log('Sofware carpentry tags extension loaded corectly')
* })
*/


});
37 changes: 37 additions & 0 deletions swc/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
define(function() {
var CellToolbar = IPython.CellToolbar;

// generate a checkbox for <tagname> bound to
// cell.metadata.<namespace>.<tagname>
// and return the key to register for it a a preset.
var tagg = function (namespace, tagname){
var local = CellToolbar.utils.checkbox_ui_generator(tagname,
function(cell, value){
if (cell.metadata[namespace] == undefined){cell.metadata[namespace] = {}}
cell.metadata[namespace][tagname] = value
},
function(cell){ var ns = cell.metadata[namespace];
return (ns == undefined)? undefined: ns[tagname]
}
);
var cname = namespace+'_'+tagname
CellToolbar.register_callback(namespace+'_'+tagname,local);
return cname
}

// generate a preset with name <UIname>
// that register a bunch of tags [<tagsname>,...]s
// bound to cell.metadata.<namespace>.<tagname> = [Bool|unset]
var new_tag_set = function(UIname, namespace, tagsnames){
var taglistname = []
for( var i in tagsnames){
taglistname.push(tagg(namespace, tagsnames[i]))
}
CellToolbar.register_preset(UIname, taglistname)
}

//
//taggl('Software Carpentry Tags', 'swc' ,['instructor','learner','exercise'])
//
return {new_tag_set:new_tag_set}
})