Socket
Socket
Sign inDemoInstall

alloy

Package Overview
Dependencies
Maintainers
4
Versions
269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alloy - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

Alloy/generators.js

337

Alloy/alloy.js

@@ -10,2 +10,3 @@ /**

logger = require("./common/logger"),
U = require('./utils'),
wrench = require("wrench"),

@@ -17,3 +18,4 @@ colors = require("colors"),

jsp = require("./uglify-js/uglify-js").parser,
pro = require("./uglify-js/uglify-js").uglify;
pro = require("./uglify-js/uglify-js").uglify,
generators = require('./generators');

@@ -61,9 +63,11 @@ //

" TFL$ = Ti.UI.FILL,\n" +
" TFT$ = Ti.UI.FIT,\n" +
" TSZ$ = Ti.UI.SIZE,\n" +
" $ = {}\n" +
";\n",
JS = "",
JS_EPILOG = "$.w.finishLayout();\n$.w.open();\n",
JS_EPILOG = "", //"$.w.finishLayout();\n$.w.open();\n",
ids = {},
compilerMakeFile;
compilerMakeFile,
alloyUniqueIdPrefix = '__alloyId',
alloyUniqueIdCounter = 0;

@@ -112,19 +116,2 @@ function CompilerMakeFile()

function ensureDir(p)
{
if (!path.existsSync(p))
{
logger.debug("Creating directory: "+p);
fs.mkdirSync(p);
}
}
function stringifyJSON(j)
{
var ast = jsp.parse("("+JSON.stringify(j)+")");
ast = pro.ast_mangle(ast);
var final_code = pro.gen_code(ast,{beautify:true,quote_keys:true});
return final_code = final_code.substring(1,final_code.length-2); // remove ( ) needed for parsing
}
function getNodeText(node)

@@ -186,3 +173,3 @@ {

f = f.replace(/Ti\.UI\.FILL/g,'"TI_UI_FILL"');
f = f.replace(/Ti\.UI\.FIT/g,'"TI_UI_FIT"');
f = f.replace(/Ti\.UI\.SIZE/g,'"TI_UI_SIZE"');
f = f.replace(/Ti\.UI\.TEXT_ALIGNMENT_LEFT/g,'"TI_UI_TEXT_ALIGNMENT_LEFT"')

@@ -239,3 +226,3 @@ f = f.replace(/Ti\.UI\.TEXT_ALIGNMENT_RIGHT/g,'"TI_UI_TEXT_ALIGNMENT_RIGHT"')

outputPath = outputPath ? outputPath : (program.outputPath || path.join(resolveAppHome(),".."));
ensureDir(outputPath);
U.ensureDir(outputPath);

@@ -280,3 +267,3 @@ if (program.config)

var resourcesDir = path.join(outputPath,"Resources");
ensureDir(resourcesDir);
U.ensureDir(resourcesDir);

@@ -378,3 +365,3 @@ var assetsDir = path.join(inputPath,'assets');

var beautify = alloyConfig.compiler ? alloyConfig.compiler.beautify : false;
var beautify = program.config.deploytype === 'development' ? true : false;

@@ -413,3 +400,3 @@ var ast = jsp.parse(code); // parse code and get the initial AST

{
ensureDir(rd);
U.ensureDir(rd);
wrench.copyDirSyncRecursive(fpath, rd);

@@ -498,3 +485,3 @@ }

'TI_UI_FILL':'TFL$',
'TI_UI_FIT':'TFT$',
'TI_UI_SIZE':'TSZ$',
'TI_UI_TEXT_ALIGNMENT_LEFT':'Ti.UI.TEXT_ALIGNMENT_LEFT',

@@ -510,15 +497,10 @@ 'TI_UI_TEXT_ALIGNMENT_CENTER':'Ti.UI.TEXT_ALIGNMENT_CENTER',

var cf = constants[v];
if (cf)
{
if (cf) {
v = cf;
q = false;
}
if (q)
{
} else if (q) {
str.push(" "+sn+':'+'"'+v+'"');
} else {
str.push(" "+sn+':'+ JSON.stringify(v));
}
else
{
str.push(" "+sn+':'+v);
}
}

@@ -537,4 +519,4 @@ return str.join(",\n");

if (name == 'widget')
{
var src = symbol + " = (function(exports," + arg2.join(",") + "){\n" +
{
var src = symbol + " = (function(exports){\n" +
js + "\n" +

@@ -587,2 +569,6 @@ " return exports;\n" +

function generateUniqueId() {
return alloyUniqueIdPrefix + alloyUniqueIdCounter++;
};
function generateNode(ischild,viewFile,node,state,defId)

@@ -592,3 +578,3 @@ {

var id = node.getAttribute('id') || defId;
var id = node.getAttribute('id') || defId || generateUniqueId();
var symbol = generateVarName(id);

@@ -606,3 +592,3 @@ var nodename = node.nodeName;

{
parseView(req,state);
parseView(req,state,null,id);
return;

@@ -635,3 +621,3 @@ }

if (ids[id])
if (id !== undefined && ids[id])
{

@@ -673,4 +659,8 @@ die("<"+nodename+"> from '"+viewFile+"' attempted to use the id '"+id+"' which has already been defined in the view '"+ids[id]+"'");

appendSource(generateStyleParams(state.styles,classes,id,node.nodeName));
appendSource("}),'" + node.nodeName + "', " + state.parentNode + ");");
appendSource(state.parentNode+".add("+symbol+");");
if (state.parentNode) {
appendSource("}),'" + node.nodeName + "', " + state.parentNode + ");");
appendSource(state.parentNode+".add("+symbol+");");
} else {
appendSource("}),'" + node.nodeName + "');");
}

@@ -700,3 +690,3 @@ var childstate = {

// look for our model
files = _.reject(files,function(f) { return f.indexOf(part)!=-1});
files = _.reject(files,function(f) { return f.indexOf(part)==-1});
// sort them in the oldest order first

@@ -804,2 +794,3 @@ files = files.sort(function(a,b){

var doc = new DOMParser().parseFromString(String(xml));
var docRoot = doc.documentElement;

@@ -813,24 +804,12 @@ var id = viewid || doc.documentElement.getAttribute('id') || viewName;

{
if (doc.documentElement.nodeName == 'SplitWindow')
{
//TODO -- this is not right yet - we need to populate masterView, detailView
var src = "$.w = Ti.UI.iOS.createSplitWindow({\n" +
" masterView: ,\n" +
" detailView: ,\n" +
" id: '" + "'\n" +
"});\n" +
"$.w.startLayout();\n";
JS_EPILOG = src + JS_EPILOG;
}
else
{
appendSource("$.w = Ti.UI.createWindow();");
appendSource("\n// defer rendering");
appendSource("$.w.startLayout();\n");
}
findAndLoadModels(state);
}
generateNode(false,viewFile,doc.documentElement,state,viewid||viewName);
if (docRoot.nodeName === 'App') {
for (var i = 0, l = docRoot.childNodes.length; i < l; i++) {
generateNode(false,viewFile,docRoot.childNodes.item(i),state,viewid||viewname);
}
} else {
generateNode(false,viewFile,doc.documentElement,state,viewid||viewName);
}
generateController(viewName,parameters,dir,state,id);

@@ -842,8 +821,8 @@

var state = {
parentNode:"$.w",
globals:["$.w"],
parentNode: null,
globals: [],
models:[]
};
parseView('index',state);
parseView('index',state,null,'index');
copyAssets();

@@ -861,6 +840,6 @@ copyLibs();

var plugins = path.join(rootDir,"plugins");
ensureDir(plugins);
U.ensureDir(plugins);
var alloyPluginDir = path.join(plugins,"ti.alloy");
ensureDir(alloyPluginDir);
U.ensureDir(alloyPluginDir);

@@ -965,5 +944,7 @@ var alloyPlugin = path.join(alloyPluginDir,"plugin.py");

var INDEX_XML = "<?xml version='1.0'?>\n" +
"<View class='container'>\n" +
' <Label id="t">Hello, World</Label>\n' +
"</View>\n",
"<App>\n" +
"\t<Window class='container'>\n" +
'\t\t<Label id="t">Hello, World</Label>\n' +
"\t</Window>\n" +
"</App>\n",
INDEX_JSON = "{\n" +

@@ -976,4 +957,5 @@ ' ".container":\n' +

' {\n' +
' "width": Ti.UI.FIT,\n'+
' "height": Ti.UI.FIT\n'+
' "width": Ti.UI.SIZE,\n'+
' "height": Ti.UI.SIZE,\n'+
' "color": "#000"\n'+
' }\n' +

@@ -983,3 +965,4 @@ "}\n",

" alert($.t.text);\n" +
"});\n";
"});\n\n" +
"exports.open();";

@@ -993,7 +976,5 @@ fs.writeFileSync(path.join(outputPath,'views','index.xml'),INDEX_XML);

var defaultConfig = {
compiler: {
beautify:false
}
compiler: {}
};
fs.writeFileSync(path.join(outputPath,'alloy.json'),stringifyJSON(defaultConfig));
fs.writeFileSync(path.join(outputPath,'alloy.json'),U.stringifyJSON(defaultConfig));

@@ -1012,3 +993,3 @@ // write the build file

var cfg = {global:{}, "env:development":{}, "env:test":{}, "env:production":{}, "os:ios":{}, "os:android":{}};
fs.writeFileSync(path.join(outputPath,"config","config.json"), stringifyJSON(cfg));
fs.writeFileSync(path.join(outputPath,"config","config.json"), U.stringifyJSON(cfg));

@@ -1031,194 +1012,26 @@ // install the plugin

function generateController(home,args)
function generate(args)
{
if (args.length == 0)
{
die("generate controller requires a NAME as third argument");
if (args.length === 0) {
die("generate requires a TYPE such as 'controller' as second argument");
} else if (args.length === 1) {
die("generate requires a NAME such as third argument");
}
var name = args[0];
var cn = path.join(home,'controllers',name+'.js');
if (path.existsSync(cn) && !program.force)
{
die("File already exists: "+cn);
}
// right now, it's empty. we'll likely want to generate a skeleton
var C = "\n";
fs.writeFileSync(cn,C);
logger.info('Generate controller named '+name);
}
var targets = ['controller', 'view', 'model', 'migration', 'widget'];
var target = args[0];
var name = args[1];
function generateView(home,args)
{
if (args.length == 0)
if (!_.contains(targets, target))
{
die("generate view requires a NAME as third argument");
die(
'Invalid generate target "' + target + '"\n' +
'Must be one of the following: [' + targets.join(',') + ']'
);
}
var name = args[0];
var vn = path.join(home,'views',name+'.xml');
if (path.existsSync(vn) && !program.force)
{
die("File already exists: "+vn);
}
var sn = path.join(home,'styles',name+'.json');
if (path.existsSync(sn) && !program.force)
{
die("File already exists: "+sn);
}
// right now, it's empty. we'll likely want to generate a skeleton
var XML = "<?xml version='1.0'?>\n" +
"<View class='container'>\n" +
'\n' +
"</View>\n",
JSON = "{\n" +
' ".container":\n' +
' {\n' +
' "backgroundColor":"white"\n'+
' }\n' +
"}\n";
fs.writeFileSync(vn,XML);
fs.writeFileSync(sn,JSON);
logger.info('Generate view and styles named '+name);
}
function pad(x)
{
if (x < 10)
{
return '0' + x;
}
return x;
}
function generateMigrationFileName(t)
{
var d = new Date;
var s = String(d.getUTCFullYear()) + String(pad(d.getUTCMonth())) + String(pad(d.getUTCDate())) + String(pad(d.getUTCHours())) + String(pad(d.getUTCMinutes())) + String(d.getUTCMilliseconds())
return s + '_' + t + '.js';
}
function generateModel(home,args)
{
if (args.length == 0)
{
die("generate controller requires a NAME as third argument");
}
var name = args[0],
a = args.slice(1);
var migrationsDir = path.join(home,'migrations');
ensureDir(migrationsDir);
if (a.length == 0)
{
die("missing model columns as fourth argument and beyond");
}
var J = {"columns":{},"defaults":{},"adapter":{"type":"sql","tablename":name}};
for (var c=0;c<a.length;c++)
{
var X = a[c].split(":");
J.columns[X[0]] = X[1];
}
var mn = path.join(home,'models',name+'.json');
if (path.existsSync(mn) && !program.force)
{
die("File already exists: "+mn);
}
var code = stringifyJSON(J);
fs.writeFileSync(mn,code);
var mf = path.join( migrationsDir, generateMigrationFileName(name) );
var mc = final_code.split("\n");
var md = "" +
'migration.up = function(db)\n'+
'{\n'+
' db.createTable("' + name + '",\n';
_.each(mc,function(l){
md+=' '+l+'\n';
});
md+=''+
' );\n' +
'};\n'+
'\n'+
'migration.down = function(db)\n'+
'{\n'+
' db.dropTable("' + name + '");\n'+
'};\n'+
'\n';
fs.writeFileSync(mf,md);
logger.info('Generate model named '+name);
}
function generateMigration(home,args)
{
if (args.length == 0)
{
die("generate migration requires a NAME as third argument");
}
var name = args[0];
var migrationsDir = path.join(home,'migrations');
ensureDir(migrationsDir);
var mf = path.join( migrationsDir, generateMigrationFileName(name) );
var md = "" +
'migration.up = function(db)\n'+
'{\n'+
'};\n'+
'\n'+
'migration.down = function(db)\n'+
'{\n'+
'};\n'+
'\n';
fs.writeFileSync(mf,md);
}
function generate(args)
{
if (args.length == 0)
{
die("generate requires a TYPE such as 'controller' as second argument");
}
var home = resolveAppHome();
var newargs = args.slice(1);
switch(args[0])
{
case 'controller':
{
generateController(home,newargs);
break;
}
case 'view':
{
generateView(home,newargs);
break;
}
case 'model':
{
generateModel(home,newargs);
break;
}
case 'migration':
{
generateMigration(home,newargs);
break;
}
}
var funcName = 'generate' + target.charAt(0).toUpperCase() + target.slice(1);
generators[funcName](home,newargs,name,program.force);
}

@@ -1225,0 +1038,0 @@

var _ = require("alloy/underscore")._,
Backbone = require("alloy/backbone"),
SQLSync = require("alloy/sync/sql");
SQLSync = require("alloy/sync/sql"),
osname = Ti.Platform.osname;

@@ -101,3 +102,9 @@ module.exports._ = _;

cbs[cb]=wcb;
al(e, wcb);
if (osname === 'android') {
al.call(t, e, wcb);
} else {
al(e, wcb);
}
_.bind(oo,ctx,e,cb,context)();

@@ -112,3 +119,9 @@ };

_.bind(of,ctx,e,cb,context)();
rl(e, f);
if (osname === 'android') {
rl.call(t, e, f);
} else {
rl(e, f);
}
delete cbs[cb];

@@ -115,0 +128,0 @@ f = null;

// top is the first view we defined
top.updateLayout({
$.top.updateLayout({
backgroundColor:"black",

@@ -10,5 +10,7 @@ borderRadius:2,

b.addEventListener('click',function(){
t.text = "You clicked me";
$.b.addEventListener('click',function(){
$.t.text = "You clicked me";
});
exports.open();
{
"#b":
{
"width": Ti.UI.FIT,
"height": Ti.UI.FIT,
"width": Ti.UI.SIZE,
"height": Ti.UI.SIZE,
"title" : "Click me",

@@ -7,0 +7,0 @@ "bottom" : 20

@@ -8,3 +8,3 @@ {

"width": Ti.UI.FILL,
"height":Ti.UI.FIT,
"height":Ti.UI.SIZE,
"color": "yellow",

@@ -11,0 +11,0 @@ "textAlign": Ti.UI.TEXT_ALIGNMENT_CENTER

var foo = require("foo"),
bar = require("vendor/bar");
Ti.API.info(bar.helloize(foo.generate()));
// use the selector engine to find the first Label and set the text
$("Label")[0].text = bar.helloize(foo.generate());
exports.open();
table.setData([
$.table.setData([
{"title":"Alcatraz", "image":"smallpic1.jpg"},

@@ -10,9 +10,9 @@ {"title":"American Flag", "image":"smallpic2.jpg"},

table.addEventListener("click",function(e)
$.table.addEventListener("click",function(e)
{
// note that the JPG images will be loaded (as compiled) from the assets directory
image.image = e.rowData.image;
$.image.image = e.rowData.image;
});
search.addEventListener("change", function(e)
$.search.addEventListener("change", function(e)
{

@@ -28,2 +28,4 @@ // do something with e.value

Ti.API.info("We are on an iPad so you should see a split view");
}
}
exports.open();

@@ -1,4 +0,6 @@

map.addAnnotations([
exports.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 }
]);

@@ -17,5 +17,7 @@ ALLOY

- *Simple Model*: an example of a model based system that includes migrations
- *masterdetail*: a lesson in louse-coupling through MVC, delegates, and custom events in alloy
- *Multiplatform*: an example of building a multi screen app
- *Modules*: an example that shows an app built module and a vendor module. This also demonstrates the selector engine.
- *Namespaces*: Shows you how you can use UI components outside of the `Ti.UI` namespace in your markup view hierarchy.
- *No Ids*: Build a view hierarchy without explicitly giving the elements IDs.

@@ -22,0 +24,0 @@

@@ -5,3 +5,3 @@

// the todos is a collection of todo model objects
todo.fetch(function(todos) {
$.todo.fetch(function(todos) {

@@ -12,3 +12,3 @@ var rows = [];

// bind each todo model item to the row
todos.each(function(todo)
$.todos.each(function(todo)
{

@@ -18,3 +18,3 @@ // notice that the createRowTemplate is a special Allow function that will

// row model into the template
var row = table.createRowTemplate(todo);
var row = $.table.createRowTemplate(todo);

@@ -31,5 +31,6 @@ // add the row to our array

// set the table data
table.setData(rows);
$.table.setData(rows);
});
exports.open();
{
".name" : {
"width": Ti.UI.FIT,
"height": Ti.UI.FIT,
"width": Ti.UI.SIZE,
"height": Ti.UI.SIZE,
"textAlign": Ti.UI.TEXT_ALIGNMENT_LEFT,

@@ -11,4 +11,4 @@ "color": "black",

".done" : {
"width": Ti.UI.FIT,
"height": Ti.UI.FIT,
"width": Ti.UI.SIZE,
"height": Ti.UI.SIZE,
"textAlign": Ti.UI.TEXT_ALIGNMENT_RIGHT,

@@ -15,0 +15,0 @@ "color": "red",

@@ -7,3 +7,3 @@

// test removing it
b.off("click",showAlert);
$.b.off("click",showAlert);
}

@@ -15,5 +15,7 @@

*/
b.on("click",showAlert);
$.b.on("click",showAlert);
exports.open();
{
"Button" : {
"width" : Ti.UI.FIT,
"height" : Ti.UI.FIT
"width" : Ti.UI.SIZE,
"height" : Ti.UI.SIZE
},

@@ -6,0 +6,0 @@

w.setText("Press a button to see something happen");
$.w.setText("Press a button to see something happen");
exports.open();
a.addEventListener('click',function(){
t.text = "You clicked A";
$.a.addEventListener('click',function(){
$.t.text = "You clicked A";
});
b.addEventListener('click',function(){
t.text = "You clicked B";
$.b.addEventListener('click',function(){
$.t.text = "You clicked B";
});
c.addEventListener('click',function(){
t.text = "You clicked C";
$.c.addEventListener('click',function(){
$.t.text = "You clicked C";
});

@@ -19,7 +19,7 @@

exports.setText = function(text){
t.text = text;
$.t.text = text;
};
exports.getText = function() {
return t.text;
return $.t.text;
}

@@ -16,3 +16,3 @@ {

],
"version": "0.1.0",
"version": "0.1.1",
"author": "Appcelerator, Inc. <info@appcelerator.com>",

@@ -47,2 +47,2 @@ "maintainers": [

}
}
}

@@ -68,3 +68,3 @@ Alloy

- *vendor* - this is where you should put any vendor specific modules, typically in the CommonJS format. Do not place native modules in this folder.
- *config* - _RESERVED FOR FUTURE USE_. This is currently not used but will eventually contain application specific config.
- *config* - Contains application specific config.

@@ -117,3 +117,12 @@ Compiling an App

Generating Widgets
------------------
To generate a basic widget, you run the following command
alloy generate widget <name>
This will create a default widget in your projects's `app/widgets` path.
Developing in Alloy

@@ -140,8 +149,8 @@ -------------------

"#b" : {
"width":Ti.UI.FIT,
"height":Ti.UI.FIT
"width":Ti.UI.SIZE,
"height":Ti.UI.SIZE
},
"#t" : {
"width":Ti.UI.FILL,
"height":Ti.UI.FIT,
"height":Ti.UI.SIZE,
"color":"black"

@@ -186,4 +195,4 @@ }

"Button": {
"width":Ti.UI.FIT,
"height":Ti.UI.FIT,
"width":Ti.UI.SIZE,
"height":Ti.UI.SIZE,
"borderColor":"red"

@@ -222,3 +231,3 @@ },

"width": Ti.UI.FILL,
"height":Ti.UI.FIT,
"height":Ti.UI.SIZE,
"b":false

@@ -313,5 +322,5 @@ }

```xml
<View>
<Window>
<Button id="b"></Button>
</View>
</Window>
```

@@ -325,2 +334,5 @@

});
// "exports" represents the top-level container for this view
exports.open();
```

@@ -327,0 +339,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc