6

I am reading http://www.ember-cli.com/#stylesheets which says:

Ember CLI supports plain CSS out of the box. You can add your css styles to app/styles/app.css and it will be served at assets/application-name.css.

Is there a folder structure convention I should follow? Something like:

app/styles/application.css
app/styles/users/index.css
app/styles/users/new.css
etc

Or is the convention to store all custom css in app.css?

Is there special consideration I should take into account when applying this to a Pods app?

Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215

3 Answers3

4

You are not alone in the struggles of dealing with the dreaded global CSS problems that make growing an app unwieldy.

Luckily for you a solution is just around the corner in Ember 2.0 which will be dropping this summer. You can take advantage of this feature now however if you are feeling up to it or simply want to see what I'm talking about in regard to Ember Component CSS by a core member of Ember.js.

https://www.npmjs.com/package/ember-component-css

This isn't a full solution to your problem of course because its simply for components, but since components are an essential part of the Ember workflow now I think you'll find that stashing the CSS/SASS with them will be handy in a pods folder structure.

Most people seem to be breaking css files down into folders named after their routes for organizational purposes.

Update: Pods will be deprecated in a future version of Ember in favor of the Ember core team's new adaptation of a module unification system for managing project resources. You can read more here: https://github.com/emberjs/rfcs/blob/master/text/0143-module-unification.md

Branden Silva
  • 1,406
  • 1
  • 11
  • 15
  • Not to confuse you but so far this is just a standalone addon. It just requires Ember 2.0 and a pods structure to work. But who knows, one day it may make it into core though if it gets enough love. – Branden Silva Apr 16 '15 at 01:18
4

We develop add-on that lets you put your sass files in your pods directory!

Give it a try:

https://github.com/DudaDev/ember-cli-sass-pods

Say you got contacts route and contact-box component.

Generate regular route and component:

ember g route contacts -p
ember g component contact-box -p

Then, use ember-cli-sass-pods power and generate style:

ember g style contacts -p
ember g style components/contact-box -p

Your awesome file structure would be:

app/

app/contacts
app/contacts/route.js
app/contacts/template.hbs
app/contacts/style.scss

app/components/
app/components/contact-box
app/components/contact-box/component.js
app/components/contact-box/template.hbs
app/components/contact-box/style.scss
justtal
  • 800
  • 1
  • 7
  • 16
1

I'm no Ember Guru, however I wanted to chime in with some helpful conventions and tools the Ember community is adopting regarding stylesheets as we embrace a component based future.

Note requires: ember-cli and scss.

Via this post: An Agile Design Manifesto. You don't necessary need to insert all your stylesheets into a pod structure, to get the benefits, as long as you...

"Organize SCSS by Route & Component"

For components, the article suggests you want to keep your selections global:

> stylesheets/components/_flash_messages.scss

/* 
Base Styling for the Flash Messages component - how it will appear globally.
*/
.flash-messages {
  background-color: $default-flash-color;
}

For resources you can leverage ID selectors and Ember's conventions to ensure that a template with a given ID only appears once and your SCSS code might look like:

> stylesheets/routes/_posts.scss

/* 
Global Styling for the "Posts" resource.  
It's an ID because it's guaranteed to only ever appear on the page once.
Thanks Ember!
*/
#posts {
  @import "show";
  @import "new";
  @import "edit";
}

You can use this to override global styling and create a faux CSS scope.

The imported show route styles could then be:

> stylesheets/routes/posts/_show.scss

/* 
Styling here is specifically for this on the "Show" route of the "Posts" resource.  
Most likely, it's empty, but it's a good place to override the global appearance of components, and ensure those changes are contained to this route only. 
*/

#posts-show {
  .flash-messages {
    background-color: $posts-show-flash-color;
  }
}

Given these recommendations you could use a module like: ember-cli-sass-pods to allow you to generate stylesheets in your routes or component pods. You would then need to add the @import declarations to the generated files in your app.scss file.

Matt Jensen
  • 1,495
  • 17
  • 21