Commits

Alex Khomenko committed a0c7e66

Added
- Simple test on Jasmine
- Simple module

Comments (0)

Files changed (10)

+DirectoryIndex index.html
+
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} -s [OR]
+RewriteCond %{REQUEST_FILENAME} -l [OR]
+RewriteCond %{REQUEST_FILENAME} -d
+RewriteRule ^.*$ - [NC,L]
+RewriteRule ^.*$ index.html [NC,L]

public/app/app.js

+
+  window.App = {
+    module: (function() {
+      var modules;
+      modules = [];
+      return function(name) {
+        var _ref;
+        return (_ref = modules[name]) != null ? _ref : modules[name] = {
+          Views: {},
+          Templates: {}
+        };
+      };
+    })()
+  };

public/app/modules/module.js

+(function() {
+  var Module;
+  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
+  Module = App.module('module');
+
+  Module.Model = (function() {
+
+    __extends(Model, Backbone.Model);
+
+    function Model() {
+      Model.__super__.constructor.apply(this, arguments);
+    }
+
+    Model.prototype.isNameFilled = function() {
+      return this.get('name');
+    };
+
+    return Model;
+
+  })();
+
+  Module.Templates.Item = '<span class=name><%= name %></span>';
+
+  Module.Views.Item = (function() {
+
+    __extends(Item, Backbone.View);
+
+    function Item() {
+      Item.__super__.constructor.apply(this, arguments);
+    }
+
+    Item.prototype.tagName = 'li';
+
+    Item.prototype.className = 'item';
+
+    Item.prototype.template = _.template(Module.Templates.Item);
+
+    Item.prototype.initialize = function() {
+      return _.bindAll(this, 'render');
+    };
+
+    Item.prototype.render = function() {
+      var content;
+      content = this.template(this.model.toJSON());
+      ($(this.el)).append(content);
+      return this;
+    };
+
+    return Item;
+
+  })();
+
+  Module.Router = (function() {
+
+    __extends(Router, Backbone.Router);
+
+    function Router() {
+      Router.__super__.constructor.apply(this, arguments);
+    }
+
+    Router.prototype.routes = {
+      '': 'home',
+      'module': 'render'
+    };
+
+    Router.prototype.home = function() {
+      return ($('.modModule')).html('Home page');
+    };
+
+    Router.prototype.render = function() {
+      var content, model, view;
+      ($('.modModule')).append(content);
+      model = new Module.Model({
+        name: 'Home page of Module.js'
+      });
+      view = new Module.Views.Item({
+        model: model
+      });
+      content = view.render().el;
+      return ($('.modModule')).html(content);
+    };
+
+    return Router;
+
+  })();
+
+}).call(this);

public/app/run.js

+
+  jQuery(function($) {
+    var Module;
+    ($('a')).click(function(e) {
+      var href, link, pattern;
+      e.preventDefault();
+      href = ($(this)).prop('href');
+      pattern = /([^:\\/\\/]+[\\/$])(.*)/;
+      link = href.match(pattern)[2];
+      return Backbone.history.navigate(link, true);
+    });
+    Module = App.module('module');
+    new Module.Router;
+    return Backbone.history.start({
+      pushState: true
+    });
+  });

public/index.html

 <!doctype html>
 <html>
 <head>
+  <meta charset=utf-8>
+  <title>BB Project</title>
+  
+  <link rel=stylesheet href=/assets/css/style.css>
+</head>
 
-</head>
+<body>
+
+  <div id=container>
+
+    <div id=content>
+      
+      <nav>
+        <ul>
+          <li><a href=/>Home Page</a></li>
+          <li><a href=/module>Module</a></li>
+        </ul>
+      </nav>
+
+      <div class='modModule'>
+
+      </div>
+
+    </div>
+
+  </div>
+
+
+
+  <!-- Libs -->
+  <script src=/assets/js/libs/jquery-1.7.1.js></script>
+  <script src=/assets/js/libs/underscore-1.2.3.js></script>
+  <script src=/assets/js/libs/backbone-0.5.3.js></script>
+
+  <!-- App -->
+  <script src=/app/app.js></script>
+
+  <!-- Modules -->
+  <script src=/app/modules/module.js></script>
+
+  <!-- Run -->
+  <script src=/app/run.js></script>
+
+</body>
 </html>

src/modules/module.coffee

