Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds naming conventions documentation #223

Merged
merged 4 commits into from
Oct 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ guides:
page: "/guides/deployment.html"
- name: "Using With Ember Data"
page: "/guides/ember-data.html"
- name: "Naming Conventions"
page: "/guides/naming-conventions.html"
- name: "Frequently Asked Questions"
page: "/guides/faq.html"

Expand Down
88 changes: 88 additions & 0 deletions guides/naming-conventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
layout: default
title: "Naming Conventions"
permalink: naming-conventions.html
---

When using Ember App Kit its important to keep in mind that the Resolver changes some of the naming conventions you would typically use out of the box with Ember, Ember Data and Handlebars. In this section we review some of these naming conventions.

### Views and Templates

Let's say we were using Ember out of the box with the following view:

{% highlight sh %}
App.UserView = Ember.View.extend({});
{% endhighlight %}

We could easily embed this view into a container/parent using the Handlebars view helper:

{% highlight sh %}
{% raw %}
{{ view App.UserView }}
{% endraw %}
{% endhighlight %}

This is great. However, Ember App Kit cusotmizes the default Ember Resolver to help alleviate the issue of namespacing your objects (views, controllers, models, etc.) manually. The above example, as such, will not work in an EAK project.

In EAK our view would be declared like so:

{% highlight sh %}
var UserView = Ember.View.extend({});

export default UserView;
{% endhighlight %}

We can then embed our view using the following convention:

{% highlight sh %}
{% raw %}
{{view 'user'}}
{% endraw %}
{% endhighlight %}

> Please note that we did not namespace UserView. The resolver takes care of this for you. For more information about the default Ember resolver, check out the source [here](https://github.com/emberjs/ember.js/blob/master/packages/ember-application/lib/system/resolver.js).

### Filenames

It is important to keep in mind that the Resolver uses filenames to create the associations correctly. This helps you by not having to namespace everything yourself. But there a couple of things you should know.

#### All filenames should be lowercased

{% highlight sh %}
// models/user.js
var User = Ember.Model.extend();

export default User;
{% endhighlight %}

#### Comma seperated file names are recommended

You may want to name your files according to their function, this is easily accomplished:

{% highlight sh %}
// models/user_model.js
var UserModel = Ember.Model.extend();

export default User;
{% endhighlight %}


#### Nested directories can be referenced

If you prefer to nest your files to better manage your application, you can easily do so.

{% highlight sh %}
// controller/posts/new.js -> controller:posts/new
var PostsNewController = Ember.Controller.extend();

export default PostsNewController;
{% endhighlight %}

If your filename has an underscore in it, we can reference it using the following technique:

{% highlight sh %}
// controller/posts/comment_thread.js -> controller:posts/comment-thread
var CommentThreadPostsController = Ember.Controller.extend();

export default CommentThreadPostsController;
{% endhighlight %}