3

私はバックエンドとしてrailsを使用してemberjsでアプリを構築しており(ember-rails gemを使用しています)、ハンドルバーテンプレートに名前を付ける正しい方法に苦労しています。正しい規則は何ですか?例えば:

ルート/user_profiles/4/については、テンプレートをuser_profiles/show.hbs正しく配置する必要があると思いますか?それともそうすべきuserProfile/show.hbsですか?

単純なテンプレートの場合も同じですが、user_menu.hbsまたはuserMenu.hbs(両方とも私のために機能しています)。ただし、ヘルパーでレンダリングするには、次のことを行う必要があります。

{{render 'userMenu' }}

私のApp.UserMenuControllerを正しく使用するには

だから私はどこでもキャメルケースを使うべきですか、それともsnake_caseを使うべきですか?または両方(フォルダーの場合はcamelCase、ファイル名の場合はsnake_case)

残り火のガイドでは、ほとんどが単純な名前であるため、誰かが私にそれを理解するのを手伝ってもらえますかpostscomments

4

2 に答える 2

5

I'm struggling with the correct way to name my handlebars templates. What is the correct convention?

Most of the time the template name will match the route name. If route name has a . replace it with a / and covert camelCase route names to under_scored template names. See the naming conventions guide for more examples.

I imagine that for the route /user_profiles/4/ I should put my template in user_profiles/show.hbs right? Or should it be userProfile/show.hbs?

Not sure where you are getting show.hbs. Since template is based on route names (not urls) it is impossible to tell. Let's assume you've got routes like this:

App.Router.map(function() {
  this.route('user_profile', { path: '/user_profiles/:user_profile_id' });
});

The routes name is "user_profile" so Ember.js will look for these objects:

  • App.UserProfileRoute
  • App.UserProfileController
  • the user_profile template

Alternatively you could use a route name of userProfile, everything else would stay the same.

So Should I use camelCase every where or snake_case ?? or both (camelCase for folders and snake_case for filenames)

Convention seems to be camelCase for everything but template paths (and thus template's foldername/filename)

于 2013-03-12T19:27:38.470 に答える
0

Ember 2.x の命名規則は次のとおりです。

  • ケバブケース
    • ファイル名
    • ディレクトリ名
    • html タグ/ember コンポーネント
    • CSS クラス
    • URL
  • キャメルケース
    • JavaScript
    • JSON

http://ember-cli.com/user-guide/#naming-conventions

于 2016-03-04T00:42:24.380 に答える