Permalink
Browse files

Tag 07 Created

git-svn-id: http://restfulezm.rubyforge.org/svn/tags/0.7/restful_easy_messages@2 2729d79b-15ba-4ce6-ad7d-ed0b230976c8
  • Loading branch information...
0 parents commit c98d77200a968dcc85beb0eff38cddf57ed33280 sschroed committed Oct 16, 2007
Showing with 5,574 additions and 0 deletions.
  1. +18 −0 FILELIST
  2. +1 −0 README
  3. +36 −0 RESTFUL_EZM_ROUTES
  4. +27 −0 Rakefile
  5. +2 −0 TODO
  6. +2 −0 VERSION
  7. +1 −0 generators/messages/USAGE
  8. +53 −0 generators/messages/messages_generator.rb
  9. +30 −0 generators/messages/templates/403.html
  10. +19 −0 generators/messages/templates/create_restful_easy_messages.rb
  11. +15 −0 generators/messages/templates/index.atom.builder
  12. +21 −0 generators/messages/templates/index.haml
  13. +25 −0 generators/messages/templates/index.html.erb
  14. +61 −0 generators/messages/templates/message.rb
  15. +71 −0 generators/messages/templates/message_test.rb
  16. +48 −0 generators/messages/templates/messages.yml
  17. +183 −0 generators/messages/templates/messages_controller.rb
  18. +116 −0 generators/messages/templates/messages_controller_test.rb
  19. +94 −0 generators/messages/templates/messages_helper.rb
  20. +21 −0 generators/messages/templates/new.haml
  21. +31 −0 generators/messages/templates/new.html.erb
  22. +23 −0 generators/messages/templates/restful_easy_messages_controller_system.rb
  23. +23 −0 generators/messages/templates/show.haml
  24. +32 −0 generators/messages/templates/show.html.erb
  25. +54 −0 generators/messages/templates/users.yml
  26. +2 −0 init.rb
  27. +1 −0 install.rb
  28. +119 −0 lib/restful_easy_messages_system.rb
  29. +303 −0 rdoc/classes/Message.html
  30. +386 −0 rdoc/classes/MessageTest.html
  31. +636 −0 rdoc/classes/MessagesController.html
  32. +533 −0 rdoc/classes/MessagesControllerTest.html
  33. +543 −0 rdoc/classes/MessagesHelper.html
  34. +117 −0 rdoc/classes/ProtonMicro.html
  35. +111 −0 rdoc/classes/ProtonMicro/RestfulEasyMessages.html
  36. +147 −0 rdoc/classes/ProtonMicro/RestfulEasyMessages/Messages.html
  37. +196 −0 rdoc/classes/ProtonMicro/RestfulEasyMessages/Messages/ClassMethods.html
  38. +343 −0 rdoc/classes/ProtonMicro/RestfulEasyMessages/Messages/InstanceMethods.html
  39. +1 −0 rdoc/created.rid
  40. +107 −0 rdoc/files/README.html
  41. +101 −0 rdoc/files/__/__/__/app/controllers/messages_controller_rb.html
  42. +107 −0 rdoc/files/__/__/__/app/helpers/messages_helper_rb.html
  43. +101 −0 rdoc/files/__/__/__/app/models/message_rb.html
  44. +108 −0 rdoc/files/__/__/__/test/functional/messages_controller_test_rb.html
  45. +101 −0 rdoc/files/__/__/__/test/unit/message_test_rb.html
  46. +107 −0 rdoc/files/lib/restful_easy_messages_system_rb.html
  47. +36 −0 rdoc/fr_class_index.html
  48. +33 −0 rdoc/fr_file_index.html
  49. +96 −0 rdoc/fr_method_index.html
  50. +24 −0 rdoc/index.html
  51. +208 −0 rdoc/rdoc-style.css
