Skip to content

Instantly share code, notes, and snippets.

@grantges
Created December 1, 2014 15:27
Show Gist options
  • Save grantges/060ff360326f1e165c6b to your computer and use it in GitHub Desktop.
Save grantges/060ff360326f1e165c6b to your computer and use it in GitHub Desktop.
Using Custom Tags to Map HTML to Ti
function htmlToTi(_args){
var json = {};
var keys = _.keys(_args);
_.each(keys, function(key){
switch(key){
case "bgcolor":
case "background-color":
json.backgroundColor = _args[key];
break;
case "height":
case "width":
case "top":
case "left":
case "bottom":
case "right":
json[key] = _args[key];
break;
case "style":
//_.extend(json, htmlToTi()
break;
default:
}
});
return json;
}
exports.creatediv = function(_args){
var json = htmlToTi(_args);
var view = Ti.UI.createView(json);
return view;
};
exports.createDIV = exports.creatediv;
exports.createDiv = exports.creatediv;
<Alloy>
<Window class="container">
<div module="html" bgcolor="#f00" style="border-radius:3px" height="200" width="200">
<div module="html" bgcolor="#00f" height="50" width="50" />
</div>
</Window>
</Alloy>
@FokkeZB
Copy link

FokkeZB commented Dec 2, 2014

I think you only need createDiv since Alloy will camelCase it for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment