├── part1
├── README.md
└── index.html
├── part2
├── README.md
├── PostViewWithTemplate.js
├── PostViewWithoutTemplate.js
├── index.html
├── tests.html
├── PostViewWithEvents.js
└── PostView.js
├── part3
├── README.md
├── public
│ ├── js
│ │ ├── models
│ │ │ └── PostModel.js
│ │ ├── views
│ │ │ ├── PostView.js
│ │ │ └── PostFormView.js
│ │ └── basic_samples
│ │ │ └── PostModel.js
│ ├── samples.html
│ ├── index.html
│ ├── add.html
│ └── lib
│ │ ├── underscore-min.js
│ │ ├── backbone-min.js
│ │ └── mustache.js
├── basic
│ ├── index.html
│ └── ModelsBasicUsage.js
└── posts.rb
├── part4
├── README.md
├── public
│ ├── js
│ │ ├── collections
│ │ │ └── PostList.js
│ │ ├── models
│ │ │ └── PostModel.js
│ │ └── views
│ │ │ ├── PostView.js
│ │ │ ├── AppView.js
│ │ │ └── PostFormView.js
│ ├── index.html
│ └── lib
│ │ ├── underscore-min.js
│ │ ├── backbone-min.js
│ │ └── mustache.js
├── samples
│ ├── index.html
│ ├── server.js
│ └── samples.js
└── posts.rb
├── part5
├── README.md
├── blog
│ ├── public
│ │ ├── js
│ │ │ ├── models
│ │ │ │ ├── PostReaded.js
│ │ │ │ └── PostModel.js
│ │ │ ├── collections
│ │ │ │ └── PostCollection.js
│ │ │ ├── views
│ │ │ │ ├── AppView.js
│ │ │ │ ├── HeaderView.js
│ │ │ │ └── posts
│ │ │ │ │ ├── PostView.js
│ │ │ │ │ └── PostFormView.js
│ │ │ └── AppRouter.js
│ │ ├── css
│ │ │ └── blog.css
│ │ ├── index.html
│ │ └── libs
│ │ │ └── js
│ │ │ ├── backbone.localStorage-min.js
│ │ │ ├── underscore-min.js
│ │ │ └── mustache.js
│ └── posts.rb
└── examples
│ ├── js
│ ├── utils.js
│ ├── sync.js
│ ├── router.js
│ └── events.js
│ └── index.html
├── part6
├── README.md
└── contacts-manager
│ ├── .gitattributes
│ ├── app
│ ├── robots.txt
│ ├── styles
│ │ ├── main.css
│ │ └── main.scss
│ ├── scripts
│ │ └── main.js
│ ├── favicon.ico
│ ├── index.html
│ └── 404.html
│ ├── .bowerrc
│ ├── .gitignore
│ ├── test
│ ├── lib
│ │ ├── expect.js
│ │ └── mocha
│ │ │ └── mocha.css
│ ├── spec
│ │ └── test.js
│ └── index.html
│ ├── bower.json
│ ├── .editorconfig
│ ├── .jshintrc
│ ├── package.json
│ └── Gruntfile.js
├── .gitignore
└── README.md
/part1/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/part2/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/part3/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/part4/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/part5/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/part6/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
--------------------------------------------------------------------------------
/part6/contacts-manager/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
--------------------------------------------------------------------------------
/part6/contacts-manager/app/robots.txt:
--------------------------------------------------------------------------------
1 | # robotstxt.org
2 |
3 | User-agent: *
4 |
--------------------------------------------------------------------------------
/part6/contacts-manager/.bowerrc:
--------------------------------------------------------------------------------
1 | {
2 | "directory": "app/bower_components"
3 | }
4 |
--------------------------------------------------------------------------------
/part6/contacts-manager/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | test/temp
4 | .sass-cache
5 | app/bower_components
6 | .tmp
7 | test/bower_components/
8 |
--------------------------------------------------------------------------------
/part6/contacts-manager/app/styles/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | background: #fafafa;
3 | }
4 |
5 | .hero-unit {
6 | margin: 50px auto 0 auto;
7 | width: 300px;
8 | }
--------------------------------------------------------------------------------
/part5/blog/public/js/models/PostReaded.js:
--------------------------------------------------------------------------------
1 | var PostReaded = Backbone.Model.extend({
2 | localStorage: new Backbone.LocalStorage("PostReaded"),
3 | defaults: {
4 | id: 1,
5 | post_id: ''
6 | }
7 | });
8 |
--------------------------------------------------------------------------------
/part4/public/js/collections/PostList.js:
--------------------------------------------------------------------------------
1 | var PostList = Backbone.Collection.extend({
2 | model: PostModel,
3 | url: '/posts',
4 | comparator: function(post) {
5 | -post.get('id');
6 | }
7 | });
8 |
9 | var Posts = new PostList();
--------------------------------------------------------------------------------
/part5/blog/public/js/collections/PostCollection.js:
--------------------------------------------------------------------------------
1 | var PostCollection = Backbone.Collection.extend({
2 | model: PostModel,
3 | url: '/posts',
4 | comparator: function(post) {
5 | -post.get('id');
6 | }
7 | });
8 |
9 | var Posts = new PostCollection();
--------------------------------------------------------------------------------
/part6/contacts-manager/test/lib/expect.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * chai
3 | * Copyright(c) 2011-2012 Jake Luer
4 | * MIT Licensed
5 | */
6 |
7 | module.exports = function (chai, util) {
8 | chai.expect = function (val, message) {
9 | return new chai.Assertion(val, message);
10 | };
11 | };
12 |
13 |
--------------------------------------------------------------------------------
/part6/contacts-manager/test/spec/test.js:
--------------------------------------------------------------------------------
1 | /*global describe, it */
2 | 'use strict';
3 | (function () {
4 | describe('Give it some context', function () {
5 | describe('maybe a bit more context here', function () {
6 | it('should run here few assertions', function () {
7 |
8 | });
9 | });
10 | });
11 | })();
12 |
--------------------------------------------------------------------------------
/part4/public/js/models/PostModel.js:
--------------------------------------------------------------------------------
1 | var PostModel = Backbone.Model.extend({
2 | defaults: {
3 | title: "",
4 | text: ""
5 | },
6 | validate: function(attrs) {
7 | if (attrs.title == '')
8 | return 'O título é obrigatório';
9 | if (attrs.text == '')
10 | return 'O texto é obrigatório'
11 | }
12 | });
--------------------------------------------------------------------------------
/part3/public/js/models/PostModel.js:
--------------------------------------------------------------------------------
1 | var PostModel = Backbone.Model.extend({
2 | urlRoot: 'posts',
3 | defaults: {
4 | title: "",
5 | text: ""
6 | },
7 | validate: function(attrs) {
8 | if (attrs.title == '')
9 | return 'O título é obrigatório';
10 | if (attrs.text == '')
11 | return 'O texto é obrigatório'
12 | }
13 | });
--------------------------------------------------------------------------------
/part6/contacts-manager/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "contacts-manager",
3 | "version": "0.0.0",
4 | "dependencies": {
5 | "sass-bootstrap": "~3.0.0",
6 | "jquery": "~1.9.0",
7 | "underscore": "~1.4.3",
8 | "backbone": "~1.0.0",
9 | "requirejs": "~2.1.5",
10 | "requirejs-text": "~2.0.5",
11 | "modernizr": "~2.6.2"
12 | },
13 | "devDependencies": {}
14 | }
15 |
--------------------------------------------------------------------------------
/part2/PostViewWithTemplate.js:
--------------------------------------------------------------------------------
1 | var PostView = Backbone.View.extend({
2 | tagName: 'article',
3 | className: 'page-posts',
4 | template: _.template("<%= title %>
<%= content %>
"),
5 | render: function() {
6 | this.$el.html(this.template({title: "Nome do Post", content: "Conteudo do Post"}));
7 | }
8 | });
9 |
10 | var postView = new PostView();
11 | postView.render();
12 | console.log(postView.el);
--------------------------------------------------------------------------------
/part2/PostViewWithoutTemplate.js:
--------------------------------------------------------------------------------
1 | var PostView = Backbone.View.extend({
2 | tagName: 'article',
3 | className: 'page-posts',
4 | render: function() {
5 | var htmlGenerated = "Nome do Post
";
6 | htmlGenerated += "Conteudo do post
";
7 | this.$el.html(htmlGenerated); //Shortcut to $(this.el).html(htmlGenerated);
8 | }
9 | });
10 |
11 | var postView = new PostView();
12 | postView.render();
13 | console.log(postView.el);
--------------------------------------------------------------------------------
/part3/basic/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Backbone Tutorial Series Part 3 - Model
5 |
6 |
7 |
8 |
9 |
10 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/part5/examples/js/utils.js:
--------------------------------------------------------------------------------
1 | Backbone.$ = jQuery.noConflict();
2 |
3 | // Main Backbone does not use Zepto, will return an error because "pluck" is present on Zepto API
4 | try {
5 | console.log(Backbone.$('body > *').pluck('nodeName'));
6 | } catch (error) {
7 | console.log(error);
8 | }
9 |
10 | var localBackbone = Backbone.noConflict();
11 | var localBackboneModel = localBackbone.Model.extend({});
12 |
13 | // The localBackbone will use Zepto
14 | localBackbone.$ = Zepto;
15 | console.log(localBackbone.$('body > *').pluck('nodeName'));
--------------------------------------------------------------------------------
/part6/contacts-manager/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 |
10 | # Change these settings to your own preference
11 | indent_style = space
12 | indent_size = 4
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/part6/contacts-manager/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "node": true,
3 | "browser": true,
4 | "esnext": true,
5 | "bitwise": true,
6 | "camelcase": true,
7 | "curly": true,
8 | "eqeqeq": true,
9 | "immed": true,
10 | "indent": 4,
11 | "latedef": true,
12 | "newcap": true,
13 | "noarg": true,
14 | "quotmark": "single",
15 | "regexp": true,
16 | "undef": true,
17 | "unused": true,
18 | "strict": true,
19 | "trailing": true,
20 | "smarttabs": true,
21 | "jquery": true
22 | }
23 |
--------------------------------------------------------------------------------
/part3/public/samples.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Backbone Tutorial Series Part 3 - Samples
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/part5/blog/public/js/models/PostModel.js:
--------------------------------------------------------------------------------
1 | var PostModel = Backbone.Model.extend({
2 | urlRoot: '/posts',
3 | defaults: {
4 | title:'',
5 | text:''
6 | },
7 | isReaded: function() {
8 | var lastPost = new PostReaded();
9 | lastPost.fetch();
10 | return lastPost.get('post_id') == this.get('id');
11 | },
12 | validate: function(attrs) {
13 | if (attrs.title == '')
14 | return 'The title field is required';
15 | if (attrs.text == '')
16 | return 'The text field is required';
17 | }
18 | });
19 |
--------------------------------------------------------------------------------
/part5/blog/public/js/views/AppView.js:
--------------------------------------------------------------------------------
1 | var AppView = Backbone.View.extend({
2 | el: $('#content'),
3 | initialize: function() {
4 | _.bindAll(this, 'render', 'addAll', 'addPost', 'showForm');
5 | },
6 | render: function() {
7 | this.$el.empty();
8 | this.addAll();
9 | },
10 | addPost: function(post) {
11 | var view = new PostView({
12 | model: post
13 | });
14 | this.$el.append(view.render().el);
15 | },
16 | addAll: function() {
17 | Posts.each(this.addPost);
18 | },
19 | showForm: function() {
20 | this.form.show();
21 | }
22 | });
23 |
--------------------------------------------------------------------------------
/part4/samples/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Backbone Tutorial - Part 4 Collections
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/part2/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Backbone Tutorial Series Part 2 - View
5 |
6 |
7 |
8 |
9 |
10 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/part2/tests.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Backbone Tutorial Series Part 2 - View
5 |
6 |
7 |
8 |
9 |
10 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/part6/contacts-manager/test/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Mocha Spec Runner
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |