Skip to content

Instantly share code, notes, and snippets.

@rafamvc
Created February 16, 2012 16:02
Show Gist options
  • Save rafamvc/1846006 to your computer and use it in GitHub Desktop.
Save rafamvc/1846006 to your computer and use it in GitHub Desktop.

Revisions

  1. rafamvc revised this gist Mar 27, 2012. 2 changed files with 4 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions bcontroller_name.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    RELASPHERE.<controller_name> = {
    MY_APP.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
    @@ -12,4 +12,4 @@ RELASPHERE.<controller_name> = {
    edit: function() {
    // Your code for the edit page goes here
    }
    }
    }
    4 changes: 2 additions & 2 deletions controller_name.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    RELASPHERE.<controller_name> = {
    MY_APP.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
    @@ -12,4 +12,4 @@ RELASPHERE.<controller_name> = {
    edit: function() {
    // Your code for the edit page goes here
    }
    }
    }
  2. Rafael Cardoso renamed this gist Feb 16, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Rafael Cardoso revised this gist Feb 16, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Where you see RELASPHERE you should use MY_APP on the controller_name.js. Somehow github doesnt let me edit that file because of the name.
  4. Rafael Cardoso renamed this gist Feb 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion acontroller_name.js → controller_name.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    MY_APP.<controller_name> = {
    RELASPHERE.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
  5. Rafael Cardoso revised this gist Feb 16, 2012. No changes.
  6. Rafael Cardoso revised this gist Feb 16, 2012. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions bcontroller_name.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // On the page specific file:
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    RELASPHERE.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
    index: function() {
    // Your code for the index page goes here
    },
    edit: function() {
    // Your code for the edit page goes here
    }
    }
  7. Rafael Cardoso renamed this gist Feb 16, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. Rafael Cardoso revised this gist Feb 16, 2012. No changes.
  9. Rafael Cardoso revised this gist Feb 16, 2012. No changes.
  10. Rafael Cardoso revised this gist Feb 16, 2012. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions controller_name.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // On the page specific file:
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    MY_APP.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
    index: function() {
    // Your code for the index page goes here
    },
    edit: function() {
    // Your code for the edit page goes here
    }
    }
  11. Rafael Cardoso revised this gist Feb 16, 2012. 3 changed files with 19 additions and 18 deletions.
    15 changes: 15 additions & 0 deletions <controller_name>.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // On the page specific file:
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    RELASPHERE.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
    index: function() {
    // Your code for the index page goes here
    },
    edit: function() {
    // Your code for the edit page goes here
    }
    }
    4 changes: 4 additions & 0 deletions application.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <html>
    <body data-controller="<%= controller_name %>" data-action="<%= action_name %>" class='<%= controller_name %>'>
    </body>
    </html>
    18 changes: 0 additions & 18 deletions init.js
    Original file line number Diff line number Diff line change
    @@ -24,21 +24,3 @@ UTIL = {
    };

    $( document ).ready( UTIL.init );



    // On the page specific file:
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    RELASPHERE.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
    index: function() {
    // Your code for the index page goes here
    },
    edit: function() {
    // Your code for the edit page goes here
    }
    }
  12. Rafael Cardoso revised this gist Feb 16, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions init.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // This global variable will hold all your page specific functions
    // I know that global vars suck, but I think this is a good and safe exception
    MY_APP = {
    };

  13. Rafael Cardoso revised this gist Feb 16, 2012. 1 changed file with 21 additions and 10 deletions.
    31 changes: 21 additions & 10 deletions init.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,9 @@
    RELASPHERE = {
    common: {
    init: function() {
    // application-wide code
    depress_menu_button();
    }
    }
    MY_APP = {
    };

    UTIL = {
    exec: function( controller, action ) {
    var ns = RELASPHERE,
    var ns = MY_APP,
    action = ( action === undefined ) ? "init" : action;

    if ( controller !== "" && ns[controller] && typeof ns[controller][action] == "function" ) {
    @@ -22,10 +16,27 @@ UTIL = {
    controller = body.getAttribute( "data-controller" ),
    action = body.getAttribute( "data-action" );

    UTIL.exec( "common" );
    UTIL.exec( controller );
    UTIL.exec( controller, action );
    }
    };

    $( document ).ready( UTIL.init );
    $( document ).ready( UTIL.init );



    // On the page specific file:
    // "<controller_name>.js", and you import it after the init.js on your application.js
    // Replace the <controller_name> with the actual name

    RELASPHERE.<controller_name> = {
    init: function() {
    // Your shared code for the whole controller goes here
    },
    index: function() {
    // Your code for the index page goes here
    },
    edit: function() {
    // Your code for the edit page goes here
    }
    }
  14. Rafael Cardoso created this gist Feb 16, 2012.
    31 changes: 31 additions & 0 deletions init.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    RELASPHERE = {
    common: {
    init: function() {
    // application-wide code
    depress_menu_button();
    }
    }
    };

    UTIL = {
    exec: function( controller, action ) {
    var ns = RELASPHERE,
    action = ( action === undefined ) ? "init" : action;

    if ( controller !== "" && ns[controller] && typeof ns[controller][action] == "function" ) {
    ns[controller][action]();
    }
    },

    init: function() {
    var body = document.body,
    controller = body.getAttribute( "data-controller" ),
    action = body.getAttribute( "data-action" );

    UTIL.exec( "common" );
    UTIL.exec( controller );
    UTIL.exec( controller, action );
    }
    };

    $( document ).ready( UTIL.init );