Frontend Workflow

Created by Marco A. Pajares / gitHub

Index

Local repository

  • Initialize repositories
  • Craft file versions
  • Create branches

Branches

Created with Snap 1 2 3 Created with Snap

Main Git commands

Command Task

											git clone [remote_URL]
										
clone the remote repo on your local machine

											git pull origin [branch_Name]
										
update branch (like synchronize)

											git checkout -b [branch_name]
										
create a new branch

											git checkout [branch_name]
										
move to another branch

											git status
										
list changes that have been made and ready to push

											git add/rm [file_path]
										
add/remove new files to commit

											git commit -am [Message]
										
index your changes

											git push origin [branch_name]
										
push to remote branch

											git reset --hard
										
revert to initial state (if something fails)

Another useful Git commands

Command Task

											git log
										
show history commits

											git diff [commit_hash] [commit_hash]
										
show diff between commits

											git stash
										
Stash the changes in a dirty working directory away (DO before git pull)

											git stash pop
										
apply changes on stash branch in your current branch (DO after git pull)

											git checkout -t [branch_name]
										
download a branch that only exist on remote

											git branch -d [branch_name]
										
delete a LOCAL branch

											git checkout [commit_hash] [file_path]
										
revert specific file to a previous commit

											git tag -a [tag_version] -m [tag_message]
										
index your changes

											git push origin [tag_name]
										
push a tag to remote branch

                                                                                        git checkout [branch] -- [filepath]
                                                                                
overwrite a specific file in your current branch from same file in other branch

Why use Backbone?

  • We really need MVC for the front end. Traditional methods leave us with code that's too coupled, messy and incredibly hard to maintain.
  • Storing data and state in the DOM is a bad idea. This started making more sense after creating apps that needed different parts of the app to be updated with the same data.
  • Fat models and skinny controllers are the way to go. Workflow is simplified when business logic is taken care of by models.
  • Templating is an absolute necessity. Putting HTML inside your JavaScript gives you bad karma.
see more at: tutplus or backbone tutorials

1 - Intro to Backbone

Backbone supplies structure to JavaScript-heavy applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interface.

1.1 - Backbone essentials

Backbone's core consists of four major classes:

  • Model
  • Collection
  • View
  • Controller

1.1.1 - Model

In Backbone, a model represents a singular entity -- a record in a database if you will. But there are no hard and fast rules here. From the Backbone website: Models are the heart of any JavaScript application, containing the interactive data as well as a large part of the logic surrounding it: conversions, validations, computed properties, and access control. The model merely gives you a way to read and write arbitrary properties or attributes on a data set.

1.1.2 - Collection

Collections in Backbone are essentially just a collection of models. Going with our database analogy from earlier, collections are the results of a query where the results consists of a number of records [models].

1.1.3 - View

A view handles two duties fundamentally:

  • Listen to events thrown by the DOM and models/collections.
  • Represent the application's state and data model to the user.
Creating a new app

Why use Sass?

Sass is a preprocessor a meta-language on top of CSS that both provides a simpler, more elegant syntax for CSS and implements various features that are useful for creating manageable stylesheets.

see more at: zivtech or Sass Creating a new style file

Features

  • Syntax
  • Compass
  • Variables
  • Mixins
  • Extends

Why use Jasmine

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests

Testing with Jasmine see more at: Jasmine

Why use Grunt?

In one word: automation. The less work you have to do when performing repetitive tasks like minification, compilation, unit testing, linting, etc, the easier your job becomes. After you've configured it, a task runner can do most of that mundane work for you—and your team—with basically zero effort.

List of Grunt task available see more at: Grunt

Struct

From now on, we are going to try a new struct to develope new backbone apps like could be catalitycs or trends

Tree

1 - src/test

test folder has been created to store Jasmine tests

1 - src/main/Resources

resources folder has been created to store documentation and style preprocess files

    Contain:
  • Documentation generated with Yuidoc
  • Style Sass files (not Css)

1 - src/main/Webapp/js/apps

apps folder has been created to store Backbone applications

Backbone App

In order to create or check a new Backbone application, creator must take the following steps:

  • Router
  • Create Struct
  • BaseView
  • Check Require

1 - Router

inside js/router.js file, must appear URL and METHOD


								"url":"method"
							
    Important! About notation:
  • URL: must be lowercase, as specific as could be, and use underscore (_) for composite words.
  • Methods & Backbone Apps: must be using camelCase notation
Tree Tree

2 - Struct

    Every Backbone App must contain the following folders:
  • entities: models and collections are placed here
  • templates: every Jade/Handlebars must be here
  • views: every view must be here ATENTION! inside this folder must appear always a yourappnameBaseView.js
Tree

3 - BaseView

In order to simplify create Backbone apps, inside 'router.js' there is a method called 'load backbone' that search inside 'apps/yourBackboneApp/views/yourBackboneAppBaseView.js to init the app, thats why must exist a BaseView.js file.

Tree

4 - RequireJs

When maven production task start, uglify every Js code, and use requireJs to avoid ask server multiple times for the same file. To do that, require.js needs a dependencies map, wich is located on 'js/config.js' and contain every dependencies that the app needs.

Tree

Style


							grunt style
						

In order to create or check a style file, creator must take the following steps:

  • Check deps
  • Create a file inside '/custom'
  • Link to init file
Tree

1 - Check deps

    Inside 'resources/stylesheets' folder there are two folders:
  • custom : wich are located every style file made by us
  • vendors : wich are located every external css lib that our code need

So, if you have to import external css, place it into resources/stylesheets/vendors

2 - Create a file inside /custom

Create a file inside 'resources/stylesheets/custom' folder and wrap it using a div

3 - Link to init file

    Inside resources/stylesheets folder there are two files:
  • new_sytle : listed some scss file located on custom folder and use BOOTSTRAP v3 to generate new_style.css
  • old_sytle: listed some scss file located on custom folder and use BOOTSTRAP v2 to generate old_style.css

Why testing code?


							grunt test
						
  • It is our proof/evidence that our code works properly
  • Also, is a way to avoid future unexpected problems
  • It runs in a controlled environment

Generating a Spec

Inside 'test/spec' are listed all tthe backbone applications that right now exist, just create another folder and using require call your new aplication and start to add tests!

Tree

Generating a Spec

Tree

Using grunt many important task has been created

  • Download external deps/libs using Bower
  • Genarting Html files from jade/handlebars
  • Generating style files from scss (sass)
  • Evaluating JS code syntax using JsHint
  • Evaluating JS code works using Jasmine
  • Compress and uglify every js files in order to generate main-built using requireJs
  • Generating documentation using Yuidoc
  • Clean workspace

Main tasks

Command Bower template style Jshint Test requireJs Doc

											grunt production
										

											grunt bower
										

											grunt init
										

											grunt
										

											grunt fast
										

											grunt test
										

											grunt style
										

											grunt notest
										

Documentation

Inside 'resources/js-documentation' exist a file named 'index.html' where you could see every comment that appears on js files.

THE END

BY Marco A. Pajares

Skype: marco.pajares