Skip to content

Loading…

Port to CoffeeScript in cs-wip branch #206

Closed
wants to merge 9 commits into from

4 participants

@hwrod

Added /app/src/config.coffee to start

@gf3

This pull request is racist. Also sexist.

@hwrod

We still good to pull these commits, or does the boilerplate development tree structure need to change first?

@tbranyen
Owner

I think I might be able to provide this on-the-fly with scaffolding without needing a separate branch. Definitely want to consider CoffeeScript users.

@hwrod

Cool man, love my Coffee. Let me know if I can do anything for ya

@tbranyen
Owner

As much as I like Coffee and would like to see this flavor baked in, I'm not going to be able to maintain this along with the base JavaScript implementation. If you are able to fork and maintain the CoffeeScript flavor, I will of course endorse and link to it from the README.

Thanks again for your hard work, it is greatly appreciated :)

@tbranyen tbranyen closed this
@SBoudrias

Also, I plan on checking out a converter js/coffee when using the BBB Yeoman generator (Angular generator does this for you so it'll be a nice point for someone wanting to start BBB with coffeescript).

@hwrod

Sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2013
  1. @hwrod
  2. @hwrod
  3. @hwrod

    add autogenerated config.js

    hwrod committed
  4. @hwrod

    port app.js to coffee

    hwrod committed
Commits on Mar 15, 2013
  1. @hwrod

    port main.js to coffee

    hwrod committed
  2. @hwrod

    port router.js to coffee

    hwrod committed
  3. @hwrod

    move files around

    hwrod committed
  4. @hwrod

    port grunt.js to coffee

    hwrod committed
  5. @hwrod

    port tests from js to coffee

    hwrod committed
This page is out of date. Refresh to see the latest.
View
51 src/app/app.js
@@ -0,0 +1,51 @@
+// Generated by CoffeeScript 1.6.1
+(function() {
+
+ define(["backbone.layoutmanager"], function(LayoutManager) {
+ var JST, app;
+ app = {
+ root: "/"
+ };
+ JST = window.JST = window.JST || {};
+ LayoutManager.configure({
+ manage: true,
+ prefix: "app/templates/",
+ fetch: function(path) {
+ var done;
+ path = path + ".html";
+ if (JST[path]) {
+ return JST[path];
+ }
+ done = this.async();
+ return $.get(app.root + path, function(contents) {
+ return done(_.template(contents));
+ }, "text");
+ }
+ });
+ return _.extend(app, {
+ module: function(additionalProps) {
+ return _.extend({
+ Views: {}
+ }, additionalProps);
+ },
+ useLayout: function(name, options) {
+ if (_.isObject(name)) {
+ options = name;
+ }
+ options = options || {};
+ if (_.isString(name)) {
+ options.template = name;
+ }
+ if (this.layout) {
+ this.layout.template = options.template;
+ } else {
+ this.layout = new Backbone.Layout(_.extend({
+ el: "main"
+ }, options));
+ }
+ return this.layout;
+ }
+ }, Backbone.Events);
+ });
+
+}).call(this);
View
17 src/app/config.js
@@ -0,0 +1,17 @@
+// Generated by CoffeeScript 1.6.1
+(function() {
+
+ require.config({
+ deps: ["../vendor/jam/require.config", "main"],
+ paths: {
+ "lodash": "../vendor/jam/lodash/lodash.underscore"
+ },
+ map: {
+ "*": {
+ "underscore": "lodash"
+ }
+ },
+ shim: {}
+ });
+
+}).call(this);
View
24 src/app/main.js
@@ -0,0 +1,24 @@
+// Generated by CoffeeScript 1.6.1
+(function() {
+
+ require(["app", "router"], function(app, Router) {
+ app.router = new Router();
+ Backbone.history.start({
+ pushState: true,
+ root: app.root
+ });
+ return $(document).on("click", "a[href]:not([data-bypass])", function(evt) {
+ var href, root;
+ href = {
+ prop: $(this).prop("href"),
+ attr: $(this).attr("href")
+ };
+ root = location.protocol + "//" + location.host + app.root;
+ if (href.prop.slice(0, root.length) === root) {
+ evt.preventDefault();
+ return Backbone.history.navigate(href.attr, true);
+ }
+ });
+ });
+
+}).call(this);
View
15 src/app/router.js
@@ -0,0 +1,15 @@
+// Generated by CoffeeScript 1.6.1
+(function() {
+
+ define(["app"], function(app) {
+ var Router;
+ Router = Backbone.Router.extend({
+ routes: {
+ "": "index"
+ },
+ index: function() {}
+ });
+ return Router;
+ });
+
+}).call(this);
View
71 src/app/src/app.coffee
@@ -0,0 +1,71 @@
+define [
+ "backbone.layoutmanager"
+
+ # Include additional libraries installed with JamJS or placed in the
+ # `vendor/js` directory, here.
+],
+
+(LayoutManager) ->
+
+ # Provide a global location to place configuration settings and module
+ # creation.
+ app =
+ # The root path to run the application.
+ root: "/"
+
+ # Localize or create a new JavaScript Template object.
+ JST = window.JST = window.JST or {}
+
+ # Configure LayoutManager with Backbone Boilerplate defaults.
+ LayoutManager.configure
+ # Allow LayoutManager to augment Backbone.View.prototype.
+ manage: true
+
+ prefix: "app/templates/"
+
+ fetch: (path) ->
+ # Concatenate the file extension.
+ path = path + ".html"
+
+ # If cached, use the compiled template.
+ return JST[path] if JST[path]
+
+ # Put fetch into `async-mode`.
+ done = @async()
+
+ # Seek out the template asynchronously.
+ $.get app.root + path, (contents) ->
+ done _.template contents
+ , "text"
+
+ # Mix Backbone.Events, modules, and layout management into the app object.
+ _.extend app,
+ # Create a custom object with a nested Views object.
+ module: (additionalProps) ->
+ _.extend Views: {} , additionalProps
+
+ # Helper for using layouts.
+ useLayout: (name, options) ->
+ # Enable variable arity by allowing the first argument to be the options
+ # object and omitting the name argument.
+ options = name if _.isObject name
+
+ # Ensure options is an object.
+ options = options or {}
+
+ # If a name property was specified use that as the template.
+ options.template = name if _.isString name
+
+ # Check if a layout already exists, if so, update the template.
+ if @layout
+ @layout.template = options.template
+ else
+ # Create a new Layout with options.
+ @layout = new Backbone.Layout _.extend
+ el: "main"
+ , options
+
+ # Cache the reference.
+ @layout
+
+ , Backbone.Events
View
22 src/app/src/config.coffee
@@ -0,0 +1,22 @@
+# Set the require.js configuration for your application.
+require.config
+
+ # Initialize the application with the main application file and the JamJS
+ # generated configuration file.
+ deps: ["../vendor/jam/require.config", "main"]
+
+ paths:
+ # Use the underscore build of Lo-Dash to minimize incompatibilities.
+ "lodash": "../vendor/jam/lodash/lodash.underscore"
+
+ # Put additional paths here.
+
+ map:
+ # Ensure Lo-Dash is used instead of underscore.
+ "*": { "underscore": "lodash" }
+
+ # Put additional maps here.
+
+ shim: {
+ # Put shims here.
+ }
View
42 src/app/src/main.coffee
@@ -0,0 +1,42 @@
+require [
+ # Application.
+ "app",
+
+ # Main Router.
+ "router"
+],
+
+(app, Router) ->
+
+ # Define your master router on the application namespace and trigger all
+ # navigation from this instance.
+ app.router = new Router()
+
+ # Trigger the initial route and enable HTML5 History API support, set the
+ # root folder to '/' by default. Change in app.js.
+ Backbone.history.start
+ pushState: true
+ root: app.root
+
+ # All navigation that is relative should be passed through the navigate
+ # method, to be processed by the router. If the link has a `data-bypass`
+ # attribute, bypass the delegation completely.
+ $(document).on "click", "a[href]:not([data-bypass])", (evt) ->
+ # Get the absolute anchor href.
+ href =
+ prop: $(this).prop "href"
+ attr: $(this).attr "href"
+
+ # Get the absolute root.
+ root = location.protocol + "//" + location.host + app.root
+
+ # Ensure the root is part of the anchor href, meaning it's relative.
+ if href.prop.slice(0, root.length) is root
+ # Stop the default event to ensure the link will not cause a page
+ # refresh.
+ evt.preventDefault()
+
+ # `Backbone.history.navigate` is sufficient for all Routers and will
+ # trigger the correct events. The Router's internal `navigate` method
+ # calls this anyways. The fragment is sliced from the root.
+ Backbone.history.navigate href.attr, true
View
17 src/app/src/router.coffee
@@ -0,0 +1,17 @@
+define [
+ # Application.
+ "app"
+],
+
+(app) ->
+
+ # Defining the application router, you can attach sub routers here.
+ Router = Backbone.Router.extend
+ routes: {
+ "": "index"
+ }
+
+ index: () ->
+ # Handle index sub route here.
+
+ return Router
View
84 src/grunt.js
@@ -0,0 +1,84 @@
+// Generated by CoffeeScript 1.6.1
+(function() {
+
+ module.exports = function(grunt) {
+ grunt.initConfig({
+ lint: {
+ files: ["build/config.js", "app/**/*.js"]
+ },
+ jshint: {
+ options: {
+ scripturl: true
+ }
+ },
+ jst: {
+ "dist/debug/templates.js": ["app/templates/**/*.html"]
+ },
+ styles: {
+ "dist/debug/index.css": {
+ src: "app/styles/index.css",
+ paths: ["app/styles"],
+ prefix: "app/styles/",
+ additional: []
+ }
+ },
+ requirejs: {
+ mainConfigFile: "app/config.js",
+ jamConfig: "/vendor/jam/require.config.js",
+ out: "dist/debug/require.js",
+ name: "config",
+ wrap: false
+ },
+ concat: {
+ dist: {
+ src: ["vendor/js/libs/almond.js", "dist/debug/templates.js", "dist/debug/require.js"],
+ dest: "dist/debug/require.js",
+ separator: ";"
+ }
+ },
+ mincss: {
+ "dist/release/index.css": ["dist/debug/index.css"]
+ },
+ min: {
+ "dist/release/require.js": ["dist/debug/require.js"]
+ },
+ server: {
+ files: {
+ "favicon.ico": "favicon.ico"
+ },
+ prefix: "app/styles/",
+ debug: {
+ files: "<config:server.files>",
+ folders: {
+ "app": "dist/debug",
+ "vendor/js/libs": "dist/debug",
+ "app/styles": "dist/debug"
+ }
+ },
+ release: {
+ host: "0.0.0.0",
+ files: "<config:server.files>",
+ folders: {
+ "app": "dist/release",
+ "vendor/js/libs": "dist/release",
+ "app/styles": "dist/release"
+ }
+ }
+ },
+ qunit: {
+ all: ["test/qunit/*.html"]
+ },
+ jasmine: {
+ all: ["test/jasmine/*.html"]
+ },
+ watch: {
+ files: ["grunt.js", "vendor/**/*", "app/**/*"],
+ tasks: "styles"
+ },
+ clean: ["dist/"]
+ });
+ grunt.registerTask("debug", "clean lint jst requirejs concat styles");
+ return grunt.registerTask("release", "debug min mincss");
+ };
+
+}).call(this);
View
207 src/src/grunt.coffee
@@ -0,0 +1,207 @@
+# This is the main application configuration file. It is a Grunt
+# configuration file, which you can learn more about here:
+# https://github.com/cowboy/grunt/blob/master/docs/configuring.md
+module.exports = (grunt) ->
+
+ grunt.initConfig
+
+ # The lint task will run the build configuration and the application
+ # JavaScript through JSHint and report any errors. You can change the
+ # options for this task, by reading this:
+ # https://github.com/cowboy/grunt/blob/master/docs/task_lint.md
+ lint:
+ files: [
+ "build/config.js", "app/**/*.js"
+ ]
+
+ # The jshint option for scripturl is set to lax, because the anchor
+ # override inside main.js needs to test for them so as to not accidentally
+ # route.
+ jshint:
+ options:
+ scripturl: true
+
+ # The jst task compiles all application templates into JavaScript
+ # functions with the underscore.js template function from 1.2.4. You can
+ # change the namespace and the template options, by reading this:
+ # https://github.com/gruntjs/grunt-contrib/blob/master/docs/jst.md
+ #
+ # The concat task depends on this file to exist, so if you decide to
+ # remove this, ensure concat is updated accordingly.
+ jst:
+ "dist/debug/templates.js": [
+ "app/templates/**/*.html"
+ ]
+
+ # This task simplifies working with CSS inside Backbone Boilerplate
+ # projects. Instead of manually specifying your stylesheets inside the
+ # configuration, you can use `@imports` and this task will concatenate
+ # only those paths.
+ styles:
+ # Out the concatenated contents of the following styles into the below
+ # development file path.
+ "dist/debug/index.css":
+ # Point this to where your `index.css` file is location.
+ src: "app/styles/index.css"
+
+ # The relative path to use for the @imports.
+ paths: ["app/styles"]
+
+ # Point to where styles live.
+ prefix: "app/styles/"
+
+ # Additional production-only stylesheets here.
+ additional: []
+
+ # This task uses James Burke's excellent r.js AMD build tool. In the
+ # future other builders may be contributed as drop-in alternatives.
+ requirejs:
+ # Include the main configuration file.
+ mainConfigFile: "app/config.js"
+
+ # Also include the JamJS configuration file.
+ jamConfig: "/vendor/jam/require.config.js"
+
+ # Output file.
+ out: "dist/debug/require.js"
+
+ # Root application module.
+ name: "config"
+
+ # Do not wrap everything in an IIFE.
+ wrap: false
+
+ # The concatenate task is used here to merge the almond require/define
+ # shim and the templates into the application code. It's named
+ # dist/debug/require.js, because we want to only load one script file in
+ # index.html.
+ concat:
+ dist:
+ src: [
+ "vendor/js/libs/almond.js"
+ "dist/debug/templates.js"
+ "dist/debug/require.js"
+ ]
+
+ dest: "dist/debug/require.js"
+
+ separator: ";"
+
+ # This task uses the MinCSS Node.js project to take all your CSS files in
+ # order and concatenate them into a single CSS file named index.css. It
+ # also minifies all the CSS as well. This is named index.css, because we
+ # only want to load one stylesheet in index.html.
+ mincss:
+ "dist/release/index.css": [
+ "dist/debug/index.css"
+ ]
+
+ # Takes the built require.js file and minifies it for filesize benefits.
+ min:
+ "dist/release/require.js": [
+ "dist/debug/require.js"
+ ]
+
+ # Running the server without specifying an action will run the defaults,
+ # port: 8000 and host: 127.0.0.1. If you would like to change these
+ # defaults, simply add in the properties `port` and `host` respectively.
+ # Alternatively you can omit the port and host properties and the server
+ # task will instead default to process.env.PORT or process.env.HOST.
+ #
+ # Changing the defaults might look something like this:
+ #
+ # server:
+ # host: "127.0.0.1", port: 9001
+ # debug: { ... can set host and port here too ... }
+ #
+ # To learn more about using the server task, please refer to the code
+ # until documentation has been written.
+ server:
+ # Ensure the favicon is mapped correctly.
+ files:
+ "favicon.ico": "favicon.ico"
+
+ # For styles.
+ prefix: "app/styles/"
+
+ debug:
+ # Ensure the favicon is mapped correctly.
+ files: "<config:server.files>"
+
+ # Map `server:debug` to `debug` folders.
+ folders:
+ "app": "dist/debug"
+ "vendor/js/libs": "dist/debug"
+ "app/styles": "dist/debug"
+
+ release:
+ # This makes it easier for deploying, by defaulting to any IP.
+ host: "0.0.0.0"
+
+ # Ensure the favicon is mapped correctly.
+ files: "<config:server.files>"
+
+ # Map `server:release` to `release` folders.
+ folders:
+ "app": "dist/release"
+ "vendor/js/libs": "dist/release"
+ "app/styles": "dist/release"
+
+ # The headless QUnit testing environment is provided for "free" by Grunt.
+ # Simply point the configuration to your test directory.
+ qunit:
+ all: ["test/qunit/*.html"]
+
+ # The headless Jasmine testing is provided by grunt-jasmine-task. Simply
+ # point the configuration to your test directory.
+ jasmine:
+ all: ["test/jasmine/*.html"]
+
+ # The watch task can be used to monitor the filesystem and execute
+ # specific tasks when files are modified. By default, the watch task is
+ # available to compile CSS if you are unable to use the runtime compiler
+ # (use if you have a custom server, PhoneGap, Adobe Air, etc.)
+ watch:
+ files: ["grunt.js", "vendor/**/*", "app/**/*"]
+ tasks: "styles"
+
+ # The clean task ensures all files are removed from the dist/ directory so
+ # that no files linger from previous builds.
+ clean: ["dist/"]
+
+ # If you want to generate targeted `index.html` builds into the `dist/`
+ # folders, uncomment the following configuration block and use the
+ # conditionals inside `index.html`.
+ #targethtml:
+ # debug:
+ # src: "index.html"
+ # dest: "dist/debug/index.html"
+ #
+ # release:
+ # src: "index.html"
+ # dest: "dist/release/index.html"
+
+ # This task will copy assets into your build directory,
+ # automatically. This makes an entirely encapsulated build into
+ # each directory.
+ #copy:
+ # debug:
+ # files:
+ # "dist/debug/app/": "app/**"
+ # "dist/debug/vendor/": "vendor/**"
+
+ # release:
+ # files:
+ # "dist/release/app/": "app/**"
+ # "dist/release/vendor/": "vendor/**"
+
+ # The debug task will remove all contents inside the dist/ folder, lint
+ # all your code, precompile all the underscore templates into
+ # dist/debug/templates.js, compile all the application code into
+ # dist/debug/require.js, and then concatenate the require/define shim
+ # almond.js and dist/debug/templates.js into the require.js file.
+ grunt.registerTask "debug", "clean lint jst requirejs concat styles"
+
+ # The release task will run the debug tasks and then minify the
+ # dist/debug/require.js file and CSS files.
+ grunt.registerTask "release", "debug min mincss"
View
59 src/test/jasmine/spec/example.spec.js
@@ -0,0 +1,59 @@
+// Generated by CoffeeScript 1.6.1
+(function() {
+
+ describe("one tautology", function() {
+ it("is a tautology", function() {
+ return expect(true).toBeTruthy();
+ });
+ return describe("is awesome", function() {
+ return it("is awesome", function() {
+ return expect(1).toBe(1);
+ });
+ });
+ });
+
+ describe("simple tests", function() {
+ it("increments", function() {
+ var mike;
+ mike = 0;
+ expect(mike++ === 0).toBeTruthy();
+ return expect(mike === 1).toBeTruthy();
+ });
+ return it("increments (improved)", function() {
+ var mike;
+ mike = 0;
+ expect(mike++).toBe(0);
+ return expect(mike).toBe(1);
+ });
+ });
+
+ describe("setUp/tearDown", function() {
+ beforeEach(function() {});
+ afterEach(function() {});
+ it("example", function() {});
+ return describe("setUp/tearDown", function() {
+ beforeEach(function() {});
+ afterEach(function() {});
+ return it("example", function() {});
+ });
+ });
+
+ describe("async", function() {
+ return it("multiple async", function() {
+ var semaphore;
+ semaphore = 2;
+ setTimeout(function() {
+ expect(true).toBeTruthy();
+ return semaphore--;
+ }, 500);
+ setTimeout(function() {
+ expect(true).toBeTruthy();
+ return semaphore--;
+ }, 500);
+ return waitsFor(function() {
+ return semaphore === 0;
+ });
+ });
+ });
+
+}).call(this);
View
54 src/test/jasmine/spec/src/example.spec.coffee
@@ -0,0 +1,54 @@
+describe "one tautology", () ->
+ it "is a tautology", () ->
+ expect(true).toBeTruthy()
+
+ describe "is awesome", () ->
+ it "is awesome", () ->
+ expect(1).toBe(1)
+
+describe "simple tests", () ->
+ it "increments", () ->
+ mike = 0
+ expect(mike++ is 0).toBeTruthy()
+ expect(mike is 1).toBeTruthy()
+
+ it "increments (improved)", () ->
+ mike = 0
+ expect(mike++).toBe(0)
+ expect(mike).toBe(1)
+
+describe "setUp/tearDown", () ->
+ beforeEach () ->
+ # console.log("Before")
+
+ afterEach () ->
+ # console.log("After")
+
+ it "example", () ->
+ # console.log("During")
+
+ describe "setUp/tearDown", () ->
+ beforeEach () ->
+ # console.log("Before2")
+
+ afterEach () ->
+ # console.log("After2")
+
+ it "example", () ->
+ # console.log("During Nested")
+
+describe "async", () ->
+ it "multiple async", () ->
+ semaphore = 2
+
+ setTimeout () ->
+ expect(true).toBeTruthy()
+ semaphore--
+ , 500
+
+ setTimeout () ->
+ expect(true).toBeTruthy()
+ semaphore--
+ , 500
+
+ waitsFor () -> return semaphore is 0
View
47 src/test/qunit/tests/example.js
@@ -0,0 +1,47 @@
+// Generated by CoffeeScript 1.6.1
+(function() {
+
+ test("one tautology", function() {
+ return ok(true);
+ });
+
+ module("simple tests");
+
+ test("increments", function() {
+ var mike;
+ mike = 0;
+ ok(mike++ === 0);
+ return ok(mike === 1);
+ });
+
+ test("increments (improved)", function() {
+ var mike;
+ mike = 0;
+ equal(mike++, 0);
+ return equal(mike, 1);
+ });
+
+ module("setUp/tearDown", {
+ setup: function() {},
+ teardown: function() {}
+ });
+
+ test("example", function() {});
+
+ module("async");
+
+ test("multiple async", function() {
+ expect(2);
+ stop();
+ setTimeout(function() {
+ ok(true, "async operation completed");
+ return start();
+ }, 500);
+ stop();
+ return setTimeout(function() {
+ ok(true, "async operation completed");
+ return start();
+ }, 500);
+ });
+
+}).call(this);
View
43 src/test/qunit/tests/src/example.coffee
@@ -0,0 +1,43 @@
+test "one tautology", () ->
+ ok(true)
+
+module("simple tests")
+
+test "increments", () ->
+ mike = 0
+ ok(mike++ is 0)
+ ok(mike is 1)
+
+test "increments (improved)", () ->
+ mike = 0
+ equal(mike++, 0)
+ equal(mike, 1)
+
+module "setUp/tearDown",
+ setup: () ->
+ #console.log("Before")
+
+ teardown: () ->
+ #console.log("After")
+
+test "example", () ->
+ #console.log("During")
+
+module "async"
+
+test "multiple async", () ->
+ expect(2)
+
+ stop()
+
+ setTimeout () ->
+ ok true, "async operation completed"
+ start()
+ , 500
+
+ stop()
+
+ setTimeout () ->
+ ok true, "async operation completed"
+ start()
+ , 500
Something went wrong with that request. Please try again.