http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/css/index.css ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/css/index.css b/spec/fixtures/projects/native/ios/www/css/index.css new file mode 100644 index 0000000..f1f9d76 --- /dev/null +++ b/spec/fixtures/projects/native/ios/www/css/index.css @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +* { + -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ + -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */ + -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */ + -webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */ +} + +body { + background-color:#E4E4E4; + background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); + background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); + background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); + background-image:-webkit-gradient( + linear, + left top, + left bottom, + color-stop(0, #A7A7A7), + color-stop(0.51, #E4E4E4) + ); + background-attachment:fixed; + font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif; + font-size:12px; + height:100%; + margin:0px; + padding:0px; + text-transform:uppercase; + width:100%; +} + +/* Portrait layout (default) */ +.app { + background:url(../img/logo.png) no-repeat center top; /* 170px x 200px */ + position:absolute; /* position in the center of the screen */ + left:50%; + top:50%; + height:50px; /* text area height */ + width:225px; /* text area width */ + text-align:center; + padding:180px 0px 0px 0px; /* image height is 200px (bottom 20px are overlapped with text) */ + margin:-115px 0px 0px -112px; /* offset vertical: half of image height and text area height */ + /* offset horizontal: half of text area width */ +} + +/* Landscape layout (with min-width) */ +@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) { + .app { + background-position:left center; + padding:75px 0px 75px 170px; /* padding-top + padding-bottom + text area = image height */ + margin:-90px 0px 0px -198px; /* offset vertical: half of image height */ + /* offset horizontal: half of image width and text area width */ + } +} + +h1 { + font-size:24px; + font-weight:normal; + margin:0px; + overflow:visible; + padding:0px; + text-align:center; +} + +.event { + border-radius:4px; + -webkit-border-radius:4px; + color:#FFFFFF; + font-size:12px; + margin:0px 30px; + padding:2px 0px; +} + +.event.listening { + background-color:#333333; + display:block; +} + +.event.received { + background-color:#4B946A; + display:none; +} + +@keyframes fade { + from { opacity: 1.0; } + 50% { opacity: 0.4; } + to { opacity: 1.0; } +} + +@-webkit-keyframes fade { + from { opacity: 1.0; } + 50% { opacity: 0.4; } + to { opacity: 1.0; } +} + +.blink { + animation:fade 3000ms infinite; + -webkit-animation:fade 3000ms infinite; +}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/img/logo.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/img/logo.png b/spec/fixtures/projects/native/ios/www/img/logo.png new file mode 100644 index 0000000..9519e7d Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/img/logo.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/index.html ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/index.html b/spec/fixtures/projects/native/ios/www/index.html new file mode 100644 index 0000000..92484ad --- /dev/null +++ b/spec/fixtures/projects/native/ios/www/index.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="format-detection" content="telephone=no" /> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> + <link rel="stylesheet" type="text/css" href="css/index.css" /> + <title>Hello World</title> + </head> + <body> + <div class="app"> + <h1>Apache Cordova</h1> + <div id="deviceready" class="blink"> + <p class="event listening">Connecting to Device</p> + <p class="event received">Device is Ready</p> + </div> + </div> + <script type="text/javascript" src="cordova-2.1.0.js"></script> + <script type="text/javascript" src="js/index.js"></script> + <script type="text/javascript"> + app.initialize(); + </script> + </body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/js/index.js ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/js/index.js b/spec/fixtures/projects/native/ios/www/js/index.js new file mode 100644 index 0000000..3b75d3f --- /dev/null +++ b/spec/fixtures/projects/native/ios/www/js/index.js @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +var app = { + // Application Constructor + initialize: function() { + this.bindEvents(); + }, + // Bind Event Listeners + // + // Bind any events that are required on startup. Common events are: + // `load`, `deviceready`, `offline`, and `online`. + bindEvents: function() { + document.addEventListener('deviceready', this.onDeviceReady, false); + }, + // deviceready Event Handler + // + // The scope of `this` is the event. In order to call the `receivedEvent` + // function, we must explicity call `app.receivedEvent(...);` + onDeviceReady: function() { + app.receivedEvent('deviceready'); + }, + // Update DOM on a Received Event + receivedEvent: function(id) { + var parentElement = document.getElementById(id); + var listeningElement = parentElement.querySelector('.listening'); + var receivedElement = parentElement.querySelector('.received'); + + listeningElement.setAttribute('style', 'display:none;'); + receivedElement.setAttribute('style', 'display:block;'); + + console.log('Received Event: ' + id); + } +}; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57-2x.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57-2x.png b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57-2x.png new file mode 100644 index 0000000..efd9c37 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57-2x.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57.png b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57.png new file mode 100644 index 0000000..c795fc4 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-57.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72-2x.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72-2x.png b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72-2x.png new file mode 100644 index 0000000..dd819da Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72-2x.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72.png b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72.png new file mode 100644 index 0000000..b1cfde7 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/icon/ios/icon-72.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape-2x.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape-2x.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape-2x.png new file mode 100644 index 0000000..95c542d Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape-2x.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape.png new file mode 100644 index 0000000..04be5ac Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-landscape.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait-2x.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait-2x.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait-2x.png new file mode 100644 index 0000000..aae1862 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait-2x.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait.png new file mode 100644 index 0000000..41e839d Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-ipad-portrait.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape-2x.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape-2x.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape-2x.png new file mode 100644 index 0000000..0165669 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape-2x.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape.png new file mode 100644 index 0000000..d154883 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-landscape.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait-2x.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait-2x.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait-2x.png new file mode 100644 index 0000000..bd24886 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait-2x.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait.png ---------------------------------------------------------------------- diff --git a/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait.png b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait.png new file mode 100644 index 0000000..6fcba56 Binary files /dev/null and b/spec/fixtures/projects/native/ios/www/res/screen/ios/screen-iphone-portrait.png differ http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/spec/platform.spec.js ---------------------------------------------------------------------- diff --git a/spec/platform.spec.js b/spec/platform.spec.js index 2f16d59..4e64731 100644 --- a/spec/platform.spec.js +++ b/spec/platform.spec.js @@ -4,6 +4,8 @@ var cordova = require('../cordova'), path = require('path'), rmrf = wrench.rmdirSyncRecursive, fs = require('fs'), + et = require('elementtree'), + config_parser = require('../src/config_parser'), tempDir = path.join(__dirname, '..', 'temp'); var cwd = process.cwd(); @@ -14,7 +16,6 @@ describe('platform command', function() { try { rmrf(tempDir); } catch(e) {} mkdirp(tempDir); }); - it('should run inside a Cordova-based project', function() { this.after(function() { process.chdir(cwd); @@ -43,6 +44,7 @@ describe('platform command', function() { describe('`ls`', function() { beforeEach(function() { cordova.create(tempDir); + process.chdir(tempDir); }); afterEach(function() { @@ -50,8 +52,6 @@ describe('platform command', function() { }); it('should list out no platforms for a fresh project', function() { - process.chdir(tempDir); - expect(cordova.platform('ls')).toEqual('No platforms added. Use `cordova platform add <platform>`.'); }); @@ -59,7 +59,6 @@ describe('platform command', function() { var cbtwo = jasmine.createSpy(); var cb = jasmine.createSpy(); - process.chdir(tempDir); runs(function() { cordova.platform('add', 'android', cb); }); @@ -78,6 +77,7 @@ describe('platform command', function() { describe('`add`', function() { beforeEach(function() { cordova.create(tempDir); + process.chdir(tempDir); }); afterEach(function() { @@ -85,6 +85,7 @@ describe('platform command', function() { }); describe('without any libraries cloned', function() { + // TODO! it('should clone down and checkout the correct android library'); it('should clone down and checkout the correct ios library'); it('should add a basic android project'); @@ -95,7 +96,6 @@ describe('platform command', function() { it('should add a basic android project', function() { var cb = jasmine.createSpy(); - process.chdir(tempDir); runs(function() { cordova.platform('add', 'android', cb); }); @@ -104,13 +104,26 @@ describe('platform command', function() { expect(fs.existsSync(path.join(tempDir, 'platforms', 'android', 'AndroidManifest.xml'))).toBe(true); }); }); - }); + it('should use the correct application name based on what is in config.xml', function() { + var cfg = new config_parser(path.join(tempDir, 'www', 'config.xml')); + var cb = jasmine.createSpy(); + runs(function() { + cfg.name('chim chim'); + cordova.platform('add', 'android', cb); + }); + waitsFor(function() { return cb.wasCalled; }, "platform add android callback"); + runs(function() { + var strings = new et.ElementTree(et.XML(fs.readFileSync(path.join(tempDir, 'platforms', 'android', 'res', 'values', 'strings.xml'), 'utf-8'))); + var app_name = strings.find('string[@name="app_name"]').text; + expect(app_name).toBe('chim chim'); + }); + }); + }); describe('ios', function() { it('should add a basic ios project', function() { var cb = jasmine.createSpy(); - process.chdir(tempDir); runs(function() { cordova.platform('add', 'ios', cb); }); @@ -121,10 +134,10 @@ describe('platform command', function() { }); }); }); - describe('remove', function() { beforeEach(function() { cordova.create(tempDir); + process.chdir(tempDir); }); afterEach(function() { @@ -135,7 +148,6 @@ describe('platform command', function() { var cb = jasmine.createSpy(); var cbone = jasmine.createSpy(); - process.chdir(tempDir); runs(function() { cordova.platform('add', 'ios', cbone); }); http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/src/metadata/android_parser.js ---------------------------------------------------------------------- diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js new file mode 100644 index 0000000..edb58c9 --- /dev/null +++ b/src/metadata/android_parser.js @@ -0,0 +1,24 @@ +var fs = require('fs'), + path = require('path'), + et = require('elementtree'), + config_parser = require('../config_parser'); + +module.exports = function android_parser(project) { + if (!fs.existsSync(path.join(project, 'AndroidManifest.xml'))) { + throw 'The provided path is not an Android project.'; + } + this.path = project; + this.strings = path.join(this.path, 'res', 'values', 'strings.xml') +}; + +module.exports.prototype = { + update_from_config:function(config) { + if (config instanceof config_parser) { + } else throw 'update_from_config requires a config_parser object'; + + var name = config.name(); + var strings = new et.ElementTree(et.XML(fs.readFileSync(this.strings, 'utf-8'))); + strings.find('string[@name="app_name"]').text = name; + fs.writeFileSync(this.strings, strings.write(), 'utf-8'); + } +}; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/src/metadata/ios_parser.js ---------------------------------------------------------------------- diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js new file mode 100644 index 0000000..becf5fa --- /dev/null +++ b/src/metadata/ios_parser.js @@ -0,0 +1,39 @@ +var fs = require('fs'), + path = require('path'), + xcode = require('node-xcode'), + asyncblock = require('asyncblock'), + config_parser = require('../config_parser'); + +module.exports = function ios_parser(project) { + try { + this.xcodeproj = fs.readdirSync(project).filter(function(e) { return e.match(/\.xcodeproj$/i); })[0]; + } catch(e) { + throw 'The provided path is not a Cordova iOS project.'; + } + this.path = project; + this.pbxproj = path.join(this.xcodeproj, 'project.pbxproj'); +}; + +module.exports.prototype = { + update_from_config:function(config) { + if (config instanceof config_parser) { + } else throw 'update_from_config requires a config_parser object'; + + var name = config.name(); + + var proj = new xcode(this.pbxproj); + asyncblock(function(flow) { + proj.parse(flow.set({ + key:'parse', + firstArgIsError:false, + responseFormat:['err','hash'] + })); + var parse = flow.get('parse'); + if (parse.err) throw 'An error occured during parsing of project.pbxproj. Start weeping.'; + else { + proj.updateProductName(name); + fs.writeFileSync(this.pbxproj, proj.writeSync(), 'utf-8'); + } + }); + } +}; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/132a9631/src/platform.js ---------------------------------------------------------------------- diff --git a/src/platform.js b/src/platform.js index a140036..f9c06e3 100644 --- a/src/platform.js +++ b/src/platform.js @@ -6,6 +6,7 @@ var config_parser = require('./config_parser'), rmrf = wrench.rmdirSyncRecursive, exec = require('child_process').exec, path = require('path'), + android_parser= require('./metadata/android_parser'), asyncblock = require('asyncblock'); var repos = { @@ -90,6 +91,8 @@ module.exports = function platform(command, target, callback) { } else { switch(target) { case 'android': + var android = new android_parser(output); + android.update_from_config(cfg); break; case 'ios': break;