Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

new: archetype for hybrid app/mojit combo #606

Closed
wants to merge 16 commits into from

1 participant

@isao
  • add lib/app/archetypes/app/hybrid/* which contains both an app and mojit template/scaffolding; primarily for hybrid html5app configs
  • tweak create.js so usage text reflects new mojito create app hybrid subtype
  • remove lingering remnant of create project
isao added some commits
@isao isao make web page fetch error non-fatal 73e4552
@isao isao redo hybrid/html5app archtype from scratch
these files are copied from template-app, and I'll edit to
include things from the docs and crt post-processing script
d88c2eb
@isao isao app.json
- rename
- add hb template placeholders
- add configs from docs
bdf11de
@isao isao package.json rname, add {{name}}, etc 4d4c986
@isao isao routes rename, add mojit route,, {{name}} eb74069
@isao isao rm shell-based template, add hb stuff 60da949
@isao isao rm readme c701587
@isao isao update controller, binder, model
- use "top_frame" name/prefix
- rename .hb
655078b
@isao isao rename reformat {{name}} + yahoo.mojito.package: public f410cf0
@isao isao redo test archetypes again with top_frame, not {{name}} 2dec13b
@isao isao mv archetype (avoids needing create.js changes)
new: `mojito create app hybrid` command creates a mojito
application and a top_frame HTMLFrameMojit with configs
useful for hybrid Html5App/Cocktails-Runtime development
ff33e62
@isao isao update `mojito create` usage
- add usage text for `create app hybrid`
- remove remnants of non-functional, long-gone `create project`
59da488
@isao isao de-lint ce3f7ad
@isao isao rm optional config that is part of a separate change 139a12d
@isao isao rm old external script 6d3691c
@isao

This change for mojito create app hybrid creates an app that contains a mojit named "top_frame". This is different from mojito create app [simple,default,full] which only create the app, and the mojit is created in a second step. However, this was the requirement I was given.

@isao

n.b. if archetypes include binder tests, mojito test app . fails with dom on nodejs error; fixed for pre-existing archetypes in pull #607

@isao isao closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 9, 2012
  1. @isao
  2. @isao

    redo hybrid/html5app archtype from scratch

    isao authored
    these files are copied from template-app, and I'll edit to
    include things from the docs and crt post-processing script
  3. @isao

    app.json

    isao authored
    - rename
    - add hb template placeholders
    - add configs from docs
  4. @isao
  5. @isao
  6. @isao
  7. @isao

    rm readme

    isao authored
  8. @isao

    update controller, binder, model

    isao authored
    - use "top_frame" name/prefix
    - rename .hb
  9. @isao
  10. @isao
  11. @isao

    mv archetype (avoids needing create.js changes)

    isao authored
    new: `mojito create app hybrid` command creates a mojito
    application and a top_frame HTMLFrameMojit with configs
    useful for hybrid Html5App/Cocktails-Runtime development
  12. @isao

    update `mojito create` usage

    isao authored
    - add usage text for `create app hybrid`
    - remove remnants of non-functional, long-gone `create project`
  13. @isao

    de-lint

    isao authored
  14. @isao
  15. @isao

    rm old external script

    isao authored
  16. @isao

    rm dummy binder test

    isao authored
This page is out of date. Refresh to see the latest.
View
45 lib/app/archetypes/app/hybrid/application.json.hb
@@ -0,0 +1,45 @@
+[
+ {
+ "settings": [ "master" ],
+ "appPort": 8666,
+ "builds": {
+ "html5app": {
+ "urls": ["/yahoo.application.{{name}}/index.html"]
+ }
+ },
+ "cacheViewTemplates": true,
+ "deferAllOptionalAutoload": false,
+ "embedJsFilesInHtmlFrame": false,
+ "log": {
+ "client": {
+ "level": "info",
+ "yui": false
+ },
+ "server": {
+ "level": "info",
+ "yui": false
+ }
+ },
+ "shareYUIInstance": true,
+ "tunnelPrefix": "/tunnel/",
+ "staticHandling": {
+ "appName": "yahoo.{{name}}.application",
+ "cache": false,
+ "frameworkName": "yahoo.{{name}}.mojito",
+ "prefix": "",
+ "useRollups": false
+ },
+ "yui": {
+ "dependencyCalculations": "precomputed"
+ }
+ },
+
+ {
+ "settings": [ "environment:dev" ],
+ "yui": {
+ "base": "/yahoo.libs.yui/",
+ "url": "$$yui.base$$yui/yui-min.js",
+ "loader": "loader/loader-min.js"
+ }
+ }
+]
View
BIN  lib/app/archetypes/app/hybrid/assets/favicon.ico
Binary file not shown
View
17 lib/app/archetypes/app/hybrid/index.js
@@ -0,0 +1,17 @@
+/*jslint nomen: true, unparam: true, sloppy: true, node: true */
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+// this file provides Manhattan integration
+
+process.chdir(__dirname);
+
+/**
+ * @token given by manhattan and used to emit that the app is ready
+ */
+module.exports = function (config, token) {
+ var app = require('./server.js');
+
+ // send the application to Manhattan along with the token
+ process.emit("application-ready", token, app);
+};
View
57 lib/app/archetypes/app/hybrid/mojits/top_frame/binders/index.js.hb
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('top_frameBinderIndex', function(Y, NAME) {
+
+/**
+ * The top_frameBinderIndex module.
+ *
+ * @module top_frameBinderIndex
+ */
+
+ /**
+ * Constructor for the top_frameBinderIndex class.
+ *
+ * @class top_frameBinderIndex
+ * @constructor
+ */
+ Y.namespace('mojito.binders')[NAME] = {
+
+ /**
+ * Binder initialization method, invoked after all binders on the page
+ * have been constructed.
+ */
+ init: function(mojitProxy) {
+ this.mojitProxy = mojitProxy;
+ },
+
+ /**
+ * The binder method, invoked to allow the mojit to attach DOM event
+ * handlers.
+ *
+ * @param node {Node} The DOM node to which this mojit is attached.
+ */
+ bind: function(node) {
+ var me = this;
+ this.node = node;
+ /**
+ * Example code for the bind method:
+ *
+ * node.all('dt').on('mouseenter', function(evt) {
+ * var dd = '#dd_' + evt.target.get('text');
+ * me.node.one(dd).addClass('sel');
+ *
+ * });
+ * node.all('dt').on('mouseleave', function(evt) {
+ *
+ * var dd = '#dd_' + evt.target.get('text');
+ * me.node.one(dd).removeClass('sel');
+ *
+ * });
+ */
+ }
+
+ };
+
+}, '0.0.1', {requires: ['event-mouseenter', 'mojito-client']});
View
47 lib/app/archetypes/app/hybrid/mojits/top_frame/controller.server.js.hb
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('top_frame', function(Y, NAME) {
+
+/**
+ * The top_frame module.
+ *
+ * @module top_frame
+ */
+
+ /**
+ * Constructor for the Controller class.
+ *
+ * @class Controller
+ * @constructor
+ */
+ Y.namespace('mojito.controllers')[NAME] = {
+
+ init: function(config) {
+ this.config = config;
+ },
+
+ /**
+ * Method corresponding to the 'index' action.
+ *
+ * @param ac {Object} The ActionContext that provides access
+ * to the Mojito API.
+ */
+ index: function(ac) {
+ ac.models.top_frameModelFoo.getData(function(err, data) {
+ if (err) {
+ ac.error(err);
+ return;
+ }
+ ac.assets.addCss('./index.css');
+ ac.done({
+ status: 'Mojito is working.',
+ data: data
+ });
+ });
+ }
+
+ };
+
+}, '0.0.1', {requires: ['mojito', 'top_frameModelFoo']});
View
5 lib/app/archetypes/app/hybrid/mojits/top_frame/definition.json
@@ -0,0 +1,5 @@
+[
+ {
+ "settings": [ "master" ]
+ }
+]
View
37 lib/app/archetypes/app/hybrid/mojits/top_frame/models/foo.server.js.hb
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('top_frameModelFoo', function(Y, NAME) {
+
+/**
+ * The top_frameModelFoo module.
+ *
+ * @module top_frame
+ */
+
+ /**
+ * Constructor for the top_frameModelFoo class.
+ *
+ * @class top_frameModelFoo
+ * @constructor
+ */
+ Y.namespace('mojito.models')[NAME] = {
+
+ init: function(config) {
+ this.config = config;
+ },
+
+ /**
+ * Method that will be invoked by the mojit controller to obtain data.
+ *
+ * @param callback {function(err,data)} The callback function to call when the
+ * data has been retrieved.
+ */
+ getData: function(callback) {
+ callback(null, { some: 'data' });
+ }
+
+ };
+
+}, '0.0.1', {requires: []});
View
26 lib/app/archetypes/app/hybrid/mojits/top_frame/package.json.hb
@@ -0,0 +1,26 @@
+{
+ "name": "yahoo.{{name}}.top_frame",
+ "version": "0.0.1",
+ "pkg_type": "frame",
+ "description": "The {{name}} application's top frame (HTMLFrameMojit)",
+ "dependencies": {
+ "mojito": ">0.4"
+ },
+ "engines": {
+ "node": ">0.6",
+ "npm": ">1.0",
+ "mojito": ">0.4"
+ },
+ "maintainers": [
+ {
+ "email": "yourname@yahoo-inc.com",
+ "name": "Your Name"
+ }
+ ],
+ "yahoo": {
+ "mojito": {
+ "package": "public",
+ "version": ">0.4"
+ }
+ }
+}
View
19 lib/app/archetypes/app/hybrid/mojits/top_frame/specs/default.json
@@ -0,0 +1,19 @@
+[
+ {
+ "settings": [ "master" ],
+
+ "type": "HTMLFrameMojit",
+ "config": {
+ "deploy": true,
+ "title": "template App",
+ "child": {
+ "type": "yahoo._template_.top_frame"
+ },
+ "assets": {
+ "bottom": {
+ "js": ["/yahoo.ychrome.lib/yui-cfg.js"]
+ }
+ }
+ }
+ }
+]
View
62 lib/app/archetypes/app/hybrid/mojits/top_frame/tests/controller.server-tests.js
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+
+YUI.add('top_frame-tests', function(Y) {
+
+ var suite = new YUITest.TestSuite('top_frame-tests'),
+ controller = null,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'top_frame user tests',
+
+ setUp: function() {
+ controller = Y.mojito.controllers.top_frame;
+ },
+ tearDown: function() {
+ controller = null;
+ },
+
+ 'test mojit': function() {
+ var ac,
+ modelData,
+ assetsResults,
+ doneResults;
+ modelData = { x:'y' };
+ ac = {
+ assets: {
+ addCss: function(css) {
+ assetsResults = css;
+ }
+ },
+ models: {
+ top_frameModelFoo: {
+ getData: function(cb) {
+ cb(null, modelData);
+ }
+ }
+ },
+ done: function(data) {
+ doneResults = data;
+ }
+ };
+
+ A.isNotNull(controller);
+ A.isFunction(controller.index);
+ controller.index(ac);
+ A.areSame('./index.css', assetsResults);
+ A.isObject(doneResults);
+ A.areSame('Mojito is working.', doneResults.status);
+ A.isObject(doneResults.data);
+ A.isTrue(doneResults.data.hasOwnProperty('x'));
+ A.areEqual('y', doneResults.data['x']);
+
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'top_frame']});
View
39 lib/app/archetypes/app/hybrid/mojits/top_frame/tests/models/model.server-tests.js
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+
+YUI.add('top_frameModelFoo-tests', function(Y, NAME) {
+
+ var suite = new YUITest.TestSuite(NAME),
+ model = null,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'top_frameModelFoo user tests',
+
+ setUp: function() {
+ model = Y.mojito.models.top_frameModelFoo;
+ },
+ tearDown: function() {
+ model = null;
+ },
+
+ 'test mojit model': function() {
+ var called = false;
+ A.isNotNull(model);
+ A.isFunction(model.getData);
+ model.getData(function(err, data) {
+ called = true;
+ A.isTrue(!err);
+ A.isObject(data);
+ A.areSame('data', data.some);
+ });
+ A.isTrue(called);
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'top_frameModelFoo']});
View
3  lib/app/archetypes/app/hybrid/mojits/top_frame/views/index.mu.html
@@ -0,0 +1,3 @@
+<div id="{{mojit_view_id}}">
+ <p>Hello Template</p>
+</div>
View
18 lib/app/archetypes/app/hybrid/package.json.hb
@@ -0,0 +1,18 @@
+{
+ "name": "yahoo.application.{{name}}",
+ "author": "Your Name <you@yahoo-inc.com>",
+ "description": "This application's main package: yahoo.application.{{name}}",
+ "version": "0.0.1",
+ "pkg_type": "application",
+ "dependencies": {
+ "mojito": ">0.4"
+ },
+ "engines": {
+ "node": ">0.6",
+ "npm": ">1.0",
+ "mojito": ">0.4"
+ },
+ "scripts": {
+ "start": "mojito start"
+ }
+}
View
23 lib/app/archetypes/app/hybrid/routes.json.hb
@@ -0,0 +1,23 @@
+[
+ {
+ "settings": [ "master" ],
+
+ "top_frame_view": {
+ "verbs": ["get"],
+ "path": "/",
+ "call": "yahoo.{{name}}.top_frame.index"
+ },
+
+ "default-for-html5app": {
+ "verbs": ["get"],
+ "path": "/yahoo.application.{{name}}/index.html",
+ "call": "yahoo.{{name}}.top_frame.index"
+ },
+
+ "by-mojit-action": {
+ "verbs": [ "GET" ],
+ "path": "/:module/:action",
+ "call": "{module}.{action}"
+ }
+ }
+]
View
5 lib/app/archetypes/app/hybrid/server.js
@@ -0,0 +1,5 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+
+module.exports = require('mojito').createServer();
View
2  lib/app/commands/build.js
@@ -501,7 +501,7 @@ writeWebPagesToFiles = function(destination, urls, config, callback) {
if (err) {
utils.error('FAILED to get ' + url + ' with error:\n' +
- err, null, true);
+ err, null, false);
} else {
if (config.attachManifest) {
content = attachManifest(destination, urls[url],
View
73 lib/app/commands/create.js
@@ -36,20 +36,28 @@ var path = require('path'),
Y.applyConfig({useSync: false});
-usage = 'mojito create {type} [archetype] {name} [options]\n' +
- "\t- type: 'app', 'mojit', or 'project'\n" +
- '\t- archetype: (optional) template to use for creation\n' +
- '\t- name: given name for creation\n\n' +
- 'Example Usage: mojito create app foo\n' +
- "\t(creates directory 'foo' containing new Mojito application)\n" +
- 'Example Usage: mojito create mojit Bar\n' +
- "\t(creates directory 'Bar' containing new Mojit)\n\n" +
- 'OPTIONS: \n' +
- '\t --port [number]: ' +
- 'Provides a default port for your Mojito app to run within.\n' +
- '\t -p [number]: Short for --port\n' +
- '\t--force: Forced mojit creation even outside a Mojito app.\n' +
- '\t -f: Short for --force\n';
+usage = [
+ 'mojito create {type} [archetype] {name} [options]',
+ ' - type: "app" or "mojit"',
+ ' - archetype: optional template. Possible values are default, full, simple',
+ ' "app" types also have a "hybrid" archtype which creates an app and a',
+ ' mojit with common configurations for use with hybrid app.',
+ ' - name: name of the app or mojit to create',
+ '',
+ 'Example: mojito create app Foo',
+ " (creates directory 'Foo' containing new Mojito application)",
+ '',
+ 'Example: mojito create mojit Bar',
+ ' (creates directory "Bar" containing new Mojit)',
+ '',
+ 'Example: mojito create app hybrid Baz',
+ ' (creates directory "Baz" containing new hybrid app and mojit)',
+ '',
+ 'OPTIONS: ',
+ ' --port [number] Specifies default port for your Mojito app to run on.',
+ ' -p [number] Short for --port',
+ ' --force Forced mojit creation even outside a Mojito app.',
+ ' -f Short for --force'].join("\n");
var createApp = function(archetype, destdir, inputs, force, callback) {
@@ -92,39 +100,6 @@ var createMojit = function(archetype, destdir, inputs, force, callback) {
};
-var createProject = function(archetype, destdir, inputs, force, callback) {
-
- var type = 'project',
- name = inputs.name,
- data = {
- name: name
- },
- config;
-
- // Are we in a Mojito App? (We need the application.json file to make this
- // work)
- try {
- config = Y.JSON.parse(String(fs.readFileSync(path.join(process.cwd(),
- 'application.json'))));
- config = config[0];
- } catch (err) {
- // there is no application.json
- return utils.error('You need to be in a Mojito application directory' +
- ' that has an \'application.json\' file.');
- }
-
- utils.makeDir(path.join(process.cwd(), 'artifacts/projects/', archetype));
- destdir = path.join('artifacts/projects/', archetype, destdir);
-
- utils.process_directory(path.join(archetypePath, type, archetype), '/',
- destdir, data, force);
-
- utils.success(type + ': ' + name + ' created!');
-
- callback();
-};
-
-
function run(params, options, callback) {
var type = params[0],
@@ -146,10 +121,6 @@ function run(params, options, callback) {
type = 'mojit';
create = createMojit;
break;
- case 'PROJECT':
- type = 'project';
- create = createProject;
- break;
default:
type = null;
}
Something went wrong with that request. Please try again.