LoginSignup
10
10

More than 5 years have passed since last update.

meteorの開発にCoffeeScriptとjadeを使う

Posted at

meteorの開発にCoffeeScriptとjadeを使う

今更ながらMeteorで遊んでみることにしました。

私はカッコ閉じるの苦手星人になってしまっているので

-JavaScriptはCoffeeScript
-HTMLはJade

そんな環境を構築してみようと思います。

まずテスト的なプロジェクトを作ります。

meteor create hello

参考サイト

coffee scriptの導入

meteor add coffeescript

↑これだけでOKです。

.meteor/packagesを見てみると、追加されていることが確認できます。

プロジェクトのhello.jsを削除してhello.coffeeを追加します。

if Meteor.isClient
  Template.hello.greeting = ->
    "こんにちわーるど!"

  Template.hello.events "click input": ->

    # template data, if any, is available in 'this'
    console.log "You pressed the button"  if typeof console isnt "undefined"
    return

if Meteor.isServer
  Meteor.startup ->
    # code to run on server at startup

プロジェクトのルートでmeteorしてブラウザで開くとバッチリ反映してます。

jadeの導入

meteorには独自のパッケージマネージャがあるので、まずそれを導入します。

npm install -g meteorite

これでmrtコマンドが使えるのでjadeパッケージをインストールします。

mrt add jade

これでOKです。

hello.htmlを削除してhello.jadeを追加します。

head
  title hello

body
  +hello

template(name="hello")
  h1 Hello coffee!
  !{greeting}
  input(type="button" value="Click")

meteorではテンプレートエンジンとしてHandlebars.js
が使われていますが、その辺りの作法がちょっと違うようです。

{{> hello}}

の部分を

+hello

と書き換えます。

{{greeting}}

の部分を

!{greeting}

と書き換えます

これでjadeも使えそうです。

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10