Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pec1985
Last active December 16, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pec1985/5453955 to your computer and use it in GitHub Desktop.
Save pec1985/5453955 to your computer and use it in GitHub Desktop.
BlackBerry generate setters
// Sample setters
var setters = [
'currentPage'
, 'disableBounce'
, 'overScrollMode'
, 'overlayEnabled'
, 'pagingControlAlpha'
, 'pagingControlColor'
, 'pagingControlHeight'
, 'pagingControlOnTop'
, 'pagingControlTimeout'
, 'scrollingEnabled'
, 'showPagingControl'
];
function createConst(method) {
method = method.replace(/([A-Z])/g, '_$1');
return 'N_PROP_' + method.toUpperCase();
}
function createPROP(method) {
return '{ '+ createConst(method) + ', PROP_SETGET_FUNCTION(' + createSet(method) + '), NULL},';
}
function createSet(method) {
return 'set' + method[0].toUpperCase() + method.slice(1);
}
function createPROP_SETGET(method) {
return 'PROP_SETGET(' + createSet(method) + ')\n'+
'int NativeControlObject::' + createSet(method) + '(TiObject*)\n' +
'{\n' +
'\treturn NATIVE_ERROR_NOTSUPPORTED;\n' +
'}';
}
function createTiBase(method) {
return '{\n' +
'\t"' + method + '", TI_PROP_PERMISSION_READ | TI_PROP_PERMISSION_WRITE | TI_PROP_FLAG_READ_NO_BRIDGE,\n' +
'\t' + createConst(method) + '\n' +
'},';
}
function generateOutput() {
var str = ''
str += '// NativeControlObject.cpp //\n';
for(var i = 0, len = setters.length; i < len; i++) {
str += createPROP_SETGET(setters[i]) + '\n';
}
str += '\n\n';
str += '// NativeControlObject.cpp //\n';
for(var i = 0, len = setters.length; i < len; i++) {
str += createPROP(setters[i]) + '\n';
}
str += '\n\n';
str += '// NativeControlObject.h //\n';
for(var i = 0, len = setters.length; i < len; i++) {
str += 'virtual int ' + createSet(setters[i]) + '(TiObject* obj);\n';
}
str += '\n\n';
str += '// NativeObject.h //\n';
for(var i = 0, len = setters.length; i < len; i++) {
str += ', ' + createConst(setters[i]) + '\n';
}
str += '\n\n';
str += '// TiBase.cpp //\n';
for(var i = 0, len = setters.length; i < len; i++) {
str += createTiBase(setters[i]) + '\n';
}
return str;
}
exports.clear = function() {
setters = [];
}
exports.addMethod = function(method) {
setters.push(method)
}
exports.log = function() {
console.log(generateOutput());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment