Skip to content

Commit

Permalink
🏁 v0.0.6-25 ➖ updating navigation modules and more...
Browse files Browse the repository at this point in the history
  • Loading branch information
brentonhouse committed Mar 13, 2017
1 parent 60eb289 commit 52ee2b0
Show file tree
Hide file tree
Showing 44 changed files with 15,374 additions and 341 deletions.
169 changes: 119 additions & 50 deletions alloy-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';
/***
* __ _ __ __
* ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
Expand All @@ -8,91 +8,160 @@
*
* mobile solutions for everyday heroes
*
* @file
* {nativeloop} plugin for parsing alloy xml views
*
* @module
* nativeloop/plugins/alloy-parser
*
* @author
* Brenton House <[email protected]>
*
* @copyright
* Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
*
* @license
* Licensed under the terms of the MIT License (MIT)
* Please see the license.md included with this distribution for details.
* @file {nativeloop} plugin for parsing alloy xml views
* @module nativeloop/plugins/alloy-parser
* @author Brenton House <[email protected]>
* @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
* @license Licensed under the terms of the MIT License (MIT)
*
*/

var _ = require("lodash");
var _ = require( 'lodash' );

var alloyParser = {};
module.exports = alloyParser;

alloyParser.init = function(params) {
alloyParser.init = function( params ) {
alloyParser.parserParams = params;
}

alloyParser.parse = function(params) {
console.error("********* WRAPPING base.parse **********");

// console.info("nativeloop_widgets: " + JSON.stringify(alloyParser.parserParams.nativeloop_widgets, null, 2));

return _.wrap(params.baseParser.parse, function(func, node, state, parser) {
alloyParser.parse = function( params ) {
console.error( '********* WRAPPING base.parse **********' );
return _.wrap( params.baseParser.parse, function( func, node, state, parser ) {
var logger = console;
var selectedParser = parser;
var CONST = alloyParser.parserParams.CONST;
var CU = alloyParser.parserParams.CU;
var U = alloyParser.parserParams.U;

console.error("********* BASE:PARSE **********");
console.error( '********* BASE:PARSE **********' );

if(CU[CONST.DOCROOT_MODULE_PROPERTY] && !node.hasAttribute('module')) {
node.setAttribute('module', CU[CONST.DOCROOT_MODULE_PROPERTY]);
if( CU[ CONST.DOCROOT_MODULE_PROPERTY ] && !node.hasAttribute( 'module' ) ) {
node.setAttribute( 'module', CU[ CONST.DOCROOT_MODULE_PROPERTY ] );
}

var fullname = CU.getNodeFullname(node);
var src = node.getAttribute('src');
var name = node.getAttribute('name');
var moduleName = node.getAttribute('module');
node.nodeName = _.upperFirst(_.camelCase(node.nodeName));
var fullname = CU.getNodeFullname( node );
var src = node.getAttribute( 'src' );
var name = node.getAttribute( 'name' );
var moduleName = node.getAttribute( 'module' );
node.nodeName = _.upperFirst( _.camelCase( node.nodeName ) );
// logger.error("name in parser: " + name);
// logger.error("module in parser: " + moduleName);
// logger.error("fullname in parser: " + fullname);
// logger.error("nodeName in parser: " + _.lowerFirst(node.nodeName));
if(moduleName === "nativeloop") {

if(_.includes(alloyParser.parserParams.nativeloop_widgets, _.lowerFirst(node.nodeName))) {
// logger.debug("returning Alloy.Widget parser");
logger.error( 'moduleName: ' + JSON.stringify( moduleName, null, 2 ) );
if( moduleName === '/nativeloop' ) {
moduleName = 'nativeloop';
node.setAttribute( 'module', 'nativeloop' );
}
if( moduleName === 'nativeloop' ) {

!src && node.setAttribute("src", moduleName);
!name && node.setAttribute("name", _.lowerFirst(node.nodeName));
var nodeText = U.XML.getNodeText( node );
console.error( "nodeText: " + nodeText );
if( nodeText ) {
nodeText = U.trim( nodeText.replace( /'/g, "\\'" ) );
node.setAttribute( 'text', nodeText );
}
// _.forEach( node.attributes, function( attribute ) {
// // logger.debug("attribute: " + attribute.name + ": " + attribute.value);
// } );

//TODO: Add this to constants module
node.setAttribute( '__nativeloop', true );
node.setAttribute( '__navigatorId', "_.get($,'nav.id')");

console.warn( 'you are here → Looking for widget node: ' + _.lowerFirst( node.nodeName ) );
if( _.includes( alloyParser.parserParams.nativeloop_widgets, _.lowerFirst( node.nodeName ) ) ) {

console.error( 'you are here → Found widget node: ' + _.lowerFirst( node.nodeName ) );

var nodeText = U.XML.getNodeText(node);
// console.debug("nodeText: " + nodeText);
if(nodeText) {
nodeText = U.trim(nodeText.replace(/'/g, "\\'"));
node.setAttribute("text", nodeText);
!src && node.setAttribute( 'src', moduleName );
!name && node.setAttribute( 'name', _.lowerFirst( node.nodeName ) );

// make autoStyle default to true for nativeloop tags.
if( _.isNil( node.getAttribute( 'autoStyle' ) ) || _.isEmpty( node.getAttribute( 'autoStyle' ) ) ) {
node.setAttribute( 'autoStyle', true );
}
_.forEach(node.attributes, function(attribute) {
// logger.debug("attribute: " + attribute.name + ": " + attribute.value);
});

// var nodeText = U.XML.getNodeText( node );
// console.error("nodeText: " + nodeText);
// if( nodeText ) {
// nodeText = U.trim( nodeText.replace( /'/g, "\\'" ) );
// node.setAttribute( 'text', nodeText );
// }
// // _.forEach( node.attributes, function( attribute ) {
// // // logger.debug("attribute: " + attribute.name + ": " + attribute.value);
// // } );

// //TODO: Add this to constants module
// node.setAttribute( '__nativeloop', true );

selectedParser = params.widgetParser.parse;

}

} else {
// logger.debug("returning default parser");
_.forEach(node.attributes, function(attribute) {
// logger.debug("attribute: " + attribute.name + " = " + attribute.value);
});
// _.forEach( node.attributes, function( attribute ) {
// logger.debug("attribute: " + attribute.name + " = " + attribute.value);
// } );
}

var args = CU.getParserArgs( node, state ),
code = '';

// console.error( 'args.createArgs: ' + JSON.stringify( args.createArgs, null, 2 ) );
// Convert attributes that are in dot-notation to objects.
_.forEach( _.keys( args.createArgs ), key => {
console.error( 'key: ' + JSON.stringify( key, null, 2 ) );
if( _.includes( key, '.' ) ) {
let value = args.createArgs[ key ];
delete args.createArgs[ key ];
let split = key.split( '.' );
if( _.last( split ) === 'class' ) {
split[ split.length - 1 ] = 'classes';
key = split.join( '.' );
value = value.split( ' ' );
}
_.set( args.createArgs, key, value );
delete args.createArgs[ key ];
}
} );


// console.error( 'args.createArgs: ' + JSON.stringify( args.createArgs, null, 2 ) );

if( state.pre ) {
code += state.pre( node, state, args ) || '';
delete state.pre;
}
var newState = selectedParser( node, state, args );
// logger.error( 'newState.code: ' + JSON.stringify( newState.code, null, 2 ) );
// newState.code = newState.code.replace( /((Alloy.createWidget[^{]+{)(apiName))/g, "$2 navigator: _.get($,'args.navigator'), $3" )
// logger.error( 'newState.code: ' + JSON.stringify( newState.code, null, 2 ) );
code += newState.code;
if( state.post ) {
logger.error( 'state.post: ' + JSON.stringify( state.post, null, 2 ) );
code += state.post( node, newState, args ) || '';
delete state.post;
}
newState.code = code;

// if( node.getAttribute( '__nativeloop' ) && newState.code && newState.parent && newState.parent.symbol ) {
if( node.getAttribute( '__nativeloop' ) && newState.code ) {
// newState.parent.symbol = newState.parent.symbol.replace( /\.getViewEx[^\)]*\)/, '' );
newState.code = newState.code.replace( /\.getViewEx[^\)]*\)/g, '' );
newState.code = newState.code.replace( /(__navigatorId:\s*)"([^"]*)"/g, '$1$2' );
}

return func(node, state, selectedParser);
return newState;

});
// var newState = func( node, state, selectedParser );
// if( node.getAttribute( '__nativeloop' ) && newState.parent && newState.parent.symbol ) {
// // newState.parent.symbol = newState.parent.symbol.replace( /\.getViewEx[^\)]*\)/, '' );
// newState.code = response.newState.replace( /\.getViewEx[^\)]*\)/g, '' );
// }
// return newState;
} );
}
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env node

var yargs = require( "yargs" );
const yargs = require( "yargs" );
var Promise = require( "bluebird" );
Promise.promisifyAll( require( "fs-extra" ) );
const _ = require( 'lodash' );
Expand Down
78 changes: 78 additions & 0 deletions commands/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
var path = require( 'path' );
var fs = require( 'fs-extra' );
var _ = require( 'lodash' );
// var conf = require('rc')('nativeloop', {});
var pathExists = require( 'path-exists' );

exports.desc = 'Initializes a project for native development with {nativeloop}.'

var builder = {

"path": {
alias: "p",
default: process.cwd(),
describe: "Specifies the directory where you want to initialize the project, if different from the current directory. The directory must already exist.",
demand: false,
type: "string"
},
"force": {
alias: "f",
describe: "If set, applies the default project configuration and does not show the interactive prompt. ",
demand: false,
type: "string"
}

}
var copy_template = function( argv ) {

console.info( 'copy template ----------------------------------------------' );
console.info( 'path: ' + argv[ 'path' ] );
// process.chdir(argv['path']);
console.info( '__dirname: ' + __dirname );
console.info( 'process.cwd(): ' + process.cwd() );

let filename = 'alloy.jmk';
let source = path.join( __dirname, "..", 'templates', filename );
let root = argv[ "path" ];
console.error( 'source: ' + source );
console.info( 'root: ' + root );

console.warn( 'pathExists.sync(source): ' + pathExists.sync( source ) );
console.warn( 'pathExists.sync(root): ' + pathExists.sync( root ) );

if( !pathExists.sync( source ) ) {
console.error( 'source does not exist: ' + source );
return;
}

let tiapp = path.join( root, 'tiapp.xml' );

if( !pathExists.sync( tiapp ) ) {
console.error( 'Cannot find tiapp.xml: ' + tiapp );
return;
}

let target = path.join( root, 'app', filename );

Promise.resolve( () => console.error( "pathExists.sync(target): " + pathExists.sync( root ) ) )
.then( () => {
// check to see if the file is a nativeloop file.
// if it is not, make a backup of the file.
} )
.then( () => console.warn( "copying files to target directory: " + root ) )
.then( () => fs.copyAsync( source, target, {
clobber: true
} ) )
.then( () => console.warn( "all done." ) )
.catch( err => console.error( "Error occurred: " + err ) );



}

var handler = function( argv ) {
copy_template( argv );
}

exports.handler = handler;
exports.builder = builder;
2 changes: 2 additions & 0 deletions controllers/baseController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

$.nav = $.args.params.navigator;
64 changes: 64 additions & 0 deletions controllers/flex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';
/***
* __ _ __ __
* ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
* / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
* / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
* /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
*
* mobile solutions for everyday heroes
*
* @file This is the Alloy controller for managing groups of tiles.
* @module nativeloop/controllers/flex
* @author Brenton House <[email protected]>
* @version 1.0.0
* @since 1.0.0
* @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
* @license Licensed under the terms of the MIT License (MIT)
*
*/


const utils = require( 'nativeloop/utils' );
const device = require( 'nativeloop/device' );

// console.warn( '[tiles] $.args: ' + JSON.stringify( $.args, null, 2 ) );

// We can't handle 'fill' yet as we need actual widths.
//TODO: add support for Ti.UI.FILL (with postlayout?)
if( $.args.width === Ti.UI.FILL ) {
$.args.width = device.width;
}

_.defaults( $.args, {
width: device.width,
height: Ti.UI.FILL,
} );

// Find the actual width if a percentage was passed in.
$.args.width = utils.parsePercentage( $.args.width );

// convert margin/padding into objects
let margin = utils.parsePadding( $.args.margin, $.args.width );
let padding = utils.parsePadding( $.args.padding, $.args.width );

// console.error( '[flex] $.args: ' + JSON.stringify( $.args, null, 2 ) );

_.forEach( $.args.children, child => {

let childArgs = $.args.child || {};
_.defaults( childArgs, {
width: ( ( $.args.width / 12 ) * ( childArgs.flexWidth || childArgs.flexSize || childArgs.size || 0 ) ),
height: ( ( $.args.width / 12 ) * ( childArgs.flexHeight || childArgs.flexSize || childArgs.size || 0 ) ),
} );


child.applyDefaults( childArgs );

$._wrapper.add( child.getView() );

} );

let wrapperArgs = _.assignIn( _.pick( $.args, [ 'height', 'width', 'top', 'bottom', 'left', 'right', 'backgroundColor', 'layout' ] ), margin )

$._wrapper.applyProperties( wrapperArgs );
Loading

0 comments on commit 52ee2b0

Please sign in to comment.