Permalink
Browse files

adding episode 128

  • Loading branch information...
1 parent 1432a17 commit 0f2d80b270eec72b3b4f4ef8b2ae7ba0a7d2732c @ryanb committed Sep 22, 2008
Showing with 9,295 additions and 0 deletions.
  1. +10 −0 episode-128/README
  2. +3 −0 episode-128/mailit/.gitignore
  3. 0 episode-128/mailit/README
  4. +10 −0 episode-128/mailit/Rakefile
  5. +15 −0 episode-128/mailit/app/controllers/application.rb
  6. +50 −0 episode-128/mailit/app/controllers/mailings_controller.rb
  7. +3 −0 episode-128/mailit/app/helpers/application_helper.rb
  8. +23 −0 episode-128/mailit/app/helpers/layout_helper.rb
  9. +2 −0 episode-128/mailit/app/helpers/mailings_helper.rb
  10. +6 −0 episode-128/mailit/app/models/mailing.rb
  11. +22 −0 episode-128/mailit/app/views/layouts/application.html.erb
  12. +16 −0 episode-128/mailit/app/views/mailings/_form.html.erb
  13. +8 −0 episode-128/mailit/app/views/mailings/edit.html.erb
  14. +15 −0 episode-128/mailit/app/views/mailings/index.html.erb
  15. +5 −0 episode-128/mailit/app/views/mailings/new.html.erb
  16. +20 −0 episode-128/mailit/app/views/mailings/show.html.erb
  17. +6 −0 episode-128/mailit/app/workers/mailings_worker.rb
  18. +109 −0 episode-128/mailit/config/boot.rb
  19. +19 −0 episode-128/mailit/config/database.yml
  20. +67 −0 episode-128/mailit/config/environment.rb
  21. +19 −0 episode-128/mailit/config/environments/development.rb
  22. +22 −0 episode-128/mailit/config/environments/production.rb
  23. +22 −0 episode-128/mailit/config/environments/test.rb
  24. +10 −0 episode-128/mailit/config/initializers/inflections.rb
  25. +5 −0 episode-128/mailit/config/initializers/mime_types.rb
  26. +15 −0 episode-128/mailit/config/initializers/new_rails_defaults.rb
  27. +4 −0 episode-128/mailit/config/routes.rb
  28. +13 −0 episode-128/mailit/config/starling.yml
  29. +14 −0 episode-128/mailit/db/migrate/20080914020108_create_mailings.rb
  30. +22 −0 episode-128/mailit/db/schema.rb
  31. +2 −0 episode-128/mailit/doc/README_FOR_APP
  32. +30 −0 episode-128/mailit/public/404.html
  33. +30 −0 episode-128/mailit/public/422.html
  34. +30 −0 episode-128/mailit/public/500.html
  35. +10 −0 episode-128/mailit/public/dispatch.cgi
  36. +24 −0 episode-128/mailit/public/dispatch.fcgi
  37. +10 −0 episode-128/mailit/public/dispatch.rb
  38. 0 episode-128/mailit/public/favicon.ico
  39. +2 −0 episode-128/mailit/public/javascripts/application.js
  40. +963 −0 episode-128/mailit/public/javascripts/controls.js
  41. +972 −0 episode-128/mailit/public/javascripts/dragdrop.js
  42. +1,120 −0 episode-128/mailit/public/javascripts/effects.js
  43. +4,225 −0 episode-128/mailit/public/javascripts/prototype.js
  44. +5 −0 episode-128/mailit/public/robots.txt
  45. +85 −0 episode-128/mailit/public/stylesheets/application.css
  46. +3 −0 episode-128/mailit/script/about
  47. +8 −0 episode-128/mailit/script/bj_invoker.rb
  48. +3 −0 episode-128/mailit/script/console
  49. +3 −0 episode-128/mailit/script/dbconsole
  50. +3 −0 episode-128/mailit/script/destroy
  51. +3 −0 episode-128/mailit/script/generate
  52. +3 −0 episode-128/mailit/script/performance/benchmarker
  53. +3 −0 episode-128/mailit/script/performance/profiler
  54. +3 −0 episode-128/mailit/script/performance/request
  55. +3 −0 episode-128/mailit/script/plugin
  56. +3 −0 episode-128/mailit/script/process/inspector
  57. +3 −0 episode-128/mailit/script/process/reaper
  58. +3 −0 episode-128/mailit/script/process/spawner
  59. +3 −0 episode-128/mailit/script/runner
  60. +3 −0 episode-128/mailit/script/server
  61. +17 −0 episode-128/mailit/script/workling_starling_client
  62. +9 −0 episode-128/mailit/test/fixtures/mailings.yml
  63. +54 −0 episode-128/mailit/test/functional/mailings_controller_test.rb
  64. +38 −0 episode-128/mailit/test/test_helper.rb
  65. +7 −0 episode-128/mailit/test/unit/mailing_test.rb
  66. +29 −0 episode-128/mailit/vendor/plugins/workling/Changes
  67. +20 −0 episode-128/mailit/vendor/plugins/workling/MIT-LICENSE
  68. +133 −0 episode-128/mailit/vendor/plugins/workling/README
  69. +22 −0 episode-128/mailit/vendor/plugins/workling/Rakefile
  70. +13 −0 episode-128/mailit/vendor/plugins/workling/config/starling.yml
  71. +4 −0 episode-128/mailit/vendor/plugins/workling/init.rb
  72. +10 −0 episode-128/mailit/vendor/plugins/workling/install.rb
  73. +7 −0 episode-128/mailit/vendor/plugins/workling/lib/workling.rb
  74. +30 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/base.rb
  75. +11 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/discovery.rb
  76. +23 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/remote.rb
  77. +38 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/remote/runners/base.rb
  78. +16 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/remote/runners/not_remote_runner.rb
  79. +21 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/remote/runners/spawn_runner.rb
  80. +27 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/remote/runners/starling_runner.rb
  81. +25 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/return/store/base.rb
  82. +24 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/return/store/memory_return_store.rb
  83. +24 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/return/store/starling_return_store.rb
  84. +10 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/starling.rb
  85. +24 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/starling/client.rb
  86. +124 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/starling/poller.rb
  87. +11 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/starling/routing/base.rb
  88. +48 −0 episode-128/mailit/vendor/plugins/workling/lib/workling/starling/routing/class_and_method_routing.rb
  89. +43 −0 episode-128/mailit/vendor/plugins/workling/script/listen.rb
  90. +32 −0 episode-128/mailit/vendor/plugins/workling/script/status.rb
  91. +17 −0 episode-128/mailit/vendor/plugins/workling/script/workling_starling_client
  92. +18 −0 episode-128/mailit/vendor/plugins/workling/test/class_and_method_routing_test.rb
  93. +8 −0 episode-128/mailit/vendor/plugins/workling/test/discovery_test.rb
  94. +23 −0 episode-128/mailit/vendor/plugins/workling/test/memory_return_store_test.rb
  95. +5 −0 episode-128/mailit/vendor/plugins/workling/test/mocks/logger.rb
  96. +5 −0 episode-128/mailit/vendor/plugins/workling/test/mocks/spawn.rb
  97. +11 −0 episode-128/mailit/vendor/plugins/workling/test/not_remote_runner_test.rb
  98. +45 −0 episode-128/mailit/vendor/plugins/workling/test/remote_runner_test.rb
  99. +13 −0 episode-128/mailit/vendor/plugins/workling/test/return_store_test.rb
  100. +10 −0 episode-128/mailit/vendor/plugins/workling/test/spawn_runner_test.rb
  101. +21 −0 episode-128/mailit/vendor/plugins/workling/test/starling_client_test.rb
  102. +16 −0 episode-128/mailit/vendor/plugins/workling/test/starling_poller_test.rb
  103. +29 −0 episode-128/mailit/vendor/plugins/workling/test/starling_return_store_test.rb
  104. +8 −0 episode-128/mailit/vendor/plugins/workling/test/starling_runner_test.rb
  105. +34 −0 episode-128/mailit/vendor/plugins/workling/test/test_helper.rb
  106. +10 −0 episode-128/mailit/vendor/plugins/workling/test/workers/analytics/invites.rb
  107. +15 −0 episode-128/mailit/vendor/plugins/workling/test/workers/util.rb
