Skip to content

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Dec 24, 2014
1 parent 302295e commit c3cd274
Show file tree
Hide file tree
Showing 78 changed files with 109 additions and 234 deletions.
1 change: 0 additions & 1 deletion routing-flags-roles/definitions/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ framework.onAuthorization = function(req, res, flags, callback) {

// I add role flag
flags.push('@' + get.user);

callback(true);
}
else
Expand Down
4 changes: 2 additions & 2 deletions routing-flags/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exports.install = function(framework) {

framework.route('/', view_homepage);
framework.route('/', view_index);

// [+xhr] - you can execute "view_subpage" with request type: XMLHttpRequest or classic GET/HTTP
framework.route('/sub/', view_subpage, ['+xhr']);
Expand Down Expand Up @@ -40,7 +40,7 @@ function myflag_example() {
self.view404();
};

function view_homepage() {
function view_index() {
this.plain('GET - homepage');
}

Expand Down
7 changes: 3 additions & 4 deletions routing-resize/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
framework.route('/', function() {
var self = this;
self.view('homepage');
});
exports.install = function() {
framework.route('/');
};
4 changes: 2 additions & 2 deletions routing-resize/definitions/resize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
framework.resize('/img/small/', 100, 100, {}, '/img/');
framework.resize('/img/grayscale/', null, null, { grayscale: true }, '/img/');
framework.resize('/img/grayscale/', null, null, { cache: false, grayscale: true }, '/img/');
framework.resize('/img/filters/', null, null, { blur: true, sepia: true, flip: true, flop: true }, '/img/');
framework.resize('/img/50percent/', '50%', null, {}, '/img/');
framework.resize('/img/medium/', '70%', null, {}, '/img/', ['.png']);
framework.resize('/img/medium/', '70%', null, {}, '/img/', ['.png']);
File renamed without changes.
13 changes: 5 additions & 8 deletions routing-timeout/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
exports.install = function(framework) {

// Documentation: http://docs.totaljs.com/Framework/#framework.route
exports.install = function() {
framework.route('/', timeout);

framework.route('/quick/', timeout, { timeout: 100 });

// Request timeout
framework.route('#408', view_408)
// Request timeout (define timeout page)
framework.route('#408', view_408);
}

function timeout() {
// I forgotten to call a view()
// I forgot to call the view
}

function view_408() {
Expand Down
10 changes: 4 additions & 6 deletions scheduler/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var counter = 0;

exports.install = function(framework) {
framework.route('/', view_homepage);
exports.install = function() {
framework.route('/', plain_index);

// This event is triggered every 60 seconds.

Expand All @@ -12,14 +12,12 @@ exports.install = function(framework) {
// or

/*
setInterval(function() {
counter++;
}, 1000);
*/
};

function view_homepage() {
this.plain('Scheduler ran: ' + counter);
function plain_index() {
this.plain('Scheduler run counter: ' + counter);
}
9 changes: 2 additions & 7 deletions server-sent-events/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
exports.install = function(framework) {
framework.route('/', view_homepage);
exports.install = function() {
framework.route('/');
framework.route('/one-way-messaging/', view_SSE, ['sse']);
};

function view_homepage() {
var self = this;
self.view('homepage');
}

function view_SSE() {

var self = this;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion session-cluster-redis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for (var i = 0; i < numCPUs; i++) {
fork.send({ type: 'id', id: i });
}

console.log('Cluster is running.');
console.log('The cluster is running.');

function onMessage(message) {
console.log('Message ->', message);
Expand Down
8 changes: 4 additions & 4 deletions session/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
exports.install = function(framework) {
exports.install = function() {

framework.route('/', view_homepage, ['#session']);
framework.route('/', view_index, ['#session']);

// Or set a global middleware
// framework.use('session');
};

function view_homepage() {
function view_index() {
var self = this;

if (typeof(self.session.counter) === 'undefined')
self.session.counter = 0;
self.session.counter++;

self.view('homepage');
self.view('index');
}
3 changes: 1 addition & 2 deletions session/definitions/modules.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

// Install session module
framework.install('module', 'https://modules.totaljs.com/session/v1.00/session.js');
INSTALL('module', 'https://modules.totaljs.com/session/v1.00/session.js');
2 changes: 1 addition & 1 deletion session/views/homepage.html → session/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Passport.js</title>
<title>Session Middleware</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<meta name="format-detection" content="telephone=no"/>
Expand Down
9 changes: 2 additions & 7 deletions static-crossdomain/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
exports.install = function(framework) {
framework.route('/', view_homepage);
};

function view_homepage() {
var self = this;
self.view('homepage');
}
framework.route('/');
};
3 changes: 0 additions & 3 deletions static-crossdomain/views/homepage.html

This file was deleted.

3 changes: 3 additions & 0 deletions static-crossdomain/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>CSS: @{routeStyle('style.css')}</div>
<div>JS: @{routeScript('script.js')}</div>
<div>IMG: @{routeImage('logo.png')}</div>
File renamed without changes.
16 changes: 2 additions & 14 deletions static-file-handling/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
exports.install = function(framework) {
framework.route('/', view_homepage);
framework.route('/');
framework.file('All (.jpg, .png, .gif) images', image_resize);
};

function view_homepage() {
this.view('homepage');
}

function image_resize(req, res, isValidation) {

if (isValidation)
return req.url.contains(['.jpg', '.png', '.gif']);

// generate response
// this === framework
// Documentation: http://docs.totaljs.com/Framework/#framework.responseImage
framework.responseImage(req, res, this.path.public(req.url), function (image) {

// image === FrameworkImage
// http://docs.totaljs.com/FrameworkImage/

image.resize('50%');
image.quality(80);
image.minify();

});

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</head>
<body>

<h1>Resizing of all images about 50%</h1>
<h1>Resize all images for 50%</h1>

<h2>GIF</h2>
<div><img src="/img/biker.gif" /></div>
Expand Down
8 changes: 0 additions & 8 deletions static-version/controllers/default.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>CSS: @{routeCSS('style.css')}</div>
<div>JS: @{routeJS('script.js')}</div>
<div>CSS: @{routeStyle('style.css')}</div>
<div>JS: @{routeScript('script.js')}</div>
<div>IMG: @{routeImage('logo.png')}</div>
<div>IMG (CUSTOM): @{routeImage('custom.png')}</div>
File renamed without changes.
7 changes: 3 additions & 4 deletions upload-multipart/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
exports.install = function(framework) {
exports.install = function() {
framework.route('/', view_homepage);

// the number is maximum data receive
framework.route('/', view_homepage, { flags: ['upload'], length: 1024 * 20 }); // 1 === 1 kB
framework.route('/', view_homepage, ['upload'], 100); // 100 kB
};

function view_homepage() {
var self = this;

var model = { info: '...' };

// self.files array of HttpFile === http://docs.totaljs.com/HttpFile/
if (self.files.length > 0)
model.info = self.files[0].filename + ' ({0} kB - {1}x{2})'.format(Math.floor(self.files[0].length / 1024, 2), self.files[0].width, self.files[0].height);

self.view('homepage', model);
self.view('index', model);
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions validation-custom/controllers/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function view_homepage() {
var self = this;

if (!self.xhr) {
self.view('homepage', { LoginName: '@' });
self.view('index', { LoginName: '@' });
return;
}

Expand All @@ -19,7 +19,7 @@ function view_homepage() {
var errorBuilder = new builders.ErrorBuilder(resource);

// Documentation: http://docs.totaljs.com/FrameworkUtils/#utils.validate
if (utils.validate(self.body, ['FirstName', 'LastName', 'Age', 'Email', 'Terms'], onValidation, errorBuilder).hasError()) {
if (Utils.validate(self.body, ['FirstName', 'LastName', 'Age', 'Email', 'Terms'], onValidation, errorBuilder).hasError()) {
self.json(errorBuilder);
return;
}
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions validation/controllers/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ function view_homepage() {

if (!self.xhr) {
self.meta('Validation example');
self.view('homepage', { LoginName: '@' });
self.view('index', { LoginName: '@' });
return;
}

// Look here: https://github.com/totaljs/examples/tree/master/framework-schema-validation
// Documentation: http://docs.totaljs.com/FrameworkController/#controller.validate
var result = self.validate(self.post, ['FirstName', 'LastName', 'Age', 'Email', 'Terms'], 'Form');

// Documentation: http://docs.totaljs.com/Builders.ErrorBuilder/
// Documentation: ErrorBuilder
if (result.hasError()) {
result.replace('@Email', self.post.Email);
self.json(result);
Expand Down
2 changes: 0 additions & 2 deletions validation/definitions/validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

// Global validation
// Look here: https://github.com/petersirka/total.js/tree/master/examples/framework-schema
framework.onValidation = function(name, value) {

switch (name) {
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 3 additions & 8 deletions video-streaming/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
exports.install = function(framework) {
framework.route('/', view_homepage);
};

function view_homepage() {
var self = this;
self.view('homepage');
}
exports.install = function() {
framework.route('/');
};
4 changes: 0 additions & 4 deletions video-streaming/views/homepage.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@{layout('')}

<!DOCTYPE html>
<html>
<head>
Expand All @@ -8,6 +10,10 @@
<meta name="robots" content="all,follow" />
</head>
<body>
@{body}

<video width="320" height="240" controls="controls" autoplay="autoplay">
<source src="@{routeVideo('movie.mp4')}" type="video/mp4">
<source src="@{routeVideo('movie.ogg')}" type="video/ogg">
</video>
</body>
</html>
9 changes: 2 additions & 7 deletions views-current/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
exports.install = function(framework) {
framework.route('/', view_homepage);
exports.install = function() {
framework.route('/');
framework.route('/sub/', view_subpage);
};

function view_homepage() {
var self = this;
self.view('homepage');
}

function view_subpage() {

var self = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
currentJS();
currentCSS();
currentScript();
currentStyle();
currentVideo();
currentDownload();
currentImage();
Expand Down
File renamed without changes.
11 changes: 3 additions & 8 deletions views-custom-helper/controllers/default.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
exports.install = function(framework) {
framework.route('/', view_homepage);
};

function view_homepage() {
var self = this;
self.view('homepage');
}
exports.install = function() {
framework.route('/');
};
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit c3cd274

Please sign in to comment.