@extjs/sencha-cmd-linux-32
Version:
Productivity and performance optimization tool for building applications with Sencha Ext JS and Sencha Touch.
144 lines (116 loc) • 4.39 kB
JavaScript
;
var Map = require('../export/type/Map.js');
var Literal = require('../export/type/Literal.js');
var Text = require('../export/type/Text.js');
var List = require('../export/type/List.js');
var Bool = require('../export/type/Bool.js');
var Env = require('../Env.js');
module.exports = {
init(runtime) {
runtime.register({
parsebox: function (list, num) {
if (list == null || list.$isFashionNull) {
return Literal.Null;
}
var ret, size, actual = [], i, item;
num = this.unbox(num);
if (list.type === 'list') {
list = list.items;
}
if (!this.isArray(list)) {
list = [list];
}
size = list.length;
for (i = 0; i < size; i++) {
actual.push(list[i]);
}
if (num >= size) {
if (size === 1) {
actual.push(list[0]);
actual.push(list[0]);
actual.push(list[0]);
} else if (size === 2) {
actual.push(list[0]);
actual.push(list[1]);
} else if (size === 3) {
actual.push(list[1]);
}
}
ret = actual[num - 1];
return ret;
},
is_null: function (value) {
if (value === Literal.Null) {
return true;
}
switch (value.type) {
case 'string':
case 'literal':
value = value.value;
return value == 'null' || value == 'none' || value === null;
default:
return false;
}
},
file_join: function (value1, value2) {
value1 = this.unbox(value1);
value2 = this.unbox(value2);
var joined = value1 ? value1 + '/' + value2 : value2;
return new Text(joined, '');
},
theme_image_exists: function (directory, path) {
// don't use this.unbox here, as we need the actual unquoted value
directory = directory.value;
path = path.value;
var fullPath = Env.join(directory, path);
if (Env.isBrowser) {
return true;
}
return Env.exists(fullPath);
},
map_create: function () {
return new Map();
},
map_put: function (map, key, value) {
map.put(key, value);
},
map_get: function (map, key) {
return map.get(key);
},
map_merge: function (map1, map2) {
var ret = new Fashion.Map(map1 && map1.items && [].concat(map1.items));
if (map2) {
for (var items = map2.items, i = 0; i < items.length; i += 2) {
var key = items[i],
value = items[i+1];
if (key && value) {
ret.put(items[i], items[i+1]);
}
}
}
return ret;
},
map_remove: function(map, key) {
if (map && map.$isFashionMap) {
map.remove(key);
}
},
map_keys: function(map) {
if (map && map.$isFashionMap) {
return new List(map.getKeys(), ', ');
}
},
map_values: function(map){
if (map && map.$isFashionMap) {
return new List(map.getValues(), ', ');
}
},
map_has_key: function(map, key) {
if (map && map.$isFashionMap) {
return map.hasKey(key) ? Bool.True : Bool.False;
}
return Bool.False;
}
});
}
};