From 955fa6151aabfbe0626c84005cb0cad27da3e5c3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 9 Sep 2007 17:55:26 +0000 Subject: The examples are outdated and misleading git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7424 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/Rakefile | 6 +- actionpack/examples/.htaccess | 24 ------- actionpack/examples/address_book/index.erb | 33 --------- actionpack/examples/address_book/index.rhtml | 0 actionpack/examples/address_book/layout.erb | 8 --- actionpack/examples/address_book/layout.rhtml | 0 actionpack/examples/address_book_controller.cgi | 9 --- actionpack/examples/address_book_controller.fcgi | 6 -- actionpack/examples/address_book_controller.rb | 52 -------------- actionpack/examples/address_book_controller.rbx | 4 -- actionpack/examples/benchmark.rb | 52 -------------- actionpack/examples/benchmark_with_ar.fcgi | 89 ------------------------ actionpack/examples/blog_controller.cgi | 53 -------------- actionpack/examples/debate/index.erb | 14 ---- actionpack/examples/debate/index.rhtml | 0 actionpack/examples/debate/new_topic.erb | 22 ------ actionpack/examples/debate/new_topic.rhtml | 0 actionpack/examples/debate/topic.erb | 32 --------- actionpack/examples/debate/topic.rhtml | 0 actionpack/examples/debate_controller.cgi | 57 --------------- 20 files changed, 2 insertions(+), 459 deletions(-) delete mode 100644 actionpack/examples/.htaccess delete mode 100644 actionpack/examples/address_book/index.erb delete mode 100644 actionpack/examples/address_book/index.rhtml delete mode 100644 actionpack/examples/address_book/layout.erb delete mode 100644 actionpack/examples/address_book/layout.rhtml delete mode 100755 actionpack/examples/address_book_controller.cgi delete mode 100755 actionpack/examples/address_book_controller.fcgi delete mode 100644 actionpack/examples/address_book_controller.rb delete mode 100644 actionpack/examples/address_book_controller.rbx delete mode 100644 actionpack/examples/benchmark.rb delete mode 100755 actionpack/examples/benchmark_with_ar.fcgi delete mode 100755 actionpack/examples/blog_controller.cgi delete mode 100644 actionpack/examples/debate/index.erb delete mode 100644 actionpack/examples/debate/index.rhtml delete mode 100644 actionpack/examples/debate/new_topic.erb delete mode 100644 actionpack/examples/debate/new_topic.rhtml delete mode 100644 actionpack/examples/debate/topic.erb delete mode 100644 actionpack/examples/debate/topic.rhtml delete mode 100755 actionpack/examples/debate_controller.cgi (limited to 'actionpack') diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 5c2869f06f..2f6bba80fe 100755 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -59,7 +59,7 @@ Rake::RDocTask.new { |rdoc| } # Create compressed packages -dist_dirs = [ "lib", "test", "examples" ] +dist_dirs = [ "lib", "test" ] spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY @@ -81,12 +81,10 @@ spec = Gem::Specification.new do |s| s.require_path = 'lib' s.autorequire = 'action_controller' - s.files = [ "Rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG", "MIT-LICENSE", "examples/.htaccess" ] + s.files = [ "Rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG", "MIT-LICENSE" ] dist_dirs.each do |dir| s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) } end - s.files.delete "examples/benchmark.rb" - s.files.delete "examples/benchmark_with_ar.fcgi" end Rake::GemPackageTask.new(spec) do |p| diff --git a/actionpack/examples/.htaccess b/actionpack/examples/.htaccess deleted file mode 100644 index fb59fa105e..0000000000 --- a/actionpack/examples/.htaccess +++ /dev/null @@ -1,24 +0,0 @@ - - RubyRequire apache/ruby-run - RubySafeLevel 0 - - - SetHandler ruby-object - RubyHandler Apache::RubyRun.instance - - - - -RewriteEngine On -RewriteRule ^fcgi/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ /$1_controller.fcgi?action=$2&id=$3 [QSA] -RewriteRule ^fcgi/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ /$1_controller.fcgi?action=$2 [QSA] -RewriteRule ^fcgi/([-_a-zA-Z0-9]+)/$ /$1_controller.fcgi?action=index [QSA] - -RewriteRule ^modruby/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ /$1_controller.rbx?action=$2&id=$3 [QSA] -RewriteRule ^modruby/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ /$1_controller.rbx?action=$2 [QSA] -RewriteRule ^modruby/([-_a-zA-Z0-9]+)/$ /$1_controller.rbx?action=index [QSA] - -RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ /$1_controller.cgi?action=$2&id=$3 [QSA] -RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ /$1_controller.cgi?action=$2 [QSA] -RewriteRule ^([-_a-zA-Z0-9]+)/$ /$1_controller.cgi?action=index [QSA] - diff --git a/actionpack/examples/address_book/index.erb b/actionpack/examples/address_book/index.erb deleted file mode 100644 index 217d39075c..0000000000 --- a/actionpack/examples/address_book/index.erb +++ /dev/null @@ -1,33 +0,0 @@ -

