Permalink
Browse files

Updated controllers to be routers. Bumped underscore and jQuery, fixe…

…d bugs with new project missing app/templates.
  • Loading branch information...
bnolan committed May 14, 2012
1 parent f7189a4 commit 6dcddc5e6499eeac98de2cd2c515bfe43bf12558
View
@@ -4,9 +4,3 @@ root = __dirname + "/.."
require("coffee-script")
require(root + "/src/main.coffee")
-//
-// var path = require('path');
-// var fs = require('fs');
-// var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
-//
-// require(lib + '/cake').run();
View
@@ -1,7 +1,7 @@
{
"name": "capt",
"description": "Command line tool for creating backbone.js applications with coffeescript",
- "version": "0.5.5",
+ "version": "0.5.6",
"keywords": ["jst", "templates", "rest", "backbone", "jquery", "zepto", "framework", "coffeescript", "less", "underscore"],
"homepage": "http://bnolan.github.com/capt/",
"author": "Ben Nolan <ben@nolanconsul.com>, twitter: @bnolan",
View
@@ -34,7 +34,7 @@ Usage:
Code generators:
* capt generate model post
- * capt generate controller posts
+ * capt generate router posts
* capt generate view posts show
@@ -135,7 +135,7 @@ task 'new', 'create a new project', (arguments) ->
sys.puts " * Creating folders"
- dirs = ["", "spec", "spec/jasmine", "spec/models", "spec/controllers", "spec/views", "app", "app/views", "app/views/templates", "app/controllers", "app/models", "lib", "public", "public/stylesheets", "spec/fixtures"]
+ dirs = ["", "spec", "spec/jasmine", "spec/models", "spec/routers", "spec/views", "app", "app/views", "app/templates", "app/routers", "app/models", "lib", "public", "public/stylesheets", "spec/fixtures"]
for dir in dirs
fs.mkdirSync "#{project}/#{dir}", 0755
@@ -147,7 +147,7 @@ task 'new', 'create a new project', (arguments) ->
"lib/underscore.js" : "lib/underscore.js"
"lib/backbone.js" : "lib/backbone.js"
"lib/less.js" : "lib/less.js"
- "app/controllers/application.coffee" : "controllers/application.coffee"
+ "app/routers/application.coffee" : "routers/application.coffee"
"spec/jasmine/jasmine-html.js" : "lib/jasmine-html.js"
"spec/jasmine/jasmine.css" : "lib/jasmine.css"
"spec/jasmine/jasmine.js" : "lib/jasmine.js"
@@ -207,51 +207,52 @@ task 'generate collection', 'create a new collection', (arguments) ->
copyFile "#{root}/templates/collection/spec.coffee", "spec/models/#{model}_collection.#{project.language()}"
-task 'generate controller', 'create a new controller', (arguments) ->
+task 'generate router', 'create a new router', (arguments) ->
project = new Project(process.cwd())
if arguments[0]
- controller = arguments[0].toLowerCase()
+ router = arguments[0].toLowerCase()
else
- raise("Must supply a name for the controller")
+ raise("Must supply a name for the router")
copyFile = (from, to) ->
ejs = fs.readFileSync(from) + ""
- fs.writeFileSync(Path.join(project.root, to), _.template(ejs, { project : project, controller : controller }))
+ fs.writeFileSync(Path.join(project.root, to), _.template(ejs, { project : project, router : router }))
sys.puts " * Created #{to}"
try
- fs.mkdirSync "#{project.root}/app/views/#{controller}", 0755
- fs.mkdirSync "#{project.root}/app/templates/#{controller}", 0755
+ fs.mkdirSync "#{project.root}/app/views/#{router}", 0755
+ fs.mkdirSync "#{project.root}/spec/views/#{router}", 0755
+ fs.mkdirSync "#{project.root}/app/templates/#{router}", 0755
catch e
# ...
- copyFile "#{root}/templates/controllers/controller.coffee", "app/controllers/#{controller}_controller.#{project.language()}"
- copyFile "#{root}/templates/controllers/spec.coffee", "spec/controllers/#{controller}_controller.#{project.language()}"
+ copyFile "#{root}/templates/routers/router.coffee", "app/routers/#{router}_router.#{project.language()}"
+ copyFile "#{root}/templates/routers/spec.coffee", "spec/routers/#{router}_router.#{project.language()}"
task 'generate view', 'create a new view', (arguments) ->
project = new Project(process.cwd())
if arguments[0] and arguments[1]
- controller = arguments[0].toLowerCase()
+ router = arguments[0].toLowerCase()
view = arguments[1].toLowerCase()
else
- raise("Must supply a name for the controller and then view")
+ raise("Must supply a name for the router and then view")
copyFile = (from, to) ->
ejs = fs.readFileSync(from).toString()
- fs.writeFileSync(Path.join(project.root, to), _.template(ejs, { project : project, controller: controller, view : view }))
+ fs.writeFileSync(Path.join(project.root, to), _.template(ejs, { project : project, router: router, view : view }))
sys.puts " * Created #{to}"
- if !Path.existsSync("#{project.root}/app/views/#{controller}")
- fs.mkdirSync "#{project.root}/app/views/#{controller}", 0755
+ if !Path.existsSync("#{project.root}/app/views/#{router}")
+ fs.mkdirSync "#{project.root}/app/views/#{router}", 0755
- if !Path.existsSync("#{project.root}/app/templates/#{controller}")
- fs.mkdirSync "#{project.root}/app/templates/#{controller}", 0755
+ if !Path.existsSync("#{project.root}/app/templates/#{router}")
+ fs.mkdirSync "#{project.root}/app/templates/#{router}", 0755
- copyFile "#{root}/templates/views/view.coffee", "app/views/#{controller}/#{view}.#{project.language()}"
- copyFile "#{root}/templates/templates/template.eco", "app/templates/#{controller}/#{view}.eco"
- copyFile "#{root}/templates/views/spec.coffee", "spec/views/#{controller}/#{view}.#{project.language()}"
+ copyFile "#{root}/templates/views/view.coffee", "app/views/#{router}/#{view}.#{project.language()}"
+ copyFile "#{root}/templates/templates/template.eco", "app/templates/#{router}/#{view}.eco"
+ copyFile "#{root}/templates/views/spec.coffee", "spec/views/#{router}/#{view}.#{project.language()}"
# task 'spec', 'run the specs', (arguments) ->
# project = new Project(process.cwd())
View
@@ -164,8 +164,8 @@ class Project
for script in @getDependencies('specs')
tags.push @getScriptTagFor(Path.join("..", script))
- for script in @getDependencies('fixtures')
- tags.push @getScriptTagFor(Path.join("..", script))
+ # for script in @getDependencies('fixtures')
+ # tags.push @getScriptTagFor(Path.join("..", script))
tags.join("\n ")
@@ -197,7 +197,7 @@ class Project
[].concat(
@getDependencies('static')
@getDependencies('specs')
- @getDependencies('fixtures')
+ # @getDependencies('fixtures')
@getScriptDependencies()
@getStylesheetDependencies()
)
@@ -231,54 +231,54 @@ class Project
fs.writeFileSync Path.join(@root, outpath), css.toCSS()
# Compile xml fixtures
- _compileXml : (file) ->
- fs.readFile Path.join(@root, file), "utf-8", (err, code) =>
- throw err if err
-
- path = Path.join(Path.dirname(file), ".js")
- outpath = Path.join(path, Path.basename(file, ".xml") + ".js")
-
- try
- fs.mkdirSync Path.join(@root, path), 0755
- catch e
- # .. ok ..
-
- templateName = [
- Path.dirname(file).split("/").pop().toLowerCase()
- Path.basename(file, ".xml").capitalize()
- ].join("")
-
- output = "if(!this.$fixtures){\n $fixtures={};\n};\n\n" +
- "this.$fixtures.#{templateName}=$(\"" +
- code.replace(/"/g,"\\\"").replace(/\n/g,"\\n") +
- "\");"
-
- sys.puts " * Compiled " + outpath
- fs.writeFileSync Path.join(@root, outpath), output
+ # _compileXml : (file) ->
+ # fs.readFile Path.join(@root, file), "utf-8", (err, code) =>
+ # throw err if err
+ #
+ # path = Path.join(Path.dirname(file), ".js")
+ # outpath = Path.join(path, Path.basename(file, ".xml") + ".js")
+ #
+ # try
+ # fs.mkdirSync Path.join(@root, path), 0755
+ # catch e
+ # # .. ok ..
+ #
+ # templateName = [
+ # Path.dirname(file).split("/").pop().toLowerCase()
+ # Path.basename(file, ".xml").capitalize()
+ # ].join("")
+ #
+ # output = "if(!this.$fixtures){\n $fixtures={};\n};\n\n" +
+ # "this.$fixtures.#{templateName}=$(\"" +
+ # code.replace(/"/g,"\\\"").replace(/\n/g,"\\n") +
+ # "\");"
+ #
+ # sys.puts " * Compiled " + outpath
+ # fs.writeFileSync Path.join(@root, outpath), output
# Compile json fixtures
- _compileJson : (file) ->
- fs.readFile Path.join(@root, file), "utf-8", (err, code) =>
- throw err if err
-
- path = Path.join(Path.dirname(file), ".js")
- outpath = Path.join(path, Path.basename(file, ".json") + ".js")
-
- try
- fs.mkdirSync Path.join(@root, path), 0755
- catch e
- # .. ok ..
-
- templateName = [
- Path.dirname(file).split("/").pop().toLowerCase()
- Path.basename(file, ".json").capitalize()
- ].join("")
-
- output = "if(!this.$fixtures){\n $fixtures={};\n};\n\n" +
- "this.$fixtures.#{templateName}=" + code.toString() + ";"
-
- sys.puts " * Compiled " + outpath
- fs.writeFileSync Path.join(@root, outpath), output
+ # _compileJson : (file) ->
+ # fs.readFile Path.join(@root, file), "utf-8", (err, code) =>
+ # throw err if err
+ #
+ # path = Path.join(Path.dirname(file), ".js")
+ # outpath = Path.join(path, Path.basename(file, ".json") + ".js")
+ #
+ # try
+ # fs.mkdirSync Path.join(@root, path), 0755
+ # catch e
+ # # .. ok ..
+ #
+ # templateName = [
+ # Path.dirname(file).split("/").pop().toLowerCase()
+ # Path.basename(file, ".json").capitalize()
+ # ].join("")
+ #
+ # output = "if(!this.$fixtures){\n $fixtures={};\n};\n\n" +
+ # "this.$fixtures.#{templateName}=" + code.toString() + ";"
+ #
+ # sys.puts " * Compiled " + outpath
+ # fs.writeFileSync Path.join(@root, outpath), output
_compileCoffee : (file) ->
fs.readFile Path.join(@root, file), (err, code) =>
View
No changes.
View
@@ -14,5 +14,8 @@ specs:
- 'spec/*/*.coffee'
- 'spec/views/*/*.coffee'
+fixtures:
+
templates:
+ - 'app/templates/*.eco'
- 'app/templates/*/*.eco'
@@ -1,11 +0,0 @@
-class <%= controller.capitalize() %>Controller extends Backbone.Controller
- routes :
- "<%= controller %>/:id/edit" : "edit"
- "<%= controller %>/new" : "new"
- "<%= controller %>/:id" : "show"
- "<%= controller %>" : "index"
-
- index: ->
- # new <%= controller.capitalize() %>IndexView
-
-@<%= controller.capitalize() %>Controller = <%= controller.capitalize() %>Controller
@@ -1,19 +0,0 @@
-describe '<%= controller %> controller', ->
-
- it 'should handle the truth', ->
- expect(true).toBeTruthy()
-
- it 'should exist', ->
- expect(<%= controller.capitalize() %>Controller).toBeTruthy()
-
- it 'should instantiate', ->
- x = new <%= controller.capitalize() %>Controller
- expect(x instanceof <%= controller.capitalize() %>Controller).toBeTruthy()
- expect(x instanceof Backbone.Controller).toBeTruthy()
-
- it 'should have index method', ->
- x = new <%= controller.capitalize() %>Controller
- x.index()
-
- # Umm..?
- expect(true).toBeTruthy()
Oops, something went wrong.

0 comments on commit 6dcddc5

Please sign in to comment.