Permalink
Browse files

First import

  • Loading branch information...
0 parents commit 3a96ffc0472e991746921eb510f75fbcbdacba8f @topfunky committed Sep 10, 2008
Showing with 8,823 additions and 0 deletions.
  1. +10 −0 Rakefile
  2. +15 −0 app/controllers/application.rb
  3. +2 −0 app/controllers/fields_controller.rb
  4. +60 −0 app/controllers/notes_controller.rb
  5. +3 −0 app/helpers/application_helper.rb
  6. +2 −0 app/helpers/fields_helper.rb
  7. +9 −0 app/helpers/notes_helper.rb
  8. +91 −0 app/models/basic_model.rb
  9. +8 −0 app/models/note.rb
  10. +22 −0 app/views/layouts/application.html.erb
  11. +19 −0 app/views/notes/_form.html.erb
  12. +3 −0 app/views/notes/edit.html.erb
  13. +7 −0 app/views/notes/index.html.erb
  14. +3 −0 app/views/notes/new.html.erb
  15. +7 −0 app/views/notes/show.html.erb
  16. +109 −0 config/boot.rb
  17. +19 −0 config/database.yml
  18. +73 −0 config/environment.rb
  19. +17 −0 config/environments/development.rb
  20. +22 −0 config/environments/production.rb
  21. +22 −0 config/environments/test.rb
  22. +10 −0 config/initializers/inflections.rb
  23. +5 −0 config/initializers/mime_types.rb
  24. +15 −0 config/initializers/new_rails_defaults.rb
  25. +42 −0 config/routes.rb
  26. 0 db/development.sqlite3
  27. +2 −0 doc/README_FOR_APP
  28. BIN public/.DS_Store
  29. +30 −0 public/404.html
  30. +30 −0 public/422.html
  31. +30 −0 public/500.html
  32. +10 −0 public/dispatch.cgi
  33. +24 −0 public/dispatch.fcgi
  34. +10 −0 public/dispatch.rb
  35. 0 public/favicon.ico
  36. BIN public/images/note.png
  37. BIN public/images/rails.png
  38. +13 −0 public/javascripts/application.js
  39. +963 −0 public/javascripts/controls.js
  40. +177 −0 public/javascripts/date_selector.js
  41. +972 −0 public/javascripts/dragdrop.js
  42. +1,120 −0 public/javascripts/effects.js
  43. +320 −0 public/javascripts/lowpro.js
  44. +4,225 −0 public/javascripts/prototype.js
  45. +5 −0 public/robots.txt
  46. +60 −0 public/stylesheets/application.css
  47. +80 −0 public/stylesheets/sass/application.sass
  48. +54 −0 public/stylesheets/scaffold.css
  49. +3 −0 script/about
  50. +3 −0 script/console
  51. +3 −0 script/dbconsole
  52. +3 −0 script/destroy
  53. +3 −0 script/generate
  54. +3 −0 script/performance/benchmarker
  55. +3 −0 script/performance/profiler
  56. +3 −0 script/performance/request
  57. +3 −0 script/plugin
  58. +3 −0 script/process/inspector
  59. +3 −0 script/process/reaper
  60. +3 −0 script/process/spawner
  61. +3 −0 script/runner
  62. +3 −0 script/server
  63. +8 −0 test/functional/fields_controller_test.rb
  64. +8 −0 test/functional/notes_controller_test.rb
  65. +38 −0 test/test_helper.rb
  66. +7 −0 vendor/plugins/haml/init.rb
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,15 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ protect_from_forgery # :secret => '1473d82c87ff75589db6723e090f26ac'
+
+ # See ActionController::Base for details
+ # Uncomment this to filter the contents of submitted sensitive data parameters
+ # from your application log (in this case, all fields with names like "password").
+ # filter_parameter_logging :password
+end
@@ -0,0 +1,2 @@
+class FieldsController < ApplicationController
+end
@@ -0,0 +1,60 @@
+class NotesController < ApplicationController
+
+ def index
+ @notes = Note.init_from_rows(db.view("notes/by_title"))
+ respond_to do |wants|
+ wants.html
+ wants.json { render :json => @notes.rows.to_json }
+ end
+ end
+
+ def show
+ @note = Note.new(db.get(params[:id]))
+ respond_to do |wants|
+ wants.html
+ wants.json { render :json => @note.attributes.to_json }
+ end
+ end
+
+ def new
+ @note = Note.new
+ end
+
+ def create
+ result = db.save(params[:note])
+ respond_to do |wants|
+ wants.html { redirect_to note_url(result["id"]) }
+ end
+ end
+
+ def edit
+ @note = Note.new(db.get(params[:id]))
+ end
+
+ def update
+ @note = Note.new(db.get(params[:id]))
+ @note.updated_at = DateTime.now
+ if db.save(@note.update(params[:note]))
+ respond_to do |wants|
+ wants.html { redirect_to note_url(@note) }
+ end
+ else
+ respond_to do |wants|
+ wants.html { render :action => "edit" }
+ end
+ end
+ end
+
+ def destroy
+ end
+
+ private
+
+ def db
+ @@couchrest ||= CouchRest.new(COUCHDB_SERVER)
+ # TODO Run creation tasks, load views, etc.
+ @@couchrest.create_db("travel_topfunky") rescue nil
+ @db = @@couchrest.database("travel_topfunky")
+ end
+
+end
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module FieldsHelper
+end
@@ -0,0 +1,9 @@
+module NotesHelper
+
+ def couchdb_rev_field(form, record)
+ unless record.new_record?
+ form.hidden_field("_rev")
+ end
+ end
+
+end
@@ -0,0 +1,91 @@
+##
+# A simple class to help use CouchDB and CouchRest with Rails.
+#
+# You should subclass this so routes are properly generated when making forms.
+#
+# class Note < BasicModel; end
+#
+# couch_rest = CouchRest.new('http://localhost:5984')
+# db = couch_rest.database('my_db')
+# note = Note.new(db.get('22323232'))
+# result = db.save(note.attributes)
+#
+
+class BasicModel
+
+ attr_accessor :attributes
+
+ ##
+ # Takes a record from CouchRest ID call and turns it into something
+ # usable in Rails.
+ #
+ # note = Note.new(db.get('283934927362'))
+ # note.id
+ # note._rev
+ # note.new_record?
+ # note.title # Any field from the record
+
+ def initialize(attributes={})
+ @attributes = attributes
+ end
+
+ ##
+ # Takes a set of results from a CouchRest view call and turns the
+ # rows into Rails-friendly objects.
+ #
+ # notes = Note.init_from_rows(db.view("notes/by_title"))
+ # notes.rows.each {|row| row.id ... }
+
+ def self.init_from_rows(couchdb_results=[])
+ results = self.new(couchdb_results)
+ results.rows.each_with_index do |row, index|
+ results.rows[index] = self.new(row['value'])
+ end
+ results
+ end
+
+ ##
+ # Takes a Hash, merges with existing attributes, and returns them with
+ # the intent that they will be serialized to JSON.
+
+ def update(attributes)
+ @attributes.merge(attributes)
+ end
+
+ def id
+ _id rescue nil
+ end
+ alias_method :to_param, :id
+
+ def new_record?
+ (_id && _rev).nil?
+ rescue NameError
+ true
+ end
+
+ # def self.json_create(o)
+ # new(*o['data'])
+ # end
+ #
+ # def to_json(*a)
+ # {
+ # 'json_class' => self.class.name,
+ # 'data' => @attributes
+ # }.to_json(*a)
+ # end
+
+ def method_missing(method_symbol, *arguments)
+ method_name = method_symbol.to_s
+
+ case method_name[-1..-1]
+ when "="
+ @attributes[method_name[0..-2]] = arguments.first
+ when "?"
+ @attributes[method_name[0..-2]] == true
+ else
+ # Returns nil on failure so forms will work
+ @attributes.has_key?(method_name) ? @attributes[method_name] : nil
+ end
+ end
+
+end
@@ -0,0 +1,8 @@
+class Note < BasicModel
+
+ def initialize(attributes={})
+ defaults = {"title" => nil, "description" => nil}
+ super(defaults.merge(attributes))
+ end
+
+end
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>Notes: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold', 'application' %>
+ <%= javascript_include_tag :defaults, "lowpro", "date_selector" %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<div class="container">
+ <%= yield %>
+
+ <div id="home"><%= link_to "Home", root_url %></div>
+</div>
+
+</body>
+</html>
@@ -0,0 +1,19 @@
+<% form_for @note do |f| %>
+
+ <%= couchdb_rev_field f, @note %>
+
+ <%= f.label "Title" %>
+ <%= f.text_field :title %>
+
+ <%= f.label "Description" %>
+ <%= f.text_area :description %>
+
+ <%= f.label "Tags (separated by spaces)" %>
+ <%= f.text_field "tags" %>
+
+ <%= f.label "Visited On" %>
+ <%= f.text_field "visited_on", :id => "date" %>
+
+ <%= f.submit "Save" %>
+
+<% end %>
@@ -0,0 +1,3 @@
+<h1 id="title"><%= @note.title %></h1>
+
+<%= render :partial => "form" %>
@@ -0,0 +1,7 @@
+<h1>Your Notes</h1>
+
+<% @notes.rows.each do |note| %>
+ <h2><%= link_to note.title, note_path(note) %></h2>
+ <p><%= note.description %></p>
+ <p><%= link_to "Edit", edit_note_path(note) %></p>
+<% end %>
@@ -0,0 +1,3 @@
+<h1 id="title">Note</h1>
+
+<%= render :partial => "form" %>
@@ -0,0 +1,7 @@
+<h1 id="title"><%= @note.title %></h1>
+
+<small>Updated <%= @note.updated_at.to_s(:rfc822) rescue "?" %></small>
+
+<p><%= @note.description %></p>
+
+<p><%= link_to "Edit", edit_note_path(@note) %></p>
@@ -0,0 +1,109 @@
+# Don't change this file!
+# Configure your app in config/environment.rb and config/environments/*.rb
+
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+
+module Rails
+ class << self
+ def boot!
+ unless booted?
+ preinitialize
+ pick_boot.run
+ end
+ end
+
+ def booted?
+ defined? Rails::Initializer
+ end
+
+ def pick_boot
+ (vendor_rails? ? VendorBoot : GemBoot).new
+ end
+
+ def vendor_rails?
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
+ end
+
+ def preinitialize
+ load(preinitializer_path) if File.exist?(preinitializer_path)
+ end
+
+ def preinitializer_path
+ "#{RAILS_ROOT}/config/preinitializer.rb"
+ end
+ end
+
+ class Boot
+ def run
+ load_initializer
+ Rails::Initializer.run(:set_load_path)
+ end
+ end
+
+ class VendorBoot < Boot
+ def load_initializer
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
+ Rails::Initializer.run(:install_gem_spec_stubs)
+ end
+ end
+
+ class GemBoot < Boot
+ def load_initializer
+ self.class.load_rubygems
+ load_rails_gem
+ require 'initializer'
+ end
+
+ def load_rails_gem
+ if version = self.class.gem_version
+ gem 'rails', version
+ else
+ gem 'rails'
+ end
+ rescue Gem::LoadError => load_error
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ end
+
+ class << self
+ def rubygems_version
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ end
+
+ def gem_version
+ if defined? RAILS_GEM_VERSION
+ RAILS_GEM_VERSION
+ elsif ENV.include?('RAILS_GEM_VERSION')
+ ENV['RAILS_GEM_VERSION']
+ else
+ parse_gem_version(read_environment_rb)
+ end
+ end
+
+ def load_rubygems
+ require 'rubygems'
+
+ unless rubygems_version >= '0.9.4'
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ exit 1
+ end
+
+ rescue LoadError
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ exit 1
+ end
+
+ def parse_gem_version(text)
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
+ end
+
+ private
+ def read_environment_rb
+ File.read("#{RAILS_ROOT}/config/environment.rb")
+ end
+ end
+ end
+end
+
+# All that for this:
+Rails.boot!
Oops, something went wrong.

0 comments on commit 3a96ffc

Please sign in to comment.