Permalink
Browse files

Added a namespace for all classes. Modified jammit.yml to package cla…

…sses in proper order. Fixed watcher classes to put files in subfolders.
  • Loading branch information...
1 parent 345488e commit a0042218d7b404a31f01b836031ca24c5d9ef711 @brikis98 committed May 16, 2011
@@ -1 +1,2 @@
-console.log 'hello there'
+$ ->
+ console.log 'Put any bootstrap code here, such as creating your backbone models, controllers and views.'
@@ -0,0 +1 @@
+window.NameSpace = {} # Change "NameSpace" to an appropriate name for all your classes
View
Binary file not shown.
View
@@ -1,4 +0,0 @@
-(function() {
- var MapModel;
- MapModel = Backbone.Model.extend();
-}).call(this);
View
@@ -1,3 +0,0 @@
-(function() {
- console.log('hello there');
-}).call(this);
View
@@ -1,4 +0,0 @@
-window.templates || (window.templates = {});
-window.templates.index = function(obj) {
-var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<html>\n <head>\n \n </head>\n <body>\n Hello World\n </body>\n</html>');}return __p.join('');
-};
View
@@ -3,8 +3,10 @@ gzip_assets: off
javascripts:
assets:
- - lib/jquery-1.6.1.min.js
- - lib/underscore-min.js
- - lib/backbone-min.js
- - compiled/*.js
+ - dependencies/jquery-1.6.1.min.js
+ - dependencies/underscore-min.js
+ - dependencies/backbone-min.js
+ - compiled/namespace.js
+ - compiled/lib/*.js
+ - compiled/mvc/*.js
- compiled/bootstrap.js
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,7 @@
+class Foo
+ constructor: (@bar) ->
+
+ explain: ->
+ console.log 'Put your own custom libraries/classes in this package'
+
+NameSpace.Foo = Foo # Add them to your namespace
View
@@ -0,0 +1,3 @@
+NameSpace.FooModel = Backbone.Model.extend
+ defaults:
+ foo: 'bar'
View
@@ -1 +0,0 @@
-MapModel = Backbone.Model.extend()
View
Binary file not shown.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -13,15 +13,15 @@ app = express.createServer()
app.configure 'development', ->
app.use express.static(path.join(__dirname, PUBLIC))
app.use express.errorHandler(dumpExceptions: true, showStack: true)
- watch.watch templates, _, 'templates', 'compiled', '.html', true
+ watch.watch templates, _, './templates', './compiled/mvc', '.html', false
app.configure 'production', ->
oneYear = 1000 * 60 * 60 * 24 * 365
app.use express.static(path.join(__dirname, PUBLIC), maxAge: oneYear)
app.use express.errorHandler()
- watch.watch templates, _, 'templates', 'compiled', '.html', false
+ watch.watch templates, _, 'templates', 'compiled', '.html', true
app.get '/', (req, res) ->
- res.send templates['index'] {}
+ res.send templates['index']()
app.listen 8003
View
@@ -1,34 +0,0 @@
-(function() {
- var PUBLIC, app, express, path, templates, watch, _;
- express = require('express');
- path = require('path');
- _ = require('underscore');
- watch = require('./util/watch');
- PUBLIC = './public';
- templates = {};
- _.templateSettings = {
- interpolate: /\{(.+?)\}/g
- };
- app = express.createServer();
- app.configure('development', function() {
- app.use(express.static(path.join(__dirname, PUBLIC)));
- app.use(express.errorHandler({
- dumpExceptions: true,
- showStack: true
- }));
- return watch.watch(templates, _, 'templates', 'compiled', '.html', true);
- });
- app.configure('production', function() {
- var oneYear;
- oneYear = 1000 * 60 * 60 * 24 * 365;
- app.use(express.static(path.join(__dirname, PUBLIC), {
- maxAge: oneYear
- }));
- app.use(express.errorHandler());
- return watch.watch(templates, _, 'templates', 'compiled', '.html', false);
- });
- app.get('/', function(req, res) {
- return res.send(templates['index']({}));
- });
- app.listen(8003);
-}).call(this);
View
@@ -2,26 +2,28 @@ var fs = require('fs');
var path = require('path');
var watchTree = require('watch-tree');
-exports.watch = function(templatesObject, _, templateDir, outputDir, templateExtension, doWrite) {
- // Compile all templates at start-up
- var templates = fs.readdirSync(templateDir);
- _.each(templates, function(template) { compileTemplate(path.join(templateDir, template)); });
+exports.watch = function(templatesObject, _, templateDir, outputDir, templateExtension, isProduction) {
+ // Compile all templates at start-up
+ var templates = fs.readdirSync(templateDir);
+ _.each(templates, function(template) { compileTemplate(path.join(templateDir, template)); });
- // Watch the templates directory and recompile them if a file changes or is created
- var watcher = watchTree.watchTree(templateDir, {'sample-rate': 500});
- watcher.on('fileModified', function(path) { compileTemplate(path); });
- watcher.on('fileCreated', function(path) { compileTemplate(path); });
+ if (isProduction) {
+ // Watch the templates directory and recompile them if a file changes or is created
+ var watcher = watchTree.watchTree(templateDir, {'sample-rate': 500});
+ watcher.on('fileModified', function(path) { compileTemplate(path); });
+ watcher.on('fileCreated', function(path) { compileTemplate(path); });
+ }
- function compileTemplate(file) {
- if (file && path.extname(file) == templateExtension) {
- console.log('Recompiling: ' + file);
- var templateName = path.basename(file, templateExtension);
- var compiled = _.template(fs.readFileSync(file, 'UTF-8'));
- templatesObject[templateName] = compiled;
- if (doWrite) {
- var asString = compiled.toString().replace('function anonymous', 'window.templates || (window.templates = {});\nwindow.templates.' + templateName + ' = function') + ';';
- fs.writeFileSync(path.join(outputDir, templateName + '.js'), asString);
- }
- }
- }
+ function compileTemplate(file) {
+ if (file && path.extname(file) == templateExtension) {
+ console.log('Recompiling: ' + file);
+ var templateName = path.basename(file, templateExtension);
+ var compiled = _.template(fs.readFileSync(file, 'UTF-8'));
+ templatesObject[templateName] = compiled;
+ if (isProduction) {
+ var asString = compiled.toString().replace('function anonymous', 'window.templates || (window.templates = {});\nwindow.templates.' + templateName + ' = function') + ';';
+ fs.writeFileSync(path.join(outputDir, templateName + '.js'), asString);
+ }
+ }
+ }
}
View
@@ -3,10 +3,15 @@
class JammitWatch
def self.compile(base, relative)
+ puts "base = #{base}, relative = #{relative}"
if relative == 'server.coffee'
`coffee --output . --compile server.coffee`
- elsif File.extname(relative) == '.coffee'
+ elsif base.end_with? 'bootstrap'
`coffee --output compiled --compile #{File.join(base, relative)}`
+ elsif base.end_with? 'lib'
+ `coffee --output compiled/lib --compile #{File.join(base, relative)}`
+ elsif File.extname(relative) == '.coffee'
+ `coffee --output compiled/mvc --compile #{File.join(base, relative)}`
elsif File.extname(relative) == '.js'
`jammit -c config/jammit.yml -o public/js`
else
@@ -21,21 +26,22 @@ def self.monitor
'controllers' => '**/*.coffee',
'models' => '**/*.coffee',
'views' => '**/*.coffee',
+ 'lib' => '**/*.coffee',
'compiled' => '**/*.js'
}
- FSSM.monitor do |monitor|
- paths.each do |path, glob|
- monitor.path path do |path|
- path.glob glob
-
+ FSSM.monitor do |monitor|
+ paths.each do |path, glob|
+ monitor.path path do |path|
+ path.glob glob
+
path.update { |base, relative|
puts "Change detected in #{base}/#{relative}"
JammitWatch.compile(base, relative)
- }
- end
- end
- end
+ }
+ end
+ end
+ end
end
end

0 comments on commit a004221

Please sign in to comment.