Skip to content

Instantly share code, notes, and snippets.

View rodriguezartav's full-sized avatar

Roberto Rodriguez rodriguezartav

View GitHub Profile
@rodriguezartav
rodriguezartav / haml-mongo-application.rb
Created October 13, 2011 18:22
config/application.rb snippet for Haml and Mongomapper used by Rails Generators
#this goes in config/application.rb
#just before the closing "end" tag
#it tels rails generators to use Haml and Mongomapper
config.generators do |g|
g.orm :mongo_mapper # :active_record
g.template_engine :haml
g.stylesheet_engine = :sass
g.test_framework :rspec, :fixture => true, :views => false
end
@rodriguezartav
rodriguezartav / mongo.rb
Created October 13, 2011 18:25
config/initializers/mongo.rb it setups mongomapper to be used locally and in heroku with MongoHQ
MongoMapper.config = {
Rails.env => { 'uri' => ENV['MONGOHQ_URL'] ||
"mongodb://localhost/rubyconf_simple_app-#{Rails.env}-1" } }
MongoMapper.connect(Rails.env)
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection.connect if forked
end
@rodriguezartav
rodriguezartav / stitch.rb
Created October 13, 2011 18:26
config/initializers/stitch.rb it setups stitch to compile and include javascript applications templates in the main app file
class TmplCompiler < Stitch::Compiler
extensions :tmpl
def compile(path)
content = File.read(path)
%{var template = jQuery.template(#{content.to_json});
module.exports = (function(data){ return jQuery.tmpl(template, data); });}
end
end
@rodriguezartav
rodriguezartav / routes.rb
Created October 13, 2011 18:28
config/routes.rb snipped for a simple javascript application that uses spine and stitch
[APP_NAME]::Application.routes.draw do
resources :posts
root :to => "pages#home"
match 'home' => "pages#home"
match 'apps/app.js' => Stitch::Server.new(:paths => ["app/assets/javascripts/app", "app/assets/javascripts/lib"])
@rodriguezartav
rodriguezartav / posts.coffee
Created October 13, 2011 18:34
Spine Controller - Simple
Post = require("models/post")
class Posts extends Spine.Controller
elements:
"#post_list" : "post_list"
events:
"click #post_list" : "on_post_click"
@rodriguezartav
rodriguezartav / app.coffee
Created October 13, 2011 18:34
Spine Main Controller
require("spine")
require("ajax")
require("tmpl")
Posts = require("controllers/posts")
class App extends Spine.Controller
elements:
"#posts" : "postsEl"
@rodriguezartav
rodriguezartav / post.coffee
Created October 13, 2011 18:34
Spine Model - Simple
class Post extends Spine.Model
@configure "Post", "name"
@extend Spine.Model.Ajax
module.exports = Post
@rodriguezartav
rodriguezartav / home.html.haml
Created October 13, 2011 18:40
Haml Spine Template
#content
#app_canvas
:javascript
var exports = this;
jQuery(function(){
var App = require("app");
exports.App = new App({el: $("#app_canvas") });
})
@rodriguezartav
rodriguezartav / GEM
Created October 13, 2011 18:43
Gem File for Rails 3.1 that will run a SpineJS App with stitch , mongo, sass and compass
source 'http://rubygems.org'
gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
@rodriguezartav
rodriguezartav / pages_controller.rb
Created October 13, 2011 18:47
Pages Controller
class PagesController < ApplicationController
def home
render 'home' ,:layout => 'js'
end
end