テンプレートエンジンSlimを使ってスマートにHTMLを作成する 昨日うちの事務所で開催したagatsuma.survive#02の中でSlimの説明が思ったよりも好評だったので改めてまとめてみます。 このエントリでは Slimを使ってHTMLを作成する ことだけを目的としているため、動的にSlimでゴニョゴニョするような話は出て来ません。HTMLの代替にSlimを使う、といった主旨の内容です。プログラムの話も出て来ませんが、残念ながらコマンドラインを少し使います。 Slim とは? 拡張子は .slim view の構文を本質的な部品まで減らすことを目指したテンプレート言語 Ruby製のテンプレートエンジン 高速, 軽量 インデント重要 用途 Railsプロジェクトのテンプレート Sinatra(Padorino)のテンプレート HTMLの代替(個人的には) SlimでHTMLを作成する
元ネタ: マークアッパー的 Haml入門21の手引き Slim は Ruby 製のテンプレートエンジンで HTML を効率的に生成するための記法です。Jade と Haml の影響を受けています。 元ネタのブログ記事が良さげな感じだったので Slim 版を試しに書いてみることにしました。Haml にあって Slim に無い機能もありますが, そのまま当て込んで書いています。 ※ ターミナルでコマンド実行を記述する場合 $ command のように頭に $ をつけて記述しています。 目次 Slim を使えるようにする Slim を HTML に変換する 基本の記法 テキストの扱い 入れ子(ネスト)も可能 一行で出力したい場合 タグ間の空白/改行をコントロール 属性をつける id と class をつける コメントアウト IE条件分岐コメントアウト Slim ファイルのみのコメント DOCTY
静的ウェブサイト生成ツール(面倒なので以下Jekyllみたいなの)と動的ウェブログ・システム(同じくWordPressみたいなの)のそれぞれの長所や短所はみなよく知っているようで、よりその人の状況にあったどちらかを選んだみたいな記事をよく見る。そういうの見る度にどうして両方使わないんだろうと思う。 静的なHTMLでのウェブサイトの運営は簡単で楽だしコストも掛からず、環境もあまり選ばない。けどMovable Typeでの破綻を引き合いに出すまでもなく、1000やそれ以上のHTMLを生成できる無理のないシステムはあるのかというと微妙な感じがする。で、規模に応じて動的なCMSと使い分ければ……となることが多いわけだけど、使い分けるのではなくJekyllみたいなのとWordPressみたいなのを組み合わせるのが良いのではないか。 テンプレート 分けちゃうとテンプレートの管理も分かれて面倒くさいとか
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く