Oct 16 2010
- 04/10/2011 - Updated application.js and application.rb thanks to @rebo's comments
In this article, I will walk through some simple steps to get a [demo app][2] up and running with [Backbone.js][3] and [Sinatra][4] on [Heroku][5].
| /** @jsx React.DOM */ | |
| var STATES = [ | |
| 'AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', | |
| 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', | |
| 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', | |
| 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY' | |
| ] | |
| var Example = React.createClass({ |
| ;; | |
| ;; NS CHEATSHEET | |
| ;; | |
| ;; * :require makes functions available with a namespace prefix | |
| ;; and optionally can refer functions to the current ns. | |
| ;; | |
| ;; * :import refers Java classes to the current namespace. | |
| ;; | |
| ;; * :refer-clojure affects availability of built-in (clojure.core) | |
| ;; functions. |
| (def history (Html5History.)) | |
| (.setUseFragment history false) | |
| (.setPathPrefix history "") | |
| (.setEnabled history true) | |
| (let [navigation (listen history EventType/NAVIGATE)] | |
| (go | |
| (while true | |
| (let [token (.-token (<! navigation))] | |
| (secretary/dispatch! token))))) |
| require "sinatra/base" | |
| require "sinatra/namespace" | |
| require "multi_json" | |
| require "api/authentication" | |
| require "api/error_handling" | |
| require "api/pagination" | |
| module Api | |
| class Base < ::Sinatra::Base |
| (ns three.demo) | |
| (def camera (THREE.Camera. 75 (/ window/innerWidth | |
| window/innerHeight) 1 10000)) | |
| (set! (.z (.position camera)) 1000) | |
| (def scene (THREE.Scene.)) | |
| (def geometry (THREE.CubeGeometry. 200 200 200)) | |
| (def obj (js/Object.)) | |
| (set! (.color obj) 0xff0000) | |
| (set! (.wireframe obj) true) | |
| (def material (THREE.MeshBasicMaterial. obj)) |
| $ rails console | |
| Loading development environment (Rails 3.0.6) | |
| ruby-1.8.7-p334 :001 > r = Rails.application.routes | |
| Gives you a handle of all the routes (config/routes.rb) | |
| #Inspect a named route: | |
| ruby-1.8.7-p334 :005 > r.recognize_path(app.destroy_user_session_path) | |
| => {:action=>"destroy", :controller=>"sessions"} |
| # encoding: UTF-8 | |
| Capistrano::Configuration.instance(:must_exist).load do | |
| namespace :rails do | |
| desc "Open the rails console on one of the remote servers" | |
| task :console, :roles => :app do | |
| hostname = find_servers_for_task(current_task).first | |
| exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'" | |
| end | |
| end |
| // installed Clojure packages: | |
| // | |
| // * BracketHighlighter | |
| // * lispindent | |
| // * SublimeREPL | |
| // * sublime-paredit | |
| { | |
| "word_separators": "/\\()\"',;!@$%^&|+=[]{}`~?", | |
| "paredit_enabled": true, |