Created
May 23, 2012 11:45
-
-
Save spalladino/2774757 to your computer and use it in GitHub Desktop.
Organizing coffeescript code in a Rails 3 app
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
if $('#my_div_in_complex_page').length > 0 | |
class Foo | |
... |
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
# on a global functions file | |
@onComplexFunctionality = (callback) -> $(-> callback() if $('#my_div_in_complex_page').length > 0) | |
# when you need to use it | |
onComplexFunctionality > | |
class Foo | |
... |
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
Site.users.index = () -> | |
# your code for users/index here... |
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
<body data-controller="<%= controller_name %>" data-action="<%= action_name %>"> |
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
class window.Foo | |
# your code for the class... |
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
class @Foo | |
# your code for the class... |
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
# in file A.js.coffee | |
class @A extends B | |
# fails because B has not been defined yet | |
# in file B.js.coffee | |
class @B | |
# is defined after A as this file is processed after A.js.coffee |
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
# in file A.js.coffee | |
#= require B | |
class @A extends B | |
... | |
# in file B.js.coffee | |
class @B | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you have a missing hyphen "-" at blog02.js.coffee line 5
https://gist.github.com/spalladino/2774757#file-blog02-js-coffee-L5