diff options
author | Jean Claveau <jean.claveau@c277.fr> | 2014-10-04 15:52:12 +0200 |
---|---|---|
committer | Jean Claveau <jean.claveau@c277.fr> | 2014-10-04 15:52:12 +0200 |
commit | b41f4f97c0cdb5a553d54fefcd5ca551603b16d9 (patch) | |
tree | dcf43908ffab16a0667facb25a5eafd4eac52fe6 /script | |
parent | 9aee5414efb0075459e7a7d6d7ad9d2351ba4c32 (diff) |
svg parser scripts in extension + removing cisms + cleaning
Diffstat (limited to 'script')
-rw-r--r-- | script/console/__init__.js | 12 | ||||
-rw-r--r-- | script/svg/__init__.js | 59 |
2 files changed, 71 insertions, 0 deletions
diff --git a/script/console/__init__.js b/script/console/__init__.js new file mode 100644 index 0000000000..a1d833b9a9 --- /dev/null +++ b/script/console/__init__.js @@ -0,0 +1,12 @@ +__setupPackage__(__extension__); + +console = { + log : function(){ + var out = [], + i = 0; + for( ; i<arguments.length; i++ ){ + out.push( JSON.stringify(arguments[i]) ); + } + print(out.join(' ')); + } +} diff --git a/script/svg/__init__.js b/script/svg/__init__.js new file mode 100644 index 0000000000..c7a0c39334 --- /dev/null +++ b/script/svg/__init__.js @@ -0,0 +1,59 @@ +__setupPackage__(__extension__); + +svg.templateHooks = {}; + +svg.regexpQuote = function (str, delimiter) { + return String(str).replace( + new RegExp( + '[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', + 'g' + ), + '\\$&' + ); +} + +svg.hookNames = function(){ + var hookNames = ['variable'], + that = this; + for( var i in this.templateHooks ) + hookNames.push(i); + + hookNames.toPattern = function(){ + for( var i in this ) + this[i] = that.regexpQuote(this[i]); + return this.join('|'); + } + + return hookNames; +} + +global = this; +svg.templateHooks.variable = variable = function( varName ){ + // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + // console.log(global[varName]); + if( varName in global ){ + return global[varName]; + } + return ''; +} + +svg.templateHooks.prop = prop = function( propName, varName ){ + var out = ''; + + if( (varName in global) ){ + var value = global[varName]; + + if( isNumber(value) ){ + out = propName + ':' + value + ';'; + } else if( value.length ) { + out = propName + ':' + value + ';'; + } + + } else { + // print( 'Unable to find ' + varName + ' for prop hook.' ); + } + + // print( varName + ' => ' out + ' | ' + (varName in global) ); + return out; +} + |