Javascriptに変換する前にCakefileを使用して連結するCoffeeScriptファイルがいくつかあります。連結されたCoffeScriptファイルをJQueryondocument ready関数でラップするにはどうすればよいですか?
例えば:
次のCoffeScriptファイルがあり、それぞれにクラスが含まれています。
foo.coffee bar.coffee tea.coffee
JSファイルを作成するには、次のCakeコマンドを使用してコーヒーを連結し、JSを作成します。
task 'build', 'Build single application file from source files', ->
appContents = new Array remaining = appFiles.length
for file, index in appFiles then do (file, index) ->
fs.readFile "#{file}.coffee", 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
process() if --remaining is 0
process = ->
fs.writeFile '../assets/js/app.coffee', appContents.join('\n\n'), 'utf8', (err) ->
throw err if err
exec 'coffee --compile ../assets/js/app.coffee', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
fs.unlink '../assets/js/app.coffee', (err) ->
throw err if err
console.log 'Done.'
これにより、次のような素敵なJSファイルが生成されます。
// Generated by CoffeeScript 1.3.3
(function() {
...all the code...
}).call(this);
次のようなready関数のJQueryですべてのコードをラップするにはどうすればよいですか?
(function() {
$(document).ready(function() {
...all the code...
});
}).call(this);
したがって、基本的には、ドキュメントの準備ができた後に実行するすべての連結コードが必要です。
サブ質問これを行う正しい方法を私が求めているのは何ですか?代わりに、各CoffeeScriptファイルに含まれる各クラスをon document ready関数でラップする必要がありますか?
どんな助けでも大歓迎です、私はこれに対する答えを無駄にどのようにそして低く検索しました。
ありがとうございました!