Created
February 24, 2014 21:51
-
-
Save gbmoretti/9197932 to your computer and use it in GitHub Desktop.
Pamela
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- layouts/application.html.erb --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<%= stylesheet_link_tag "application" %> | |
</head> | |
<body data-controller="<%= controller_name %>" data-view="<%= action_name %>"> | |
<%= yield %> | |
<!-- Scripts Js --> | |
<%= javascript_include_tag "application" %> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/assets/javascript/application/app/posts/index.js | |
window.defineAction('posts','index',function() { | |
console.log('estou em posts#index'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.defineAction = function(controller,view,fn) { | |
window[controller] = window[controller] || {}; | |
if(window[controller][view] !== undefined) { | |
new Error(controller+'#'+view + ' function already defined.'); | |
}else { | |
window[controller][view] = fn; | |
} | |
}; | |
window.onload = function() { | |
//get controller and action from body data-attribute | |
var body = window.document.getElementsByTagName('body')[0]; | |
var controller = body.dataset.controller; | |
var action = body.dataset.view; | |
if(window[controller][action] !== undefined) { | |
window[controller][action](); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment