Created
March 7, 2012 13:16
-
-
Save shreyas-satish/1993044 to your computer and use it in GitHub Desktop.
Better Organization of Assets in the Rails Asset Pipeline
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Citizenmatters</title> | |
<%= stylesheet_link_tag :application, params[:controller] %> | |
<%= javascript_include_tag :application, params[:controller] %> | |
<%= csrf_meta_tags %> | |
<%= yield :head %> | |
</head> | |
<body data-controller = "<%= controller_name %>" data-action = "<%= action_name %>"> | |
</body> | |
</html> |
This file contains hidden or 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
//= require jquery | |
//= require jquery_ujs | |
//= require script_loader | |
window.MYAPP_SCRIPTS = { | |
common: { | |
init: function() { | |
// Any script common to all views using this manifest | |
} | |
} | |
} | |
$( document ).ready( SCRIPTLOADER.init ); |
This file contains hidden or 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.MYAPP_SCRIPTS.events = { | |
init: function() { | |
// Script common to all actions in events | |
}, | |
new: function() { | |
// Script only for the new action in events | |
}, | |
edit: function() { | |
// Script only for the new action in events | |
} | |
} |
This file contains hidden or 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
MYAPP_SCRIPTLOADER = { | |
exec: function( options ) { | |
var controller = options.controller, | |
action = options.action || "init"; | |
if ( controller !== "" && MYAPP_SCRIPTS[controller] && typeof MYAPP_SCRIPTS[controller][action] == "function" ) { | |
MYAPP_SCRIPTS[controller][action](); | |
} | |
}, | |
init: function() { | |
var body = document.body, | |
controller = body.getAttribute("data-controller"), | |
action = body.getAttribute("data-action"); | |
MYAPP_SCRIPTLOADER.exec({controller: "common" }); | |
MYAPP_SCRIPTLOADER.exec({controller: controller}); | |
MYAPP_SCRIPTLOADER.exec({controller: controller, action: action}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment