【Meteor】 CoffeeScript で開発する

【Meteor】 はじめての Meteor

Meteor ではパッケージを簡単にインストールすることができます。

今回はストレスなく開発を進めるために CoffeeScript を使えるようにします。



$ meteor list

accounts-base          A user account system
accounts-facebook      Login service for Facebook accounts
accounts-github        Login service for Github accounts
accounts-google        Login service for Google accounts
accounts-meetup        Login service for Meetup accounts
accounts-password      Password support for accounts.
accounts-twitter       Login service for Twitter accounts
accounts-ui            Simple templates to add login widgets to an app.
accounts-ui-unstyled   Unstyled version of login widgets
accounts-weibo         Login service for Sina Weibo accounts
amplify                API for Persistant Storage, PubSub and Request
appcache               enable the application cache in the browser
audit-argument-checks  Try to detect inadequate input sanitization
autopublish            Automatically publish the entire database to all clients
backbone               A minimalist client-side MVC framework
bootstrap              Front-end framework from Twitter
code-prettify          Syntax highlighting of code, from Google
coffeescript           Javascript dialect with fewer braces and semicolons
d3                     Library for manipulating documents based on data.
ejson                  Extended and Extensable JSON library
email                  Send email messages
force-ssl              Require this application to use secure transport (HTTPS)
handlebars             Simple semantic templating language
htmljs                 Easy macros for generating DOM elements in Javascript
http                   Make HTTP calls to remote servers
insecure               Allow all database writes by default
jquery                 Manipulate the DOM using CSS selectors
jquery-history         pushState module from the jQuery project
jquery-layout          Easily create arbitrary multicolumn layouts
jquery-waypoints       Execute a function when the user scrolls past an element
less                   The dynamic stylesheet language.
madewith               Made With Meteor badge
preserve-inputs        Automatically preserve all form fields with a unique id
showdown               Markdown-to-HTML processor
spiderable             Makes the application crawlable to web spiders.
stylus                 Expressive, dynamic, robust CSS.
underscore             Collection of small helper functions: _.map, _.each, ...

次に coffeescript をインストールします。

Coffeescript パッケージをインストールする

$ meteor add coffeescript

coffeescript: Javascript dialect with fewer braces and semicolons
$ mv demo.js demo.coffee

demo.coffee を CoffeeScript で書き換える

# demo.coffee

if Meteor.isClient
  Template.hello.greeting = ->
    "Welcome to demo."

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

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

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