Skip to content

Commit

Permalink
merge with Mikes example changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tim committed May 17, 2014
2 parents 1fd88f4 + f1216f7 commit 4fe911c
Show file tree
Hide file tree
Showing 26 changed files with 480 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
build.json
build*
1 change: 0 additions & 1 deletion build-0.1.0.json

This file was deleted.

1 change: 0 additions & 1 deletion build-0.2.0.json

This file was deleted.

1 change: 1 addition & 0 deletions build010.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build020.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"readdirp": "~0.3.3",
"wrench": "~1.5.8",
"underscore": "~1.6.0",
"aws-sdk": "^2.0.0-rc.16"
"aws-sdk": "~2.0.0-rc.17"
}
}
23 changes: 14 additions & 9 deletions scripts/lessons.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ var s3 = new aws.S3();

module.exports = function(jsonFiles, examplesPath, cb) {
var lessons = {};
var json;
for (var i = 0; i < jsonFiles.length; i++) {
var filePath = path.resolve('./src/examples/', jsonFiles[i]);
var fileContents = fs.readFileSync(filePath, 'utf8');

var json = JSON.parse(fileContents);
json = JSON.parse(fileContents);

for (var version in json.versions) {
if (!lessons[version]) lessons[version] = {};
Expand All @@ -21,15 +22,18 @@ module.exports = function(jsonFiles, examplesPath, cb) {
var lessonData = createIndividualLesson(version, json.name, json.versions[version][example], examplesPath);
lessons[lessonData.id] = lessonData.data;

if (!lessons[version][lessonData.repo]) lessons[version][lessonData.repo] = {};
if (!lessons[version][lessonData.repo][lessonData.component]) lessons[version][lessonData.repo][lessonData.component] = [];
// if (!lessons[version][lessonData.repo]) lessons[version][lessonData.repo] = {};
// if (!lessons[version][lessonData.repo][lessonData.component]) lessons[version][lessonData.repo][lessonData.component] = [];

lessons[version][lessonData.repo][lessonData.component].push(lessonData.example);
if (!lessons[version][lessonData.component]) lessons[version][lessonData.component] = [];
lessons[version][lessonData.component].push(lessonData.example);
}
fs.writeFileSync('build-' + version + '.json', JSON.stringify(lessons[version]));
uploadFile('examples/build-' + version + '.json', 'build-' + version + '.json')
}
}

for (var version in json.versions) {
fs.writeFileSync('build' + version.replace(/\./g, '') + '.json', JSON.stringify(lessons[version]));
}
}

