Skip to content
Permalink
Browse files

initial commit

  • Loading branch information...
bevacqua committed May 13, 2014
0 parents commit 65f54118205991710ce8cc5d0dcc6874fac21d4d
Showing with 235 additions and 0 deletions.
  1. +13 −0 .editorconfig
  2. +1 −0 .gitignore
  3. +20 −0 LICENSE
  4. +9 −0 README.md
  5. +6 −0 lib/Route.js
  6. +19 −0 lib/activator.js
  7. +17 −0 lib/boot.js
  8. +25 −0 lib/links.js
  9. +28 −0 lib/navigation.js
  10. +11 −0 lib/partial.js
  11. +47 −0 lib/router.js
  12. +5 −0 lib/state.js
  13. +26 −0 package.json
  14. +8 −0 ponymoo.js
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
@@ -0,0 +1 @@
node_modules
20 LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright © 2014 Nicolas Bevacqua

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
# ponymoo

> Micro MVC engine
`ponymoo` aims to simplify the state of MVC and shared rendering.

# License

MIT
@@ -0,0 +1,6 @@
'use strict';

function Route () {
}

module.exports = Route;
@@ -0,0 +1,19 @@
'use strict';

var router = require('./router');
var partial = require('./partial');
var navigation = require('./navigation');

function activator (url) {
var route = router(url);

route.fetch(activate);

function activate (model) {
document.title = model.title;
partial(state.container, route.template, route.controller, model);
navigation(url, model);
}
}

module.exports = activator;
@@ -0,0 +1,17 @@
'use strict';

var state = require('./state');
var router = require('./router');
var navigation = require('./navigation');

function boot (container, routes) {
var data = container.dataset.ponymoo;
var model = JSON.parse(data);

state.container = container;

router.setup(routes);
navigation.start(model);
}

module.exports = boot;
@@ -0,0 +1,25 @@
'use strict';

function links (element) {
var a = element.getElementsByTagName('a');
Array.prototype.slice.call(a).forEach(link);
}

function link (a) {
var url = a.href;
var route = getRoute(url);
if (route.key === void 0) {
return;
}

a.addEventListener('click', reroute);

function reroute (e) {
if (e.which === 1) { // left-click
activate(route.key, route.settings);
e.preventDefault();
}
}
}

module.exports = routeLinks;
@@ -0,0 +1,28 @@
'use strict';

var router = require('./router');
var state = require('./state');

function start (model) {
navigation(location.pathname, model, 'replaceState');
window.onpopstate = popState;
}

function popState (e) {
var empty = !(e || e.state || e.state.model);
if (empty) {
return;
}
navigation(location.pathname, e.state.model, 'replaceState');
}

function navigation (url, model, action) {
var route = router(url);
var state = { model: model };
history[action || 'pushState'](state, model.title, url);
route.controller(model);
}

navigation.start = start;

module.exports = navigation;
@@ -0,0 +1,11 @@
'use strict';

var links = require('./links');

function partial (container, template, controller, model) {
container.innerHTML = template(model);
links(container);
controller(model);
}

module.exports = partial;
@@ -0,0 +1,47 @@
'use strict';

var Route = require('./Route');

function router (url) {
return null;
}

function setup (routes) {
// routes..
// { controller, template, fetch, match }
}

router.setup = setup;

module.exports = router;
/*
function getRoute(url){
if(url === undefined){
return {};
}
var result = {
key: stringKeys[url]
};
if(result.key !== undefined){
return result;
}
$.each(regexKeys, function() {
var self = this,
captures = url.match(self.regex);
if (captures !== null){
result = {
key: self.key,
settings: {
key: self.alias.key,
data: self.alias.route.map(captures)
}
};
return false;
}
});
return result;
}
*/
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
container: null
};
@@ -0,0 +1,26 @@
{
"name": "ponymoo",
"description": "Micro MVC engine",
"version": "0.1.0",
"homepage": "https://github.com/bevacqua/ponymoo",
"authors": [
"Nicolas Bevacqua <nicolasbevacqua@gmail.com>"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/bevacqua/ponymoo.git"
},
"bugs": {
"url": "https://github.com/bevacqua/ponymoo/issues"
},
"main": "ponymoo.js",
"scripts": {
"lint": "jshint . --reporter node_modules/jshint-stylish/stylish.js",
"test": "npm run lint"
},
"devDependencies": {
"jshint": "^2.5.0",
"jshint-stylish": "^0.2.0"
}
}
@@ -0,0 +1,8 @@
'use strict';

var contra = require('contra');
var ponymoo = λ.emitter({
boot: require('./lib/boot')
});

module.exports = ponymoo;

0 comments on commit 65f5411

Please sign in to comment.
You can’t perform that action at this time.