+
+Module = App.module 'module'
+
+
+class Module.Model extends Backbone.Model
+
+  isNameFilled: ->
+    @get 'name'
+
+Module.Templates.Item = '''
+  <span class=name><%= name %></span>
+'''
+
+class Module.Views.Item extends Backbone.View
+
+  tagName: 'li'
+  className: 'item'
+  template: _.template Module.Templates.Item
+
+  initialize: ->
+    _.bindAll @, 'render'
+
+  render: ->
+    content = @template @model.toJSON()
+    ($ @el).append content
+    @
+
+class Module.Router extends Backbone.Router
+
+  routes:
+    '': 'home'
+    'module': 'render'
+
+  home: ->
+    ($ '.modModule').html 'Home page'
+
+  render: ->
+    ($ '.modModule').append content
+    model = new Module.Model name: 'Home page of Module.js'
+    view = new Module.Views.Item model: model
+    content = view.render().el
+
+    ($ '.modModule').html content
+
+jQuery ($) ->
+
+  ($ 'a').click (e) ->
+    e.preventDefault()
+    href = ($ @).prop 'href'
+
+    pattern = ///
+                ([^:\/\/]+[\/$])    # Domain
+                (.*)                # Url
+              ///
+    link = href.match(pattern)[2]
+    Backbone.history.navigate link, true
+
+  # Dependencies
+  Module = App.module 'module'
+
+  # Adding all routers
+  new Module.Router
+
+  # Start history
+  Backbone.history.start
+      pushState: true

tests/TestSuite.html

 <!doctype html>
 <html>
-	<head>
-		<meta charset='utf-8'>
-		<title>Fuel Central Test Suite</title>
-		<link rel='stylesheet' href='assets/jasmine-1.1.0/jasmine.css'>
+  <head>
+    <meta charset='utf-8'>
+    <title>Fuel Central Test Suite</title>
+    <link rel='stylesheet' href='assets/jasmine-1.1.0/jasmine.css'>
 
-		<script src='assets/jasmine-1.1.0/jasmine.js'></script>
-		<script src='assets/jasmine-1.1.0/jasmine-html.js'></script>
-	</head>
+    <script src='assets/jasmine-1.1.0/jasmine.js'></script>
+    <script src='assets/jasmine-1.1.0/jasmine-html.js'></script>
+  </head>
 
-	<body>
+  <body>
 
-		<script src='../assets/js/libs/jquery-1.7.js'></script>
-		<script src='../assets/js/libs/underscore-1.2.1.js'></script>
-		<script src='../assets/js/libs/backbone-0.5.3.js'></script>
+  <script src='../public/assets/js/libs/jquery-1.7.1.js'></script>
+  <script src='../public/assets/js/libs/underscore-1.2.3.js'></script>
+  <script src='../public/assets/js/libs/backbone-0.5.3.js'></script>
 
-		<!-- Appplication Modules -->
-		<script src='/public/app/app.js'></script>
+  <!-- Application -->
+  <script src='../public/app/app.js'></script>
 
-		<script src='../app/modules/customers/order.js'></script>
-		<script src='app/OrdersTest.js'></script>
+  <!-- Module -->
+  <script src='../public/app/modules/module.js'></script>
+  <script src='app/module.js'></script>
 
-		<script type="text/javascript">
-			jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
-			jasmine.getEnv().execute();
-		</script>
+  <script type="text/javascript">
+    jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
+    jasmine.getEnv().execute();
+  </script>
 
-	</body>
-</html>
-
-
-
-</body>
-</html>
+  </body>
+</html>

tests/app/module.js

+(function() {
+  var Module;
+
+  Module = App.module('module');
+
+  describe('Model TestSuite', function() {
+    beforeEach(function() {
+      var a;
+      return a = 5;
+    });
+    it('can i test', function() {
+      return (expect(true)).toBeTruthy();
+    });
+    it('isNameFilled is truthy if filled name', function() {
+      var model;
+      model = new Module.Model({
+        name: 'Name'
+      });
+      return (expect(model.isNameFilled())).toBeTruthy();
+    });
+    return it('isNameFilled is falsy if filled name is not set', function() {
+      var model;
+      model = new Module.Model({
+        id: 13
+      });
+      return (expect(model.isNameFilled())).toBeFalsy();
+    });
+  });
+
+}).call(this);

tests/src/module.coffee

+
+Module = App.module 'module'
+
+describe 'Model TestSuite', ->
+
+  beforeEach ->
+    a = 5
+
+  it 'can i test', ->
+    (expect true).toBeTruthy()
+
+  it 'isNameFilled is truthy if filled name', ->
+    model = new Module.Model name: 'Name'
+    (expect model.isNameFilled()).toBeTruthy()
+
+  it 'isNameFilled is falsy if filled name is not set', ->
+    model = new Module.Model id: 13
+    (expect model.isNameFilled()).toBeFalsy()