私は Ember Guru ではありませんが、Ember コミュニティがコンポーネント ベースの未来を受け入れる際にスタイルシートに関して採用している、いくつかの役立つ規則とツールについて説明したいと思います。
注:ember-cliとscss.
この投稿から: An Agile Design Manifesto . 利点を得るために、すべてのスタイルシートを Pod 構造に挿入する必要はありません...
「ルートとコンポーネントで SCSS を整理する」
コンポーネントの場合、この記事では、選択をグローバルに維持することを提案しています。
> stylesheets/components/_flash_messages.scss
/*
Base Styling for the Flash Messages component - how it will appear globally.
*/
.flash-messages {
background-color: $default-flash-color;
}
リソースの場合、ID セレクターと Ember の規則を利用して、特定の ID を持つテンプレートが 1 回だけ表示され、SCSS コードが次のようになるようにすることができます。
> 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";
}
これを使用して、グローバル スタイルをオーバーライドし、偽の CSS スコープを作成できます。
インポートされたショー ルート スタイルは次のようになります。
> 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;
}
}
これらの推奨事項を考慮して、 ember-cli-sass-pods のようなモジュールを使用して、ルートまたはコンポーネント ポッドでスタイルシートを生成できるようにすることができます。@import次に、ファイル内の生成されたファイルに宣言を追加する必要がありapp.scssます。