Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save manish-shrivastava/2f779283132b2cdcd8cb5299fc9ed3be to your computer and use it in GitHub Desktop.

Select an option

Save manish-shrivastava/2f779283132b2cdcd8cb5299fc9ed3be to your computer and use it in GitHub Desktop.

Revisions

  1. manish-shrivastava renamed this gist Dec 21, 2016. 1 changed file with 0 additions and 0 deletions.
  2. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -69,7 +69,7 @@ App.FavoritesRoute = Ember.Route.extend({
    ```

    - Using Ember Data is not mandatory. Model could be a plain JSON object:
    -

    ``` js
    App.UserRoute = Ember.Route.extend({
    model: function(params) {
  3. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -68,6 +68,19 @@ App.FavoritesRoute = Ember.Route.extend({
    });
    ```

    - Using Ember Data is not mandatory. Model could be a plain JSON object:
    -
    ``` js
    App.UserRoute = Ember.Route.extend({
    model: function(params) {
    return {
    first_name: "Eric",
    last_name : "Sipple"
    };
    }
    });
    ```

    ### View

    - Views are for **Creating reusable components** and **Setting up logic to handle events.**
  4. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -102,7 +102,7 @@ App.UserController = Ember.ObjectController.extend({
    });
    ```

    - May contain property and observer declarations (attention to get/set calls):
    - May contain property and observer declarations (attention to get/set calls). Controller property monitors enumerated values and evaluate associated function. Observer executes their action respectively:

    ``` js
    App.NumberController = Ember.ObjectController.extend({
    @@ -122,6 +122,8 @@ App.NumberController = Ember.ObjectController.extend({

    ```

    - Example above will make this template alive:

    ``` handlebars
    {{input type="text" value=number size="50"}} x2 = {{timesTwo}}
    ```
  5. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -102,15 +102,24 @@ App.UserController = Ember.ObjectController.extend({
    });
    ```

    - Attention to the property declaration (`.property()`) ad get/set calls:
    - May contain property and observer declarations (attention to get/set calls):

    ``` js
    App.NumberController = Ember.ObjectController.extend({
    number: 1,
    timesTwo: function() {
    return Number(this.get('number')) * 2;
    }.property('number')
    }.property('number'),
    fullName: function() {
    // Calculate some value
    return this.get("first_name") + " " + this.get("last_name");
    }.property('first_name', 'last_name'),
    nameChanged: function() {
    // Execute some action
    console.log("New name! New name!");
    }.observes('first_name', 'last_name')
    });

    ```

    ``` handlebars
  6. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    - Templates are written in Handlebars.
    - Has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Backed by a model and auto-updates following model changes.
    - Can retrieve properties from model and controller.
    - Can retrieve properties from Model and Controller.
    - Can nest one another template with `{{outlet}}` expression.
    - Uses `text/x-handlebars` type when defined in `<script>` blocks.
    - Unnamed script block will be treated as `application` (root) template.
    @@ -24,14 +24,17 @@
    </script>
    ```

    - By default Ebmer will application template to the document's body element.
    - Root element could be changed during app creation: `rootElement: '#app'`.
    - By default Ember will attach `application` template to the document's body element.
    - Root element could be changed during app creation:

    ``` js
    App = Ember.Application.create({
    rootElement: '#app'
    });
    ```

    - There are partial templates that can be included with `render` Handlebars expression.

    ### Router

    - Router recognizes URL, and passes it to a Route object.
    @@ -51,7 +54,8 @@ App.Router.map(function() {

    ### Route

    - An object that tells model which template to show.
    - Route sets up a Controller and supplies it with a Model.
    - Tells model which template to show.
    - Each route has controller and template with the same name.
    - Routes can implement hooks.
    - `model` hook can specify what model will be represented to the template by controller.
    @@ -87,8 +91,8 @@ App.UserController = Ember.ObjectController.extend({

    ### Controller

    - Template can get properties from controller.
    - Used to provide the logic used to access data from the Model (e.g. calculated data).
    - Controller provides Model data to the Template.
    - Can be used to process Model data for the Template (calculated properties).

    ``` js
    App.UserController = Ember.ObjectController.extend({
  7. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ App = Ember.Application.create({
    ```
    ### Router

    - Router recognizes and passes to a Route object.
    - Router recognizes URL, and passes it to a Route object.
    - Translates URL into nested templates.
    - Keep browser address line updated.

  8. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,7 @@ App = Ember.Application.create({
    ```
    ### Router

    - Router recognizes and passes to a Route object.
    - Translates URL into nested templates.
    - Keep browser address line updated.

  9. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -97,6 +97,21 @@ App.UserController = Ember.ObjectController.extend({
    });
    ```

    - Attention to the property declaration (`.property()`) ad get/set calls:

    ``` js
    App.NumberController = Ember.ObjectController.extend({
    number: 1,
    timesTwo: function() {
    return Number(this.get('number')) * 2;
    }.property('number')
    });
    ```

    ``` handlebars
    {{input type="text" value=number size="50"}} x2 = {{timesTwo}}
    ```

    ### Component

    - Reusable UI element.
  10. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -66,6 +66,23 @@ App.FavoritesRoute = Ember.Route.extend({
    ### View

    - Views are for **Creating reusable components** and **Setting up logic to handle events.**
    - Can be used to handle browser events, and send the result to controller:

    ``` js
    App.ProfilePhotoView = Ember.View.extend({
    click: function(evt) {
    this.get('controller').send('expandProfilePhoto');
    }
    });

    App.UserController = Ember.ObjectController.extend({
    actions: {
    expandProfilePhoto: function() {
    // Get the expanded picture and display it
    }
    }
    });
    ```

    ### Controller

  11. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -65,7 +65,7 @@ App.FavoritesRoute = Ember.Route.extend({

    ### View

    - ?
    - Views are for **Creating reusable components** and **Setting up logic to handle events.**

    ### Controller

  12. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -58,7 +58,7 @@ App.Router.map(function() {
    ``` js
    App.FavoritesRoute = Ember.Route.extend({
    model: function() {
    return this.store.find('post');
    return this.store.find('project');
    }
    });
    ```
    @@ -70,7 +70,15 @@ App.FavoritesRoute = Ember.Route.extend({
    ### Controller

    - Template can get properties from controller.
    - ?
    - Used to provide the logic used to access data from the Model (e.g. calculated data).

    ``` js
    App.UserController = Ember.ObjectController.extend({
    fullName: function() {
    return this.get("first_name") + " " + this.get("last_name");
    }
    });
    ```

    ### Component

  13. @dreikanter dreikanter revised this gist Jan 12, 2015. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,6 @@
    - Can nest one another template with `{{outlet}}` expression.
    - Uses `text/x-handlebars` type when defined in `<script>` blocks.
    - Unnamed script block will be treated as `application` (root) template.
    - By default Ebmer will application template to the document's body element.
    - Root element could be changed during app creation: `rootElement: '#app'`.

    ``` handlebars
    <script type="text/x-handlebars">
    @@ -26,6 +24,14 @@
    </script>
    ```

    - By default Ebmer will application template to the document's body element.
    - Root element could be changed during app creation: `rootElement: '#app'`.

    ``` js
    App = Ember.Application.create({
    rootElement: '#app'
    });
    ```
    ### Router

    - Translates URL into nested templates.
  14. @dreikanter dreikanter revised this gist Jan 12, 2015. 2 changed files with 107 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,8 @@
    - Can nest one another template with `{{outlet}}` expression.
    - Uses `text/x-handlebars` type when defined in `<script>` blocks.
    - Unnamed script block will be treated as `application` (root) template.
    - By default Ebmer will application template to the document's body element.
    - Root element could be changed during app creation: `rootElement: '#app'`.

    ``` handlebars
    <script type="text/x-handlebars">
    @@ -67,6 +69,3 @@ App.FavoritesRoute = Ember.Route.extend({
    ### Component

    - Reusable UI element.

    ---

    105 changes: 105 additions & 0 deletions example-2.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset='utf-8'>
    <meta content='IE=Edge,chrome=1' http-equiv='X-UA-Compatible'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <title>Example Angular App</title>
    <link rel="stylesheet" media="all" href="/assets/bootstrap_and_overrides.css?body=1" />
    <link rel="shortcut icon" type="image/x-icon" href="/assets/favicon.ico" />
    <script src="/assets/jquery/jquery.js?body=1"></script>
    <script src="/assets/jquery.js?body=1"></script>
    <script src="/assets/jquery.ui.touch-punch.js?body=1"></script>
    <script src="/assets/handlebars.js?body=1"></script>
    <script src="/assets/ember.js?body=1"></script>
    <script src="/assets/ember-data.js?body=1"></script>
    </head>
    <style>
    body {
    padding: 20px;
    }
    </style>
    <body>

    <script type="text/x-handlebars">
    <h1>{{appName}}</h1>
    <h2>{{title}}</h2>

    {{outlet}}
    </script>

    <script type="text/x-handlebars" data-template-name="projects_list">
    <ul>
    {{#each item in model}}
    <li>{{#link-to 'project' item.id}}{{item.title}}{{/link-to}}</li>
    {{/each}}
    </ul>
    </script>

    <script type="text/x-handlebars" data-template-name="list_item">
    <li>{{#link-to 'project' item.id}}{{item.title}}{{/link-to}}</li>
    </script>

    <script type="text/x-handlebars" data-template-name="project">
    <dl>
    <dt>Title:</dt>
    <dd>{{model.title}}</dd>
    <dt>ID:</dt>
    <dd>{{model.id}}</dd>
    </dl>
    </script>

    <script>
    var App = Ember.Application.create({
    LOG_TRANSITIONS: true
    });

    App.ApplicationRoute = Ember.Route.extend({
    setupController: function(controller) {
    controller.set('title', "Hello world!");
    }
    });

    App.ApplicationController = Ember.Controller.extend({
    appName: 'My First Example'
    });

    App.Router.map(function() {
    this.route('projects_list', { path: 'projects' });
    this.route('project', { path: 'projects/:project_id' });
    });

    App.ProjectsController = Ember.Controller.extend({

    });

    var PROJECTS = [
    {
    id: 1,
    title: 'Project 1'
    },
    {
    id: 2,
    title: 'Project 2'
    }
    ];

    App.ProjectsListRoute = Ember.Route.extend({
    model: function() {
    return PROJECTS;
    }
    });

    App.ProjectRoute = Ember.Route.extend({
    model: function(params) {
    if (!PROJECTS[params.project_id]) {
    return null;
    }

    return PROJECTS[params.project_id];
    }
    });
    </script>

    </body>
    </html>
  15. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 41 additions and 0 deletions.
    41 changes: 41 additions & 0 deletions example-1.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset='utf-8'>
    <meta content='IE=Edge,chrome=1' http-equiv='X-UA-Compatible'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <title>Example Angular App</title>
    <link rel="stylesheet" media="all" href="/assets/bootstrap_and_overrides.css?body=1" />
    <link rel="shortcut icon" type="image/x-icon" href="/assets/favicon.ico" />
    <script src="/assets/jquery/jquery.js?body=1"></script>
    <script src="/assets/jquery.js?body=1"></script>
    <script src="/assets/jquery.ui.touch-punch.js?body=1"></script>
    <script src="/assets/handlebars.js?body=1"></script>
    <script src="/assets/ember.js?body=1"></script>
    <script src="/assets/ember-data.js?body=1"></script>
    </head>
    <body>

    <script type="text/x-handlebars">
    <h1>{{appName}}</h1>
    <h2>{{title}}</h2>
    </script>

    <script>
    var App = Ember.Application.create({
    LOG_TRANSITIONS: true
    });

    App.ApplicationRoute = Ember.Route.extend({
    setupController: function(controller) {
    controller.set('title', "Hello world!");
    }
    });

    App.ApplicationController = Ember.Controller.extend({
    appName: 'My First Example'
    });
    </script>

    </body>
    </html>
  16. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,7 @@
    - Has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Backed by a model and auto-updates following model changes.
    - Can retrieve properties from model and controller.
    - Can be nested.
    - One template can nest only one child template.
    - Nesting is implemented with `{{outlet}}` expression.
    - Can nest one another template with `{{outlet}}` expression.
    - Uses `text/x-handlebars` type when defined in `<script>` blocks.
    - Unnamed script block will be treated as `application` (root) template.

  17. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@
    - Templates are written in Handlebars.
    - Has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Backed by a model and auto-updates following model changes.
    - Can retrieve properties from model and controller.
    - Can be nested.
    - One template can nest only one child template.
    - Nesting is implemented with `{{outlet}}` expression.
  18. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,15 @@
    - An object that stores data (data persistance layer abstraction).
    - Templates transforms models into HTML.
    - Same thing as Rails model.

    ### Template

    - Templates are written in Handlebars.
    - Has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Backed by a model and auto-updates following model changes.
    - Can be nested.
    - One template can nest only one child template.
    - Nesting is implemented with `{{outlet}}` expression.
    - Uses `text/x-handlebars` type when defined in `<script>` blocks.
    - Unnamed script block will be treated as `application` (root) template.

    @@ -16,15 +25,6 @@
    </script>
    ```

    ### Template

    - Templates are written in Handlebars.
    - Has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Backed by a model and auto-updates following model changes.
    - Can be nested.
    - One template can nest only one child template.
    - Nesting is implemented with `{{outlet}}` expression.

    ### Router

    - Translates URL into nested templates.
  19. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,16 @@
    - An object that stores data (data persistance layer abstraction).
    - Templates transforms models into HTML.
    - Same thing as Rails model.
    - Uses `text/x-handlebars` type when defined in `<script>` blocks.
    - Unnamed script block will be treated as `application` (root) template.

    ``` handlebars
    <script type="text/x-handlebars">
    <div>
    {{outlet}}
    </div>
    </script>
    ```

    ### Template

  20. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@

    - An object that stores data (data persistance layer abstraction).
    - Templates transforms models into HTML.
    - Same thing as Rails model.

    ### Template

  21. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,14 @@ App.Router.map(function() {
    - Routes can implement hooks.
    - `model` hook can specify what model will be represented to the template by controller.

    ``` js
    App.FavoritesRoute = Ember.Route.extend({
    model: function() {
    return this.store.find('post');
    }
    });
    ```

    ### View

    - ?
  22. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -33,13 +33,17 @@ App.Router.map(function() {
    ### Route

    - An object that tells model which template to show.
    - Each route has controller and template with the same name.
    - Routes can implement hooks.
    - `model` hook can specify what model will be represented to the template by controller.

    ### View

    - ?

    ### Controller

    - Template can get properties from controller.
    - ?

    ### Component
  23. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Core concepts:
    ## Core concepts

    ### Model

    @@ -45,3 +45,6 @@ App.Router.map(function() {
    ### Component

    - Reusable UI element.

    ---

  24. @dreikanter dreikanter revised this gist Jan 11, 2015. 1 changed file with 32 additions and 10 deletions.
    42 changes: 32 additions & 10 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,23 @@
    Core concepts:

    - Template
    - Templates are written in Handlebars.
    - Each template has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Each template is backed by a model and auto-updates following model changes.
    - Router
    - Route
    - Model
    - View
    - Controller
    ### Model

    - An object that stores data (data persistance layer abstraction).
    - Templates transforms models into HTML.

    ## Router
    ### Template

    - Templates are written in Handlebars.
    - Has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Backed by a model and auto-updates following model changes.
    - Can be nested.
    - One template can nest only one child template.
    - Nesting is implemented with `{{outlet}}` expression.

    ### Router

    - Translates URL into nested templates.
    - Keep browser address line updated.

    ``` js
    App.Router.map(function() {
    @@ -23,3 +29,19 @@ App.Router.map(function() {
    this.route('project', { path: '/about' });
    });
    ```

    ### Route

    - An object that tells model which template to show.

    ### View

    - ?

    ### Controller

    - ?

    ### Component

    - Reusable UI element.
  25. @dreikanter dreikanter created this gist Jan 11, 2015.
    25 changes: 25 additions & 0 deletions emberjs-cheat-sheet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    Core concepts:

    - Template
    - Templates are written in Handlebars.
    - Each template has a name (file name or `data-template-name` attribute value of `<script>` element).
    - Each template is backed by a model and auto-updates following model changes.
    - Router
    - Route
    - Model
    - View
    - Controller


    ## Router

    ``` js
    App.Router.map(function() {
    this.resource('tasks', function() {
    this.route('task', { path: '/:task_id' });
    });

    this.route('user');
    this.route('project', { path: '/about' });
    });
    ```