Comparing version 0.1.14 to 0.1.15
@@ -11,4 +11,7 @@ /** | ||
_ = require("./lib/alloy/underscore")._, | ||
pkginfo = require('pkginfo')(module, 'name', 'version'); | ||
pkginfo = require('pkginfo'); | ||
// setup our module so have the pkginfo version from package.json | ||
pkginfo(module,'name','version'); | ||
// TODO: get the action list from the commands directory | ||
@@ -73,6 +76,6 @@ var ACTIONS = ['compile', 'generate', 'new', 'run']; | ||
// Setup up logging output | ||
logger.stripColors = (program.colors==false); | ||
logger.stripColors = (program.colors===false); | ||
banner(); | ||
if (program.args.length == 0) | ||
if (program.args.length === 0) | ||
{ | ||
@@ -79,0 +82,0 @@ var help = program.helpInformation(); |
@@ -13,2 +13,5 @@ var U = require('../../utils'), | ||
exports.STYLE_ALLOY_TYPE = '__ALLOY_TYPE__'; | ||
exports.STYLE_CONST_PREFIX = '__ALLOY_CONST__:'; | ||
////////////////////////////////////// | ||
@@ -31,4 +34,7 @@ ////////// public interface ////////// | ||
id = node.getAttribute('id') || state.defaultId || req || exports.generateUniqueId(); | ||
ns = ns.replace(/^Titanium\./, 'Ti'); | ||
node.setAttribute('id', id); | ||
if (state.defaultId) { delete state.defaultId; } | ||
return { | ||
@@ -45,2 +51,11 @@ ns: ns, | ||
// "Empty" states are generally used when you want to create a | ||
// Titanium component with no parent | ||
exports.createEmptyState = function(styles) { | ||
return { | ||
parent: {}, | ||
styles: styles | ||
}; | ||
}; | ||
exports.createCompileConfig = function(inputPath, outputPath, alloyConfig) { | ||
@@ -111,15 +126,14 @@ var dirs = ['assets','config','controllers','migrations','models','styles','views','widgets']; | ||
// use Ti namespace | ||
f = f.replace(/Titanium\./g,"Ti."); | ||
// fixup constants so we can use them in JSON but then we do magic conversions | ||
f = f.replace(/Ti\.UI\.FILL/g,'"TI_UI_FILL"'); | ||
f = f.replace(/Ti\.UI\.SIZE/g,'"TI_UI_SIZE"'); | ||
f = f.replace(/Ti\.UI\.TEXT_ALIGNMENT_LEFT/g,'"TI_UI_TEXT_ALIGNMENT_LEFT"') | ||
f = f.replace(/Ti\.UI\.TEXT_ALIGNMENT_RIGHT/g,'"TI_UI_TEXT_ALIGNMENT_RIGHT"') | ||
f = f.replace(/Ti\.UI\.TEXT_ALIGNMENT_CENTER/g,'"TI_UI_TEXT_ALIGNMENT_CENTER"') | ||
try | ||
{ | ||
// find constants | ||
// TODO: This needs work. There's still an off chance that this could | ||
// match content in a string. Or that the STYLE_CONST_PREFIX could | ||
// appear in other style strings. Extremely unlikely, but possible. | ||
f = f.replace(/\:\s*(Ti\.[^\s\,\}]+)/g, ': "' + exports.STYLE_CONST_PREFIX + '$1"'); | ||
try { | ||
return JSON.parse(f); | ||
} | ||
catch(E) | ||
{ | ||
} catch(E) { | ||
U.die("Error parsing style at "+p.yellow+". Error was: "+String(E).red); | ||
@@ -131,2 +145,18 @@ } | ||
exports.createVariableStyle = function(keyValuePairs, value) { | ||
var style = {}, | ||
key, value; | ||
if (_.isArray(keyValuePairs)) { | ||
_.each(keyValuePairs, function(pair) { | ||
var k = pair[0]; | ||
var v = pair[1]; | ||
style[k] = { value:v }; | ||
style[k][exports.STYLE_ALLOY_TYPE] = 'var'; | ||
}); | ||
} else { | ||
style[keyValuePairs] = { value:value }; | ||
style[keyValuePairs][exports.STYLE_ALLOY_TYPE] = 'var'; | ||
} | ||
return style; | ||
}; | ||
@@ -165,30 +195,23 @@ exports.addStyleById = function(styles, id, key, value) { | ||
mergeStyles(extraStyle,s); | ||
// Process any Titanium constants in the generated style | ||
var constants = { | ||
'TI_UI_FILL':'Ti.UI.FILL', | ||
'TI_UI_SIZE':'Ti.UI.SIZE', | ||
'TI_UI_TEXT_ALIGNMENT_LEFT':'Ti.UI.TEXT_ALIGNMENT_LEFT', | ||
'TI_UI_TEXT_ALIGNMENT_CENTER':'Ti.UI.TEXT_ALIGNMENT_CENTER', | ||
'TI_UI_TEXT_ALIGNMENT_RIGHT':'Ti.UI.TEXT_ALIGNMENT_RIGHT' | ||
}; | ||
//console.log(s); | ||
var regex = new RegExp('^' + exports.STYLE_CONST_PREFIX + '(.+)'); | ||
for (var sn in s) { | ||
var v = s[sn]; | ||
var q = typeof(v) === 'string'; | ||
var cf = constants[v]; | ||
if (cf) { | ||
str.push(stylePrefix+sn+':'+cf); | ||
} else if (q) { | ||
str.push(stylePrefix+sn+':'+'"'+v+'"'); | ||
} else { | ||
if (_.isObject(v) && v.alloyType === 'var') { | ||
str.push(stylePrefix+sn+':'+v.value); | ||
var value = s[sn], | ||
actualValue; | ||
if (_.isString(value)) { | ||
var matches = value.match(regex); | ||
if (matches !== null) { | ||
actualValue = matches[1]; // matched a constant | ||
} else { | ||
str.push(stylePrefix+sn+':'+ JSON.stringify(v)); | ||
actualValue = '"' + value + '"'; // just a string | ||
} | ||
} else if (_.isObject(value) && value[exports.STYLE_ALLOY_TYPE] === 'var') { | ||
actualValue = value.value; // dynamic variable value | ||
} else { | ||
actualValue = JSON.stringify(value); // catch all, just stringify the value | ||
} | ||
str.push(stylePrefix + sn + ':' + actualValue); | ||
} | ||
return str.join(",\n"); | ||
return str.join(',\n'); | ||
} | ||
@@ -195,0 +218,0 @@ |
@@ -11,16 +11,8 @@ // TODO: pass errors back to the calling function in the compile | ||
var args = CU.getParserArgs(node, state), | ||
children = U.XML.getElementsFromNodes(node.childNodes), | ||
parentArgs = {}, | ||
rawChildren = node.childNodes, | ||
linePrefix = '\t', | ||
tabStates = [], | ||
code = '', | ||
children = []; | ||
code = ''; | ||
// create array of children elements | ||
for (var i = 0, l = rawChildren.length; i < l; i++) { | ||
if (rawChildren.item(i).nodeType === 1) { | ||
children.push(rawChildren.item(i)); | ||
} | ||
} | ||
// Make sure the parent is TabGroup | ||
@@ -34,12 +26,4 @@ if (args.parent.node) { | ||
// See if the only child is a Window. If not, add it | ||
var winState; | ||
var createEmptyState = function() { | ||
return { | ||
parent: {}, | ||
styles: state.styles | ||
} | ||
}; | ||
// Generate the code for the Window contained in the Tab | ||
// See if the only child is a Window. If not, add it as a container | ||
// component for all the Tab's children | ||
var winNode; | ||
@@ -57,10 +41,12 @@ if (children.length !== 1 || | ||
// Generate code for Tab's Window | ||
winState = require('./default').parse(winNode || children[0], createEmptyState()); | ||
var winState = require('./default').parse(winNode || children[0], CU.createEmptyState(state.styles)); | ||
code += winState.code; | ||
// Generate the code for the Tab itself, with the Window in it | ||
var extraStyle = { window: { value: winState.parent.symbol } }; | ||
extraStyle.window[CU.STYLE_ALLOY_TYPE] = 'var'; | ||
var tabState = require('./default').parse( | ||
node, | ||
createEmptyState(), | ||
{ window: { value:winState.parent.symbol, alloyType:'var' } } | ||
CU.createEmptyState(state.styles), | ||
extraStyle | ||
); | ||
@@ -67,0 +53,0 @@ code += tabState.code; |
@@ -11,3 +11,3 @@ // TODO: pass errors back to the calling function in the compile | ||
var args = CU.getParserArgs(node, state), | ||
children = node.childNodes, | ||
children = U.XML.getElementsFromNodes(node.childNodes), | ||
linePrefix = '\t', | ||
@@ -28,13 +28,7 @@ tabStates = [], | ||
for (var i = 0, l = children.length; i < l; i++) { | ||
var c = children.item(i); | ||
if (c.nodeType != 1) { continue; } | ||
var child = children[i], | ||
childArgs = CU.getParserArgs(child); | ||
var child = { | ||
name: c.nodeName, | ||
ns: c.getAttribute('ns') || 'Ti.UI' | ||
}; | ||
child.fullname = child.ns + '.' + child.name; | ||
// Make sure all children are Tabs | ||
if (child.fullname !== 'Ti.UI.Tab') { | ||
if (childArgs.fullname !== 'Ti.UI.Tab') { | ||
U.die('All TabGroup children must be of type Ti.UI.Tab. Invalid child at position ' + i); | ||
@@ -44,3 +38,3 @@ } | ||
// process each Tab and save its state | ||
var tabState = require('./Ti.UI.Tab').parse(c, tabGroupState); | ||
var tabState = require('./Ti.UI.Tab').parse(child, tabGroupState); | ||
tabStates.push(tabState.parent); | ||
@@ -47,0 +41,0 @@ code += tabState.code; |
@@ -26,2 +26,14 @@ // The island of misfit toys... for functions | ||
}, | ||
getElementsFromNodes: function(nodeList) { | ||
var elems = []; | ||
if (nodeList && nodeList.length) { | ||
for (var i = 0, l = nodeList.length; i < l; i++) { | ||
var node = nodeList.item(i); | ||
if (node.nodeType === 1) { | ||
elems.push(node); | ||
} | ||
} | ||
} | ||
return elems; | ||
}, | ||
createEmptyNode: function(name, ns) { | ||
@@ -28,0 +40,0 @@ var str = '<' + name + (ns ? ' ns="' + ns + '"' : '') + '></' + name + '>'; |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"author": "Appcelerator, Inc. <info@appcelerator.com>", | ||
@@ -19,0 +19,0 @@ "maintainers": [ |
@@ -1,6 +0,1 @@ | ||
$.index.open(); | ||
$.map.addAnnotations([ | ||
{ animate:true, title:'Mountain View, CA', latitude:37.389569, longitude:-122.050212 }, | ||
{ animate:true, title:'Pittsburgh, PA', latitude:40.493893, longitude:-80.056856 } | ||
]); | ||
$.index.open(); |
{ | ||
".container": | ||
{ | ||
"backgroundColor":"white" | ||
} | ||
".container": | ||
{ | ||
"backgroundColor":"white" | ||
}, | ||
"Annotation": { | ||
"animate":true, | ||
"pincolor":Ti.Map.ANNOTATION_RED | ||
}, | ||
"#annotation1": { | ||
"title":"Mountain View, CA", | ||
"latitude":37.389569, | ||
"longitude":-122.050212 | ||
}, | ||
"#annotation2": { | ||
"title":"Pittsburgh, PA", | ||
"latitude":40.493893, | ||
"longitude":-80.056856 | ||
}, | ||
"#footerImage": { | ||
"image": "appc-400px.png", | ||
"backgroundColor": "#fff", | ||
"borderColor": "#a00", | ||
"borderWidth": 1, | ||
"borderRadius": 2, | ||
"width": "160dp", | ||
"height": "36dp", | ||
"bottom": "5dp", | ||
"right": "5dp" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
888380
14536
269