function uploadFile(remoteFilename, fileName) {
Expand Down Expand Up @@ -71,7 +75,7 @@ function createIndividualLesson(version, name, example, examplesPath) {
var temp = name.split('/');

var repo = temp[1];
var component = temp[2].toLowerCase();
var component = temp[2];
var exampleName = example.split('.')[0];

var id = [name, example].join('/');
Expand All @@ -81,7 +85,7 @@ function createIndividualLesson(version, name, example, examplesPath) {
var example = fs.readFileSync(filePath, "utf8")
var syntax = esprima.parse(example, { tokens: true, range: true, comment: true });

var baseWebsiteUrl = 'https://famo.us/examples'
var baseWebsiteUrl = '/examples'



Expand All @@ -90,7 +94,7 @@ function createIndividualLesson(version, name, example, examplesPath) {
component: component,
example: {
"name": exampleName,
"url": [baseWebsiteUrl, version, repo, component, exampleName].join('/'),
"url": [baseWebsiteUrl, version, repo, component.toLowerCase(), exampleName].join('/'),
"instruction": getComments(syntax, id),
"javascript": commentlessCode(example)
}
Expand Down Expand Up @@ -123,6 +127,7 @@ function getComments(syntax, name) {
return parsedComment;
});

console.log(name)
var result = parsedBlockComments[0]['description'];

return result;
Expand Down
63 changes: 63 additions & 0 deletions src/examples/inputs/GenericSync/accumulator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* GenericSync
* ------------
*
* GenericSync combines multiple types of event handling
* (e.g. touch, trackpad scrolling) into one standardized
* interface for inclusion in widgets. TouchSync and ScrollSync
* are enabled by default.
*
* In this example, we create a GenericSync that listens to
* TouchSync, ScrollSync, and MouseSync and displays the data
* it receives to the screen.
*
*/
define(function(require, exports, module) {
var Engine = require("famous/core/Engine");
var GenericSync = require("famous/inputs/GenericSync");
var MouseSync = require("famous/inputs/MouseSync");
var TouchSync = require("famous/inputs/TouchSync");
var ScrollSync = require("famous/inputs/ScrollSync");
var Surface = require("famous/core/Surface");
var Accumulator = require("famous/inputs/Accumulator");

var mainContext = Engine.createContext();

var update = 0;
var start = [0, 0];

GenericSync.register({
mouse : MouseSync,
touch : TouchSync,
scroll : ScrollSync
});

var accumulator = new Accumulator(start);
var genericSync = new GenericSync(['mouse', 'touch', 'scroll']);

Engine.pipe(genericSync);
genericSync.pipe(accumulator);

var contentTemplate = function() {
return "<div>Update Count: " + update + "</div>" +
"<div>Accumulated distance: " + accumulator.get() + "</div>";
};

var surface = new Surface({
size: [undefined, undefined],
classes: ['grey-bg'],
content: contentTemplate()
});

genericSync.on('start', function(){
accumulator.set(start);
surface.setContent(contentTemplate());
});

genericSync.on("update", function() {
update++;
surface.setContent(contentTemplate());
});

mainContext.add(surface);
});
23 changes: 14 additions & 9 deletions src/examples/inputs/GenericSync/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ define(function(require, exports, module) {
var start = 0;
var update = 0;
var end = 0;
var position = [0, 0];
var delta = [0,0];
var position = [0,0];

var genericSync = new GenericSync(function() {
return [0, 0];
}, {
syncClasses: [MouseSync, TouchSync, ScrollSync]
GenericSync.register({
mouse : MouseSync,
touch : TouchSync,
scroll : ScrollSync
});

var genericSync = new GenericSync(['mouse', 'touch', 'scroll']);

Engine.pipe(genericSync);

var contentTemplate = function() {
return "<div>Start Count: " + start + "</div>" +
"<div>End Count: " + end + "</div>" +
"<div>Update Count: " + update + "</div>" +
"<div>Distance away from mousedown/touch origin:<br>" + position + "</div>";
"<div>Delta: " + delta + "</div>" +
"<div>Distance from start: " + position + "</div>";
};

var surface = new Surface({
Expand All @@ -49,14 +54,14 @@ define(function(require, exports, module) {

genericSync.on("start", function() {
start++;
position = [0, 0];
position = [0,0];
surface.setContent(contentTemplate());
});

genericSync.on("update", function(data) {
update++;
position[0] += data.position[0];
position[1] += data.position[1];
position = data.position;
delta = data.delta;
surface.setContent(contentTemplate());
});

Expand Down
71 changes: 71 additions & 0 deletions src/examples/inputs/GenericSync/withOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* GenericSync
* ------------
*
* GenericSync combines multiple types of event handling
* (e.g. touch, trackpad scrolling) into one standardized
* interface for inclusion in widgets. TouchSync and ScrollSync
* are enabled by default.
*
* In this example, we create a GenericSync that listens to
* TouchSync, ScrollSync, and MouseSync and displays the data
* it receives to the screen.
*
*/
define(function(require, exports, module) {
var Engine = require("famous/core/Engine");
var GenericSync = require("famous/inputs/GenericSync");
var MouseSync = require("famous/inputs/MouseSync");
var TouchSync = require("famous/inputs/TouchSync");
var ScrollSync = require("famous/inputs/ScrollSync");
var Surface = require("famous/core/Surface");
var Accumulator = require("famous/inputs/Accumulator");

var mainContext = Engine.createContext();

var update = 0;
var start = 0;

GenericSync.register({
mouse : MouseSync,
touch : TouchSync,
scroll : ScrollSync
});

var accumulator = new Accumulator(start);

var genericSync = new GenericSync({
mouse : {
direction : GenericSync.DIRECTION_X,
scale : 2
},
touch : {direction : GenericSync.DIRECTION_Y},
scroll : {direction : GenericSync.DIRECTION_Y}
});

Engine.pipe(genericSync);
genericSync.pipe(accumulator);

var contentTemplate = function() {
return "<div>Update Count: " + update + "</div>" +
"<div>Accumulated distance: " + accumulator.get() + "</div>";
};

var surface = new Surface({
size: [undefined, undefined],
classes: ['grey-bg'],
content: contentTemplate()
});

genericSync.on('start', function(){
accumulator.set(start);
surface.setContent(contentTemplate());
});

genericSync.on("update", function() {
update++;
surface.setContent(contentTemplate());
});

mainContext.add(surface);
});
55 changes: 55 additions & 0 deletions src/examples/inputs/MouseSync/accumulator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* MouseSync
* ------------
*
* Famo.us syncs default to track two-dimensional movement,
* but can be passed as optional direction parameter to restrict
* movement to a single axis.
*
* In this example, we create a MouseSync but only track the x-axis
* changes on mouse drag.
*
*/
define(function(require, exports, module) {
var Engine = require("famous/core/Engine");
var MouseSync = require("famous/inputs/MouseSync");
var Surface = require("famous/core/Surface");
var Accumulator = require("famous/inputs/Accumulator");

var mainContext = Engine.createContext();

var update = 0;

var x = 0;
var y = 0;
var position = [x, y];

var mouseSync = new MouseSync();
var accumulator = new Accumulator(position);

Engine.pipe(mouseSync);
mouseSync.pipe(accumulator);

var contentTemplate = function() {
return "<div>Update Count: " + update + "</div>" +
"<div>Accumulated distance: " + accumulator.get() + "</div>";
};

var surface = new Surface({
size: [undefined, undefined],
classes: ["grey-bg"],
content: contentTemplate()
});

mouseSync.on("start", function() {
accumulator.set([x,y]);
surface.setContent(contentTemplate());
});

mouseSync.on("update", function() {
update++;
surface.setContent(contentTemplate());
});

mainContext.add(surface);
});
13 changes: 7 additions & 6 deletions src/examples/inputs/MouseSync/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ define(function(require, exports, module) {
var update = 0;
var end = 0;

var delta = [0,0];
var position = [0, 0];
var mouseSync = new MouseSync(function() {
return position;
});
var mouseSync = new MouseSync();

Engine.pipe(mouseSync);

var contentTemplate = function() {
return "<div>Start Count: " + start + "</div>" +
"<div>End Count: " + end + "</div>" +
"<div>Update Count: " + update + "</div>" +
"<div>Distance away from mousedown origin:<br>" + position + "</div>";
"<div>Delta: " + delta + "</div>" +
"<div>Distance from start: " + position + "</div>";
};

var surface = new Surface({
Expand All @@ -49,8 +49,9 @@ define(function(require, exports, module) {

mouseSync.on("update", function(data) {
update++;
position[0] += data.position[0];
position[1] += data.position[1];
position = data.position;
delta = data.delta;

surface.setContent(contentTemplate());
});

Expand Down
11 changes: 6 additions & 5 deletions src/examples/inputs/MouseSync/single-dimensional.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ define(function(require, exports, module) {
var start = 0;
var update = 0;
var end = 0;
var delta = 0;

var x = 0;
var y = 0;
var position = [x, y];

var mouseSync = new MouseSync(function() {
return x;
}, {direction : MouseSync.DIRECTION_X});
var mouseSync = new MouseSync({direction : MouseSync.DIRECTION_X});

Engine.pipe(mouseSync);

var contentTemplate = function() {
return "<div>Start Count: " + start + "</div>" +
"<div>End Count: " + end + "</div>" +
"<div>Update Count: " + update + "</div>" +
"<div>Distance away from mousedown origin:<br>" + position + "</div>";
"<div>Delta: " + delta + "</div>" +
"<div>Distance from start: " + position + "</div>";
};

var surface = new Surface({
Expand All @@ -52,7 +52,8 @@ define(function(require, exports, module) {

mouseSync.on("update", function(data) {
update++;
position[0] += data.position;
position[0] = data.position;
delta = data.delta;
surface.setContent(contentTemplate());
});

Expand Down
Loading

0 comments on commit 4fe911c

Please sign in to comment.