Permalink
Browse files

initial commit

  • Loading branch information...
Sam Breed
Sam Breed committed Jul 3, 2011
0 parents commit 68e5ba85ead4896f0bdb2dd2c01684d247f47603
Showing with 587 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +48 −0 Cakefile
  3. +3 −0 example/templates.js
  4. +2 −0 example/templates/sample.jst
  5. +495 −0 lib/jquery.tmpl.js
  6. +19 −0 package.json
  7. +13 −0 readme.md
@@ -0,0 +1,7 @@
+.DS_Store
+.rvmrc
+.bundle/*
+tmp/
+node_modules/
+.DS_Store?
+**/*/.DS_Store
@@ -0,0 +1,48 @@
+fs = require 'fs'
+{exec} = require 'child_process'
+util = require 'util'
+$ = require './lib/jquery.tmpl.js'
+
+templatesDir = 'example/templates'
+targetDir = 'example'
+
+task 'watch', 'Watch prod source files and build changes', ->
+ invoke 'build'
+ util.log "Watching for changes in #{templatesDir}"
+ templates = fs.readdirSync(templatesDir)
+
+ for file in templates then do (file) ->
+ fs.watchFile "#{templatesDir}/#{file}", (curr, prev) ->
+ if +curr.mtime isnt +prev.mtime
+ util.log "Saw change in #{templatesDir}/#{file}"
+
+task 'build', 'Pre compile jQuery Templates', ->
+ templates = fs.readdirSync(templatesDir)
+ remaining = templates.length
+ data = []
+
+ for tmpl, index in templates then do (tmpl, index) ->
+ fs.readFile "#{templatesDir}/#{tmpl}" , 'utf8'
+ , (err, fileContents) ->
+ handleError(err) if err
+ nm = tmpl.split('.')[0]
+ tmp = [
+ "JST.#{nm} = "
+ $.template(null, fileContents)
+ ";"
+ ]
+
+ data[index] = tmp.join('')
+ process( data ) if --remaining is 0
+
+ process = ( data )->
+ fileData = "(function($,window){ var JST = {}; #{ data.join('\n\n') } window.JST = JST; })(jQuery,window);"
+
+ fs.writeFile "#{targetDir}/templates.js", fileData, 'utf8', (err) ->
+ handleError(err) if err
+ util.log "#{targetDir}/templates.js written"
+
+handleError = (error) ->
+ util.log error
+ displayNotification error
+

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,2 @@
+<h1>${title}</h1>
+<p>This is a sample template</p>
Oops, something went wrong.

0 comments on commit 68e5ba8

Please sign in to comment.