@@ -0,0 +1,18 @@
+app/controllers/messages_controller.rb
+app/helpers/messages_helper.rb
+app/models/message.rb
+app/views/messages/index.atom.builder
+app/views/messages/index.haml
+app/views/messages/index.html.erb
+app/views/messages/new.haml
+app/views/messages/new.html.erb
+app/views/messages/show.haml
+app/views/messages/show.html.erb
+db/migrate/###_create_restful_easy_messages
+lib/restful_easy_messages_controller_system.rb
+public/403.html
+test/fixtures/messages.yml
+test/fixtures/users.yml
+test/functional/messages_controller_test.rb
+test/unit/message_test.rb
+vendor/plugins/restful_easy_messages/*
1 README
@@ -0,0 +1 @@
+RESTful_Easy_Messages Plug-in
@@ -0,0 +1,36 @@
+# Add these names routes to your project's config/routes.rb
+map.resources :users do |user|
+ user.resources :messages,
+ :collection => {:destroy_selected => :post,
+ :inbox => :get,
+ :outbox => :get,
+ :trashbin => :get},
+ :member => {:reply => :get}
+end
+
+# Here is a list of all the route created by Restful_EZM. Rake routes was used to generate this
+
+ inbox_user_messages GET /users/:user_id/messages/inbox {:controller=>"messages", :action=>"inbox"}
+ formatted_inbox_user_messages GET /users/:user_id/messages/inbox.:format {:controller=>"messages", :action=>"inbox"}
+ outbox_user_messages GET /users/:user_id/messages/outbox {:controller=>"messages", :action=>"outbox"}
+ formatted_outbox_user_messages GET /users/:user_id/messages/outbox.:format {:controller=>"messages", :action=>"outbox"}
+ trashbin_user_messages GET /users/:user_id/messages/trashbin {:controller=>"messages", :action=>"trashbin"}
+ formatted_trashbin_user_messages GET /users/:user_id/messages/trashbin.:format {:controller=>"messages", :action=>"trashbin"}
+ destroy_selected_user_messages POST /users/:user_id/messages/destroy_selected {:controller=>"messages", :action=>"destroy_selected"}
+formatted_destroy_selected_user_messages POST /users/:user_id/messages/destroy_selected.:format {:controller=>"messages", :action=>"destroy_selected"}
+ user_messages GET /users/:user_id/messages {:controller=>"messages", :action=>"index"}
+ formatted_user_messages GET /users/:user_id/messages.:format {:controller=>"messages", :action=>"index"}
+ POST /users/:user_id/messages {:controller=>"messages", :action=>"create"}
+ POST /users/:user_id/messages.:format {:controller=>"messages", :action=>"create"}
+ new_user_message GET /users/:user_id/messages/new {:controller=>"messages", :action=>"new"}
+ formatted_new_user_message GET /users/:user_id/messages/new.:format {:controller=>"messages", :action=>"new"}
+ edit_user_message GET /users/:user_id/messages/:id/edit {:controller=>"messages", :action=>"edit"}
+ formatted_edit_user_message GET /users/:user_id/messages/:id/edit.:format {:controller=>"messages", :action=>"edit"}
+ reply_user_message GET /users/:user_id/messages/:id/reply {:controller=>"messages", :action=>"reply"}
+ formatted_reply_user_message GET /users/:user_id/messages/:id/reply.:format {:controller=>"messages", :action=>"reply"}
+ user_message GET /users/:user_id/messages/:id {:controller=>"messages", :action=>"show"}
+ formatted_user_message GET /users/:user_id/messages/:id.:format {:controller=>"messages", :action=>"show"}
+ PUT /users/:user_id/messages/:id {:controller=>"messages", :action=>"update"}
+ PUT /users/:user_id/messages/:id.:format {:controller=>"messages", :action=>"update"}
+ DELETE /users/:user_id/messages/:id {:controller=>"messages", :action=>"destroy"}
+ DELETE /users/:user_id/messages/:id.:format {:controller=>"messages", :action=>"destroy"}
@@ -0,0 +1,27 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the Restful_Easy_Messages plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the Test the Restful_Easy_Messages plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Restful_Easy_Messages'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.include('../../../app/controllers/messages_controller.rb')
+ rdoc.rdoc_files.include('../../../app/helpers/messages_helper.rb')
+ rdoc.rdoc_files.include('../../../app/models/message.rb')
+ rdoc.rdoc_files.include('../../../test/functional/messages_controller_test.rb')
+ rdoc.rdoc_files.include('../../../test/unit/message_test.rb')
+end
2 TODO
@@ -0,0 +1,2 @@
+- Update the readme
+- Update the docreadme
@@ -0,0 +1,2 @@
+0.7
+
@@ -0,0 +1 @@
+./script/generate messages RENDERING_ENGINE(erb or haml)
@@ -0,0 +1,53 @@
+class MessagesGenerator < Rails::Generator::NamedBase
+
+ def initialize(args, options = {})
+ super
+ # do any needed initializations here
+ end
+
+ def manifest
+ record do |m|
+ # Controller
+ m.file "messages_controller.rb", "app/controllers/messages_controller.rb"
+
+ # Helper
+ m.file "messages_helper.rb", "app/helpers/messages_helper.rb"
+
+ # Model
+ m.file "message.rb", "app/models/message.rb"
+
+ # Views
+ m.directory "app/views/messages"
+ m.file "index.atom.builder", "app/views/messages/index.atom.builder"
+
+ if file_name == "haml"
+ m.file "index.haml", "app/views/messages/index.haml"
+ m.file "new.haml", "app/views/messages/new.haml"
+ m.file "show.haml", "app/views/messages/show.haml"
+ else
+ m.file "index.html.erb", "app/views/messages/index.html.erb"
+ m.file "new.html.erb", "app/views/messages/new.html.erb"
+ m.file "show.html.erb", "app/views/messages/show.html.erb"
+ end
+
+ # Lib
+ m.file "restful_easy_messages_controller_system.rb", "lib/restful_easy_messages_controller_system.rb"
+
+ # Public
+ m.file "403.html", "public/403.html"
+
+ # Tests
+ m.file "messages.yml", "test/fixtures/messages.yml"
+ m.file "users.yml", "test/fixtures/users.yml"
+ m.file "messages_controller_test.rb", "test/functional/messages_controller_test.rb"
+ m.file "message_test.rb", "test/unit/message_test.rb"
+
+ # Migration
+ m.migration_template 'create_restful_easy_messages.rb', 'db/migrate', :assigns => {
+ :migration_name => "CreateRestfulEasyMessages"
+ }, :migration_file_name => "create_restful_easy_messages"
+
+ end
+ end
+
+end
@@ -0,0 +1,30 @@
+<!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>You are not authorized to view this page. (403)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/403.html -->
+ <div class="dialog">
+ <h1>You are not authorized to view this page.</h1>
+ <p>Please keep your eyes on your own data and stop playing with the URLs.</p>
+ </div>
+</body>
+</html>
@@ -0,0 +1,19 @@
+class CreateRestfulEasyMessages < ActiveRecord::Migration
+ def self.up
+ create_table :messages, :force => true do |t|
+ t.boolean :receiver_deleted, :receiver_purged, :sender_deleted, :sender_purged
+ t.datetime :read_at
+ t.integer :receiver_id, :sender_id
+ t.string :subject, :null => false
+ t.text :body
+ t.timestamps
+ end
+
+ add_index :messages, :sender_id
+ add_index :messages, :receiver_id
+ end
+
+ def self.down
+ drop_table :messages
+ end
+end
@@ -0,0 +1,15 @@
+atom_feed do |feed|
+ feed.title "#{@rezm_user.login.capitalize}'s Inbox"
+ feed.updated @messages.first.created_at
+
+ for message in @messages
+ feed.entry(message, :url => user_message_url(rezm_user, message)) do |entry|
+ entry.title message.subject
+ entry.content message.body, :type => 'html'
+
+ entry.author do |author|
+ author.name message.sender.login
+ end
+ end
+ end
+end
@@ -0,0 +1,21 @@
+%h1 RESTful Easy Messages - haml
+%p= flash[:notice]
+= rezm_menu
+%p
+- form_for :message, :url => destroy_selected_user_messages_path do |form|
+ %table{:border => "1"}
+ %tr
+ %th
+ %th Subject
+ %th= rezm_sender_or_receiver_label
+ %th Sent
+ - for message in @messages
+ %tr
+ %td= rezm_delete_check_box(message)
+ %td= rezm_link_to_message(message)
+ %td= rezm_sender_or_receiver(message)
+ %td= rezm_sent_at(message)
+ %tr
+ %td{:colspan=> "4"}= submit_tag "Delete"
+
+
@@ -0,0 +1,25 @@
+<h1>RESTful Eazy Messages</h1>
+<div><%= flash[:notice] %></div>
+<div><%= rezm_menu -%></div>
+<p></p>
+<% form_for :message, :url => destroy_selected_user_messages_path do |form| %>
+ <table border="1">
+ <tr>
+ <th></th>
+ <th>Subject</th>
+ <th><%= rezm_sender_or_receiver_label %></th>
+ <th>Sent</th>
+ </tr>
+ <% for message in @messages %>
+ <tr>
+ <td><%= rezm_delete_check_box(message) %></td>
+ <td><%= rezm_link_to_message(message) %></td>
+ <td><%= rezm_sender_or_receiver(message) %></td>
+ <td><%= rezm_sent_at(message) %></td>
+ </tr>
+ <% end %>
+ <tr>
+ <td colspan="4"><%= submit_tag "Delete" %></td>
+ </tr>
+ </table>
+<% end %>
@@ -0,0 +1,61 @@
+class Message < ActiveRecord::Base
+
+ attr_accessor :recipient
+
+ belongs_to :sender,
+ :class_name => "User",
+ :foreign_key => "sender_id"
+
+ belongs_to :receiver,
+ :class_name => "User",
+ :foreign_key => "receiver_id"
+
+ validates_presence_of :recipient,
+ :subject,
+ :body
+
+ validates_length_of :body,
+ :minimum => 25,
+ :message => "is too short. The mimum length is %d characters. Please don't spam."
+
+ validates_length_of :body,
+ :maximum => 1000,
+ :message => "is too long. No one wants to read that. The maximum length is %d characters."
+
+ # Returns user.login for the sender
+ def sender_name
+ User.find(sender_id).login || ""
+ end
+
+ # Returns user.login for the receiver
+ def receiver_name
+ User.find(receiver_id).login || ""
+ end
+
+ def mark_message_read(user)
+ if user.id == self.receiver_id
+ self.read_at = Time.now
+ self.save false
+ end
+ end
+
+ # Performs a hard delete of a message. Should only be called from destroy
+ def purge
+ if self.sender_purged && self.receiver_purged
+ self.destroy
+ end
+ end
+
+ # Assigns the recipient to the receiver_id.
+ # I'm sure there is a better way. Please let me know.
+ def before_create
+ u = User.find_by_login(recipient)
+ self.receiver_id = u.id
+ end
+
+ # Validates that a user has entered a valid user.login name for the message recipient
+ def validate_on_create
+ u = User.find_by_login(recipient)
+ errors.add(:recipient, "is not a valid user.") if u.nil?
+ end
+end
Oops, something went wrong.

0 comments on commit c98d772

Please sign in to comment.