Address Book

- -<% if @people.empty? %> -

No people in the address book yet

-<% else %> - - - <% for person in @people %> - - <% end %> -
NameEmail AddressPhone Number
<%= person.name %><%= person.email_address %><%= person.phone_number %>
-<% end %> - -
-

- Name:
- -

- -

- Email address:
- -

- -

- Phone number:
- -

- -

- -

-
\ No newline at end of file diff --git a/actionpack/examples/address_book/index.rhtml b/actionpack/examples/address_book/index.rhtml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/examples/address_book/layout.erb b/actionpack/examples/address_book/layout.erb deleted file mode 100644 index 931e141c01..0000000000 --- a/actionpack/examples/address_book/layout.erb +++ /dev/null @@ -1,8 +0,0 @@ - - - <%= @title || "Untitled" %> - - -<%= @content_for_layout %> - - \ No newline at end of file diff --git a/actionpack/examples/address_book/layout.rhtml b/actionpack/examples/address_book/layout.rhtml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/examples/address_book_controller.cgi b/actionpack/examples/address_book_controller.cgi deleted file mode 100755 index 2e15467285..0000000000 --- a/actionpack/examples/address_book_controller.cgi +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/local/bin/ruby - -require "address_book_controller" - -begin - AddressBookController.process_cgi(CGI.new) -rescue => e - CGI.new.out { "#{e.class}: #{e.message}" } -end \ No newline at end of file diff --git a/actionpack/examples/address_book_controller.fcgi b/actionpack/examples/address_book_controller.fcgi deleted file mode 100755 index 39947b4444..0000000000 --- a/actionpack/examples/address_book_controller.fcgi +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/local/bin/ruby - -require "address_book_controller" -require "fcgi" - -FCGI.each_cgi { |cgi| AddressBookController.process_cgi(cgi) } \ No newline at end of file diff --git a/actionpack/examples/address_book_controller.rb b/actionpack/examples/address_book_controller.rb deleted file mode 100644 index 7042ad84a5..0000000000 --- a/actionpack/examples/address_book_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -$:.unshift(File.dirname(__FILE__) + "/../lib") - -require "action_controller" -require "action_controller/test_process" - -Person = Struct.new("Person", :id, :name, :email_address, :phone_number) - -class AddressBookService - attr_reader :people - - def initialize() @people = [] end - def create_person(data) people.unshift(Person.new(next_person_id, data["name"], data["email_address"], data["phone_number"])) end - def find_person(topic_id) people.select { |person| person.id == person.to_i }.first end - def next_person_id() people.first.id + 1 end -end - -class AddressBookController < ActionController::Base - layout "address_book/layout" - - before_filter :initialize_session_storage - - # Could also have used a proc - # before_filter proc { |c| c.instance_variable_set("@address_book", c.session["address_book"] ||= AddressBookService.new) } - - def index - @title = "Address Book" - @people = @address_book.people - end - - def person - @person = @address_book.find_person(params[:id]) - end - - def create_person - @address_book.create_person(params[:person]) - redirect_to :action => "index" - end - - private - def initialize_session_storage - @address_book = @session["address_book"] ||= AddressBookService.new - end -end - -ActionController::Base.view_paths = [ File.dirname(__FILE__) ] -# ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir - -begin - AddressBookController.process_cgi(CGI.new) if $0 == __FILE__ -rescue => e - CGI.new.out { "#{e.class}: #{e.message}" } -end diff --git a/actionpack/examples/address_book_controller.rbx b/actionpack/examples/address_book_controller.rbx deleted file mode 100644 index 8c04eeccc8..0000000000 --- a/actionpack/examples/address_book_controller.rbx +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/local/bin/ruby - -require "address_book_controller" -AddressBookController.process_cgi(CGI.new) \ No newline at end of file diff --git a/actionpack/examples/benchmark.rb b/actionpack/examples/benchmark.rb deleted file mode 100644 index 78a6649c74..0000000000 --- a/actionpack/examples/benchmark.rb +++ /dev/null @@ -1,52 +0,0 @@ -$:.unshift(File.dirname(__FILE__) + "/../lib") - -require "action_controller" -require 'action_controller/test_process' - -Person = Struct.new("Person", :name, :address, :age) - -class BenchmarkController < ActionController::Base - def message - render :text => "hello world" - end - - def list - @people = [ Person.new("David"), Person.new("Mary") ] - render_template "hello: <% for person in @people %>Name: <%= person.name %><% end %>" - end - - def form_helper - @person = Person.new "david", "hyacintvej", 24 - render_template( - "<% person = Person.new 'Mary', 'hyacintvej', 22 %> " + - "change the name <%= text_field 'person', 'name' %> and <%= text_field 'person', 'address' %> and <%= text_field 'person', 'age' %>" - ) - end -end - -#ActionController::Base.view_paths = [ File.dirname(__FILE__) ] - -require "benchmark" - -RUNS = ARGV[0] ? ARGV[0].to_i : 50 - -require "profile" if ARGV[1] - -runtime = Benchmark.measure { - RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "list" })) } -} - -puts "List: #{RUNS / runtime.real}" - - -runtime = Benchmark.measure { - RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "message" })) } -} - -puts "Message: #{RUNS / runtime.real}" - -runtime = Benchmark.measure { - RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "form_helper" })) } -} - -puts "Form helper: #{RUNS / runtime.real}" diff --git a/actionpack/examples/benchmark_with_ar.fcgi b/actionpack/examples/benchmark_with_ar.fcgi deleted file mode 100755 index b9de370e24..0000000000 --- a/actionpack/examples/benchmark_with_ar.fcgi +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/local/bin/ruby - -begin - -$:.unshift(File.dirname(__FILE__) + "/../lib") -$:.unshift(File.dirname(__FILE__) + "/../../../edge/activerecord/lib") - -require 'fcgi' -require 'action_controller' -require 'action_controller/test_process' - -require 'active_record' - -class Post < ActiveRecord::Base; end - -ActiveRecord::Base.establish_connection(:adapter => "mysql", :database => "basecamp") - -SESSION_OPTIONS = { "database_manager" => CGI::Session::MemoryStore } - -class TestController < ActionController::Base - def index - render_template <<-EOT - <% for post in Post.find_all(nil,nil,100) %> - <%= post.title %> - <% end %> - EOT - end - - def show_one - render_template <<-EOT - <%= Post.find_first.title %> - EOT - end - - def text - render_text "hello world" - end - - def erb_text - render_template "hello <%= 'world' %>" - end - - def erb_loop - render_template <<-EOT - <% for post in 1..100 %> - <%= post %> - <% end %> - EOT - end - - def rescue_action(e) puts e.message + e.backtrace.join("\n") end -end - -if ARGV.empty? && ENV["REQUEST_URI"] - FCGI.each_cgi do |cgi| - TestController.process(ActionController::CgiRequest.new(cgi, SESSION_OPTIONS), ActionController::CgiResponse.new(cgi)).out - end -else - if ARGV.empty? - cgi = CGI.new - end - - require 'benchmark' - require 'profile' if ARGV[2] == "profile" - - RUNS = ARGV[1] ? ARGV[1].to_i : 50 - - runtime = Benchmark::measure { - RUNS.times { - if ARGV.empty? - TestController.process(ActionController::CgiRequest.new(cgi, SESSION_OPTIONS), ActionController::CgiResponse.new(cgi)) - else - response = TestController.process_test( - ActionController::TestRequest.new({"action" => ARGV[0]}) - ) - puts(response.body) if ARGV[2] == "show" - end - } - } - - puts "Runs: #{RUNS}" - puts "Avg. runtime: #{runtime.real / RUNS}" - puts "Requests/second: #{RUNS / runtime.real}" -end - -rescue Exception => e - # CGI.new.out { "
" + e.message + e.backtrace.join("\n") + "
" } - $stderr << e.message + e.backtrace.join("\n") -end \ No newline at end of file diff --git a/actionpack/examples/blog_controller.cgi b/actionpack/examples/blog_controller.cgi deleted file mode 100755 index 506afad62f..0000000000 --- a/actionpack/examples/blog_controller.cgi +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/local/bin/ruby - -$:.unshift(File.dirname(__FILE__) + "/../lib") - -require "action_controller" - -Post = Struct.new("Post", :title, :body) - -class BlogController < ActionController::Base - before_filter :initialize_session_storage - - def index - @posts = @session["posts"] - - render_template <<-"EOF" - - <%= flash["alert"] %> -

