-
Notifications
You must be signed in to change notification settings - Fork 33
WIP: [best practice] add web-assets.rst #317
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
Merged
hidenorigoto
merged 2 commits into
symfony-japan-old:master
from
okapon:best-practice-okapon
Nov 6, 2014
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
Webアセット | ||
========== | ||
|
||
Webアセットとは、CSSやJavaScript、画像といった、Webサイトのフロントエンドの | ||
見た目や操作のためのファイルのことを指します。Symfony開発者は慣習的に、それぞれの | ||
バンドルの ``Resources/public/`` ディレクトリにアセットを配置してきました。 | ||
|
||
.. best-practice:: | ||
|
||
アセットは ``web/`` ディレクトリの中に配置しましょう。 | ||
|
||
Webアセットを複数の異なるバンドルに跨って分散させてしまうと管理するのが | ||
大変になります。全てのアプリケーションアセットが一箇所にまとまっていれば、 | ||
デザイナーの仕事はずっと楽になるでしょう。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. designers' lives will be much easier を「デザイナーの仕事はずっと楽になる」と訳しました。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
アセットを集中管理することで、テンプレートも恩恵を受けることができます。 | ||
なぜなら、リンクがより簡潔になるからです。: | ||
|
||
.. code-block:: html+jinja | ||
|
||
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}" /> | ||
<link rel="stylesheet" href="{{ asset('css/main.css') }}" /> | ||
|
||
{# ... #} | ||
|
||
<script src="{{ asset('js/jquery.min.js') }}"></script> | ||
<script src="{{ asset('js/bootstrap.min.js') }}"></script> | ||
|
||
.. note:: | ||
|
||
``web/`` は公開ディレクトリであり、配置されているものは全て一般にアクセスできる | ||
ことに気をつけましょう。そのようあな理由から、コンパイルされたwebアセットだけを | ||
を配置し、Sassのようなソースファイルは配置するべきではありません。 | ||
|
||
アセティックを利用する | ||
------------- | ||
|
||
近頃は、単に静的なCSSやJavascriptファイルを作ってテンプレートに埋め込むことは | ||
おそらくしないでしょう。それどころか、クライアントサイドのパフォーマンスを改善 | ||
するために、ファイルを結合し圧縮したいと考えることでしょう。 | ||
また、LESSやSassのようなものを使いたいと思うかも知れません。それらをCSSファイル | ||
に変換するためには何らかの方法が必要です。 | ||
|
||
GruntJSのような(PHPではない)ピュアフロントエンドツールを含めて、これらの問題を | ||
解決するためたくさんのツールが存在しています。 | ||
|
||
.. best-practice:: | ||
|
||
GruntJSのようなフロントエンドツールに満足していないなら、Asseticを使って | ||
webアセットを結合し圧縮しましょう。 | ||
|
||
`Assetic`_ は、LESSやSassやCoffeScriptといった多くのフロントエンドツールで | ||
開発されたアセットをコンパイルすることができるAssetマネージャです。 | ||
Asseticで全てのアセットを結合するには、1つのTwigタグで全てのアセットを | ||
囲みます。 | ||
|
||
.. code-block:: html+jinja | ||
|
||
{% stylesheets | ||
'css/bootstrap.min.css' | ||
'css/main.css' | ||
filter='cssrewrite' output='css/compiled/all.css' %} | ||
<link rel="stylesheet" href="{{ asset_url }}" /> | ||
{% endstylesheets %} | ||
|
||
{# ... #} | ||
|
||
{% javascripts | ||
'js/jquery.min.js' | ||
'js/bootstrap.min.js' | ||
output='js/compiled/all.js' %} | ||
<script src="{{ asset_url }}"></script> | ||
{% endjavascripts %} | ||
|
||
フロントエンドベースのアプリケーション | ||
--------------------------- | ||
|
||
近年、APIと通信を行うフロントエンドWEBアプリケーションを開発する場合、AngularJS | ||
のようなフロントエンド技術を利用することはずいぶん一般的になりました。 | ||
|
||
もしこのようなアプリケーションを開発する場合には、BowerやGruntJSのような、 | ||
その技術で推奨されているツールを使うとよいでしょう。 | ||
Symfonyバックエンドとは切り離してフロントエンドアプリケーションを開発するべきです。 | ||
バージョン管理システムのリポジトリを分離したい場合にはなおさらです。 | ||
|
||
|
||
Asseticをもっと知るために | ||
------------------------ | ||
|
||
Assetic は `UglifyCSS/UglifyJSを使う`_ ことでCSSやJavaScriptのサイズを小さくして | ||
ウェブサイトの高速化を図ることができます。Asseticの `画像の圧縮`_ 機能を使うことで、 | ||
ユーザーからリクエストされた画像をその場で圧縮してから返すようにもできます。 | ||
利用可能な機能を知りたければ `公式のAsseticドキュメント`_ を参照してください。 | ||
|
||
.. _`Assetic`: http://symfony.com/doc/current/cookbook/assetic/asset_management.html | ||
.. _`UglifyCSS/UglifyJSを使う`: http://symfony.com/doc/current/cookbook/assetic/uglifyjs.html | ||
.. _`画像の圧縮`: http://symfony.com/doc/current/cookbook/assetic/jpeg_optimize.html | ||
.. _`公式のAsseticドキュメント`: https://github.com./kriswallsmith/assetic |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symfony developers have traditionally stored these assets ~
の部分ですが「慣習的に」と訳しましたが、大丈夫でしょうか?菱田さんは「伝統的に」と翻訳されてました。
https://github.com./symfony-japan/symfony-docs-ja/pull/316/files#diff-bb96593a7a270f89d21571e736b4861eR24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @77web
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@okapon @hidenorigoto 特にこだわりはないので「慣習的に」に合わせますー
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@77web ありがとうございますー