Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Using haml coffee script for JS templating

  • Loading branch information...
commit 1ca91eba53130662e6b6a060fb472527c2a696b7 1 parent d54ccbd
@craigambrose authored
View
47 .rvmrc
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
+environment_id="ruby-1.9.3-p125"
+
+#
+# Uncomment following line if you want options to be set only for given project.
+#
+# PROJECT_JRUBY_OPTS=( --1.9 )
+
+#
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+#
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
+ then
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
+ fi
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ if ! rvm --create "$environment_id"
+ then
+ echo "Failed to create RVM environment '${environment_id}'."
+ exit 1
+ fi
+fi
+
+#
+# If you use an RVM gemset file to install a list of gems (*.gems), you can have
+# it be automatically loaded. Uncomment the following and adjust the filename if
+# necessary.
+#
+# filename=".gems"
+# if [[ -s "$filename" ]] ; then
+# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
+# fi
+
View
2  Gemfile
@@ -13,6 +13,8 @@ gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
+ gem 'haml_coffee_assets'
+ gem 'execjs' # required by haml_coffee_assets
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platform => :ruby
View
6 Gemfile.lock
@@ -42,6 +42,10 @@ GEM
erubis (2.7.0)
execjs (1.3.2)
multi_json (~> 1.0)
+ haml_coffee_assets (0.9.0)
+ execjs (>= 1.2.9)
+ sprockets (>= 2.0.3)
+ tilt (>= 1.3.3)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
@@ -132,6 +136,8 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
+ execjs
+ haml_coffee_assets
jquery-rails
rails (= 3.2.3)
rails-backbone
View
1  app/assets/javascripts/application.js
@@ -17,5 +17,6 @@
//= require backbone
//= require backbone_rails_sync
//= require backbone_datalink
+//= require hamlcoffee
//= require backbone/village_hire
//= require_tree .
View
19 app/assets/javascripts/backbone/templates/tools/edit.hamlc
@@ -0,0 +1,19 @@
+%h1 Edit tool
+
+%form#edit-tool{:name => "tool"}
+ .field
+ %label{:for => "code"} code:
+ %input#code{:type => "text", :name => "code", :value => @code}
+
+ .field
+ %label{:for => "name"} name:
+ %input#name{:type => "text", :name => "name", :value => @name}
+
+ .field
+ %label{:for => "description"} description:
+ %input#description{:type => "text", :name => "description", :value => @description}
+
+ .actions
+ %input{:type => 'submit', :value => 'Update Tool'}
+
+%a{:href => "#/index"} Back
View
25 app/assets/javascripts/backbone/templates/tools/edit.jst.ejs
@@ -1,25 +0,0 @@
-<h1>Edit tool</h1>
-
-<form id="edit-tool" name="tool">
- <div class="field">
- <label for="code"> code:</label>
- <input type="text" name="code" id="code" value="<%= code %>" >
- </div>
-
- <div class="field">
- <label for="name"> name:</label>
- <input type="text" name="name" id="name" value="<%= name %>" >
- </div>
-
- <div class="field">
- <label for="description"> description:</label>
- <input type="text" name="description" id="description" value="<%= description %>" >
- </div>
-
- <div class="actions">
- <input type="submit" value="Update Tool" />
- </div>
-
-</form>
-
-<a href="#/index">Back</a>
View
14 app/assets/javascripts/backbone/templates/tools/index.hamlc
@@ -0,0 +1,14 @@
+%h1 Listing tools
+
+%table#tools-table
+ %tr
+ %th Code
+ %th Name
+ %th Description
+ %th
+ %th
+ %th
+
+%br
+
+%a{:href => "#/new"} New Tool
View
16 app/assets/javascripts/backbone/templates/tools/index.jst.ejs
@@ -1,16 +0,0 @@
-<h1>Listing tools</h1>
-
-<table id="tools-table">
- <tr>
- <th>Code</th>
- <th>Name</th>
- <th>Description</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-</table>
-
-<br/>
-
-<a href="#/new">New Tool</a>
View
19 app/assets/javascripts/backbone/templates/tools/new.hamlc
@@ -0,0 +1,19 @@
+%h1 New tool
+
+%form#new-tool{:name => "tool"}
+ .field
+ %label{:for => "code"} code:
+ %input#code{:type => "text", :name => "code", :value => @code}
+
+ .field
+ %label{:for => "name"} name:
+ %input#name{:type => "text", :name => "name", :value => @name}
+
+ .field
+ %label{:for => "description"} description:
+ %input#description{:type => "text", :name => "description", :value => @description}
+
+ .actions
+ %input{:type => 'submit', :value => 'Update Tool'}
+
+%a{:href => "#/index"} Back
View
25 app/assets/javascripts/backbone/templates/tools/new.jst.ejs
@@ -1,25 +0,0 @@
-<h1>New tool</h1>
-
-<form id="new-tool" name="tool">
- <div class="field">
- <label for="code"> code:</label>
- <input type="text" name="code" id="code" value="<%= code %>" >
- </div>
-
- <div class="field">
- <label for="name"> name:</label>
- <input type="text" name="name" id="name" value="<%= name %>" >
- </div>
-
- <div class="field">
- <label for="description"> description:</label>
- <input type="text" name="description" id="description" value="<%= description %>" >
- </div>
-
- <div class="actions">
- <input type="submit" value="Create Tool" />
- </div>
-
-</form>
-
-<a href="#/index">Back</a>
View
13 app/assets/javascripts/backbone/templates/tools/show.hamlc
@@ -0,0 +1,13 @@
+%p
+ %strong Code:
+ = @code
+
+%p
+ %strong Name:
+ = @name
+
+%p
+ %strong Description:
+ = @description
+
+%a{:href => "#/index"} Back
View
17 app/assets/javascripts/backbone/templates/tools/show.jst.ejs
@@ -1,17 +0,0 @@
-<p>
- <b>Code:</b>
- <%= code %>
-</p>
-
-<p>
- <b>Name:</b>
- <%= name %>
-</p>
-
-<p>
- <b>Description:</b>
- <%= description %>
-</p>
-
-
-<a href="#/index">Back</a>
View
10 app/assets/javascripts/backbone/templates/tools/tool.hamlc
@@ -0,0 +1,10 @@
+%td= @code
+%td= @name
+%td= @description
+
+%td
+ %a{:href => "#/#{@id}"} Show
+%td
+ %a{:href => "#/#{@id}/edit"} Edit
+%td
+ %a{:href => "#/#{@id}/destroy"} Destroy
View
7 app/assets/javascripts/backbone/templates/tools/tool.jst.ejs
@@ -1,7 +0,0 @@
-<td><%= code %></td>
-<td><%= name %></td>
-<td><%= description %></td>
-
-<td><a href="#/<%= id %>">Show</td>
-<td><a href="#/<%= id %>/edit">Edit</td>
-<td><a href="#/<%= id %>/destroy" class="destroy">Destroy</a></td>
View
11 app/controllers/tools_controller.rb
@@ -1,13 +1,8 @@
class ToolsController < ApplicationController
- # GET /tools
- # GET /tools.json
- def index
- @tools = Tool.all
+ respond_to :html, :json
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @tools }
- end
+ def index
+ respond_with(@tools = Tool.all)
end
# GET /tools/1
View
3  app/models/tool.rb
@@ -1,3 +1,6 @@
class Tool < ActiveRecord::Base
attr_accessible :code, :description, :name
+
+ def as_json(options = {}) super(options.merge(:only => [:id, :code, :description, :name, :created_at]))
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.