Posts

- <% @posts.each do |post| %> -

<%= post.title %>
<%= post.body %>

- <% end %> - -

Create post

-
- Title:
- Body:
- -
- - - EOF - end - - def create - @session["posts"].unshift(Post.new(params[:post][:title], params[:post][:body])) - flash["alert"] = "New post added!" - redirect_to :action => "index" - end - - private - def initialize_session_storage - @session["posts"] = [] if @session["posts"].nil? - end -end - -ActionController::Base.view_paths = [ File.dirname(__FILE__) ] -# ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir - -begin - BlogController.process_cgi(CGI.new) if $0 == __FILE__ -rescue => e - CGI.new.out { "#{e.class}: #{e.message}" } -end diff --git a/actionpack/examples/debate/index.erb b/actionpack/examples/debate/index.erb deleted file mode 100644 index ddaa87da57..0000000000 --- a/actionpack/examples/debate/index.erb +++ /dev/null @@ -1,14 +0,0 @@ - - -

Topics

- -<%= link_to "New topic", :action => "new_topic" %> - - - - - \ No newline at end of file diff --git a/actionpack/examples/debate/index.rhtml b/actionpack/examples/debate/index.rhtml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/examples/debate/new_topic.erb b/actionpack/examples/debate/new_topic.erb deleted file mode 100644 index f52a69cc31..0000000000 --- a/actionpack/examples/debate/new_topic.erb +++ /dev/null @@ -1,22 +0,0 @@ - - -