View
@@ -0,0 +1,10 @@
+Railscasts Episode #128: Starling and Workling
+
+http://railscasts.com/episodes/128
+
+Commands:
+
+ gem install starling
+ script/plugin install http://svn.playtype.net/plugins/workling/
+ starling -d -P tmp/pids/starling.pid -q log/
+ script/workling_starling_client start
@@ -0,0 +1,3 @@
+tmp/*
+log/*
+*.sqlite3
No changes.
@@ -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 => '3fb7e7755b16e718d0594087efcaddc1'
+
+ # 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,50 @@
+class MailingsController < ApplicationController
+ def deliver
+ MailingsWorker.async_send_mailing(:mailing_id => params[:id])
+ flash[:notice] = "Delivering mailing"
+ redirect_to mailings_url
+ end
+
+ def index
+ @mailings = Mailing.find(:all)
+ end
+
+ def show
+ @mailing = Mailing.find(params[:id])
+ end
+
+ def new
+ @mailing = Mailing.new
+ end
+
+ def create
+ @mailing = Mailing.new(params[:mailing])
+ if @mailing.save
+ flash[:notice] = "Successfully created mailing."
+ redirect_to @mailing
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @mailing = Mailing.find(params[:id])
+ end
+
+ def update
+ @mailing = Mailing.find(params[:id])
+ if @mailing.update_attributes(params[:mailing])
+ flash[:notice] = "Successfully updated mailing."
+ redirect_to @mailing
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @mailing = Mailing.find(params[:id])
+ @mailing.destroy
+ flash[:notice] = "Successfully destroyed mailing."
+ redirect_to mailings_url
+ 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,23 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+ def title(page_title, show_title = true)
+ @content_for_title = page_title.to_s
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args.map(&:to_s)) }
+ end
+
+ def javascript(*args)
+ args = args.map { |arg| arg == :defaults ? arg : arg.to_s }
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,2 @@
+module MailingsHelper
+end
@@ -0,0 +1,6 @@
+class Mailing < ActiveRecord::Base
+ def deliver
+ sleep 10 # placeholder for sending email
+ update_attribute(:delivered_at, Time.now)
+ end
+end
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag 'application' %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <%- flash.each do |name, msg| -%>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <%- end -%>
+
+ <%- if show_title? -%>
+ <h1><%=h yield(:title) %></h1>
+ <%- end -%>
+
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,16 @@
+<%= error_messages_for :mailing %>
+<% form_for @mailing do |f| %>
+ <p>
+ <%= f.label :subject %><br />
+ <%= f.text_field :subject %>
+ </p>
+ <p>
+ <%= f.label :content %><br />
+ <%= f.text_area :content %>
+ </p>
+ <p>
+ <%= f.label :delivered_at %><br />
+ <%= f.datetime_select :delivered_at %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Mailing" %>
+
+<%= render :partial => 'form' %>
+
+<p>
+ <%= link_to "Show", @mailing %> |
+ <%= link_to "View All", mailings_path %>
+</p>
@@ -0,0 +1,15 @@
+<% title "Mailings" %>
+
+<% for mailing in @mailings %>
+ <div class="mailing">
+ <h2><%= link_to h(mailing.subject), mailing %></h2>
+ <% unless mailing.delivered_at.nil? %>
+ Delivered on: <%= mailing.delivered_at.to_s(:long) %><br />
+ <% end %>
+ <%= link_to "Edit", edit_mailing_path(mailing) %> |
+ <%= link_to "Destroy", mailing, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "Deliver", deliver_mailing_path(mailing), :confirm => 'Are you sure?', :method => :post %>
+ </div>
+<% end %>
+
+<p><%= link_to "New Mailing", new_mailing_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Mailing" %>
+
+<%= render :partial => 'form' %>
+
+<p><%= link_to "Back to List", mailings_path %></p>
@@ -0,0 +1,20 @@
+<% title "Mailing" %>
+
+<p>
+ <strong>Subject:</strong>
+ <%=h @mailing.subject %>
+</p>
+<p>
+ <strong>Content:</strong>
+ <%=h @mailing.content %>
+</p>
+<p>
+ <strong>Delivered At:</strong>
+ <%=h @mailing.delivered_at %>
+</p>
+
+<p>
+ <%= link_to "Edit", edit_mailing_path(@mailing) %> |
+ <%= link_to "Destroy", @mailing, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", mailings_path %>
+</p>
@@ -0,0 +1,6 @@
+class MailingsWorker < Workling::Base
+ def send_mailing(options)
+ mailing = Mailing.find(options[:mailing_id])
+ mailing.deliver
+ end
+end
@@ -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!
@@ -0,0 +1,19 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ timeout: 5000
Oops, something went wrong. Retry.

0 comments on commit 0f2d80b

Please sign in to comment.