New topic

- -
" method="post"> -

- Title:
- -

- -

- Body:
- -

- -

- -

-
- - - \ No newline at end of file diff --git a/actionpack/examples/debate/new_topic.rhtml b/actionpack/examples/debate/new_topic.rhtml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/examples/debate/topic.erb b/actionpack/examples/debate/topic.erb deleted file mode 100644 index e247c00f0d..0000000000 --- a/actionpack/examples/debate/topic.erb +++ /dev/null @@ -1,32 +0,0 @@ - - -

<%= @topic.title %>

- -

<%= @topic.body %>

- -<%= link_to "Back to topics", :action => "index" %> - -<% unless @topic.replies.empty? %> -

Replies

-
    - <% for reply in @topic.replies %> -
  1. <%= reply.body %>
  2. - <% end %> -
-<% end %> - -

Reply to this topic

- -
" method="post"> - -

- -

- -

- -

-
- - - \ No newline at end of file diff --git a/actionpack/examples/debate/topic.rhtml b/actionpack/examples/debate/topic.rhtml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/actionpack/examples/debate_controller.cgi b/actionpack/examples/debate_controller.cgi deleted file mode 100755 index 9cb787940c..0000000000 --- a/actionpack/examples/debate_controller.cgi +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/local/bin/ruby - -$:.unshift(File.dirname(__FILE__) + "/../lib") - -require "action_controller" - -Topic = Struct.new("Topic", :id, :title, :body, :replies) -Reply = Struct.new("Reply", :body) - -class DebateService - attr_reader :topics - - def initialize() @topics = [] end - def create_topic(data) topics.unshift(Topic.new(next_topic_id, data["title"], data["body"], [])) end - def create_reply(data) find_topic(data["topic_id"]).replies << Reply.new(data["body"]) end - def find_topic(topic_id) topics.select { |topic| topic.id == topic_id.to_i }.first end - def next_topic_id() topics.first.id + 1 end -end - -class DebateController < ActionController::Base - before_filter :initialize_session_storage - - def index - @topics = @debate.topics - end - - def topic - @topic = @debate.find_topic(params[:id]) - end - - # def new_topic() end <-- This is not needed as the template doesn't require any assigns - - def create_topic - @debate.create_topic(params[:topic]) - redirect_to :action => "index" - end - - def create_reply - @debate.create_reply(params[:reply]) - redirect_to :action => "topic", :path_params => { "id" => params[:reply][:topic_id] } - end - - private - def initialize_session_storage - @session["debate"] = DebateService.new if @session["debate"].nil? - @debate = @session["debate"] - end -end - -ActionController::Base.view_paths = [ File.dirname(__FILE__) ] -# ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir - -begin - DebateController.process_cgi(CGI.new) if $0 == __FILE__ -rescue => e - CGI.new.out { "#{e.class}: #{e.message}" } -end -- cgit v1.2.3