sinatra 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

Files changed (54) hide show
  1. data/CHANGELOG +1 -0
  2. data/LICENSE +22 -0
  3. data/Manifest +53 -0
  4. data/README +99 -0
  5. data/RakeFile +36 -0
  6. data/Rakefile +36 -0
  7. data/examples/hello/hello.rb +30 -0
  8. data/examples/hello/views/hello.erb +1 -0
  9. data/examples/todo/todo.rb +38 -0
  10. data/files/default_index.erb +42 -0
  11. data/files/error.erb +9 -0
  12. data/files/logo.png +0 -0
  13. data/files/not_found.erb +52 -0
  14. data/lib/sinatra.rb +47 -0
  15. data/lib/sinatra/context.rb +88 -0
  16. data/lib/sinatra/context/renderer.rb +75 -0
  17. data/lib/sinatra/core_ext/array.rb +5 -0
  18. data/lib/sinatra/core_ext/class.rb +49 -0
  19. data/lib/sinatra/core_ext/hash.rb +7 -0
  20. data/lib/sinatra/core_ext/kernel.rb +16 -0
  21. data/lib/sinatra/core_ext/metaid.rb +18 -0
  22. data/lib/sinatra/core_ext/module.rb +11 -0
  23. data/lib/sinatra/core_ext/symbol.rb +5 -0
  24. data/lib/sinatra/dispatcher.rb +27 -0
  25. data/lib/sinatra/dsl.rb +163 -0
  26. data/lib/sinatra/environment.rb +15 -0
  27. data/lib/sinatra/event.rb +184 -0
  28. data/lib/sinatra/irb.rb +55 -0
  29. data/lib/sinatra/loader.rb +31 -0
  30. data/lib/sinatra/logger.rb +22 -0
  31. data/lib/sinatra/options.rb +43 -0
  32. data/lib/sinatra/rack_ext/request.rb +15 -0
  33. data/lib/sinatra/route.rb +65 -0
  34. data/lib/sinatra/server.rb +54 -0
  35. data/lib/sinatra/sessions.rb +21 -0
  36. data/lib/sinatra/test_methods.rb +55 -0
  37. data/sinatra.gemspec +60 -0
  38. data/site/index.htm +100 -0
  39. data/site/index.html +100 -0
  40. data/site/logo.png +0 -0
  41. data/test/helper.rb +17 -0
  42. data/test/sinatra/dispatcher_test.rb +91 -0
  43. data/test/sinatra/event_test.rb +37 -0
  44. data/test/sinatra/renderer_test.rb +47 -0
  45. data/test/sinatra/request_test.rb +21 -0
  46. data/test/sinatra/route_test.rb +21 -0
  47. data/test/sinatra/static_files/foo.txt +1 -0
  48. data/test/sinatra/static_files_test.rb +41 -0
  49. data/test/sinatra/url_test.rb +18 -0
  50. data/vendor/erb/init.rb +3 -0
  51. data/vendor/erb/lib/erb.rb +41 -0
  52. data/vendor/haml/init.rb +3 -0
  53. data/vendor/haml/lib/haml.rb +41 -0
  54. metadata +121 -0
@@ -0,0 +1 @@
1
+ v0.1.0 Released!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007 Blake Mizerany
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ CHANGELOG
2
+ examples/hello/hello.rb
3
+ examples/hello/views/hello.erb
4
+ examples/todo/todo.rb
5
+ files/default_index.erb
6
+ files/error.erb
7
+ files/logo.png
8
+ files/not_found.erb
9
+ lib/sinatra/context/renderer.rb
10
+ lib/sinatra/context.rb
11
+ lib/sinatra/core_ext/array.rb
12
+ lib/sinatra/core_ext/class.rb
13
+ lib/sinatra/core_ext/hash.rb
14
+ lib/sinatra/core_ext/kernel.rb
15
+ lib/sinatra/core_ext/metaid.rb
16
+ lib/sinatra/core_ext/module.rb
17
+ lib/sinatra/core_ext/symbol.rb
18
+ lib/sinatra/dispatcher.rb
19
+ lib/sinatra/dsl.rb
20
+ lib/sinatra/environment.rb
21
+ lib/sinatra/event.rb
22
+ lib/sinatra/irb.rb
23
+ lib/sinatra/loader.rb
24
+ lib/sinatra/logger.rb
25
+ lib/sinatra/options.rb
26
+ lib/sinatra/rack_ext/request.rb
27
+ lib/sinatra/route.rb
28
+ lib/sinatra/server.rb
29
+ lib/sinatra/sessions.rb
30
+ lib/sinatra/test_methods.rb
31
+ lib/sinatra.rb
32
+ LICENSE
33
+ RakeFile
34
+ README
35
+ sinatra.gemspec
36
+ site/index.htm
37
+ site/index.html
38
+ site/logo.png
39
+ test/helper.rb
40
+ test/sinatra/dispatcher_test.rb
41
+ test/sinatra/event_test.rb
42
+ test/sinatra/renderer_test.rb
43
+ test/sinatra/request_test.rb
44
+ test/sinatra/route_test.rb
45
+ test/sinatra/static_files/foo.txt
46
+ test/sinatra/static_files_test.rb
47
+ test/sinatra/url_test.rb
48
+ vendor/erb/init.rb
49
+ vendor/erb/lib/erb.rb
50
+ vendor/haml/init.rb
51
+ vendor/haml/lib/haml.rb
52
+ Rakefile
53
+ Manifest
data/README ADDED
@@ -0,0 +1,99 @@
1
+ Sinatra (C) 2007 By Blake Mizerany
2
+
3
+ = Classy web-development dressed in a DSL
4
+
5
+ == Install!
6
+
7
+ sudo gem install sinatra -y
8
+
9
+ == Use!
10
+
11
+ I'm going to move quick. I'll let you drool at your own pace.
12
+
13
+ * Create a file called lyrics.rb (or any name you like)
14
+
15
+ * Add
16
+ require 'rubygems'
17
+ require 'sinatra'
18
+
19
+ * Run (yes, with just ruby)
20
+ % ruby lyrics.rb
21
+ == Sinata has taken the stage on port 4567!
22
+
23
+ * Take a moment and view the default page http://localhost:4567. Go ahead and bask in it's glory.
24
+
25
+ * Notice:
26
+ * It didn't create any page to show you that default page (just a cool thing to see, that's all)
27
+ * There was nothing generated other than a log file
28
+ * Sinatra is a really cool name for a web-framework that's a DSL
29
+
30
+ * Modify lyrics.rb by adding:
31
+ get '/' do
32
+ 'Hello World'
33
+ end
34
+
35
+ * Refresh (no need to restart Sinatra):
36
+ http://localhost:4567
37
+
38
+ * Modify again (then refresh):
39
+ get '/' do
40
+ <<-HTML
41
+ <form action='/' method="POST">
42
+ <input type="text" name="name" />
43
+ <input type="submit" value="Say my name!" />
44
+ </form>
45
+ HTML
46
+ end
47
+
48
+ post '/' do
49
+ "Hello #{params[:name] || 'World'}!"
50
+ end
51
+
52
+ * Now you try:
53
+ Use the Sinatra::Erb::EventContext or Sinatra::Haml::EventContext to do the same. Do them inline and as template files.
54
+
55
+ * Learn more cool stuff:
56
+ see Sinatra::Dsl
57
+
58
+ * Create your own plugins!
59
+ 1. Create a 'vendor' directory in your app directory
60
+ 2. Lay it out like:
61
+
62
+ myapp.rb : root
63
+ |- vendor
64
+ | - plugin_name
65
+ | - init.rb # load and hook here
66
+ | - lib
67
+ |- modules/classes here
68
+
69
+ 3. Use it in your app!
70
+
71
+ see $SINATRA_GEM_ROOT/vendor/erb or $SINATRA_GEM_ROOT/vendor/erb for examples.
72
+
73
+ * Tell!
74
+ We would love to here what you're doing with Sinatra and any cool patches/features you would like. (blake { dot } mizerany [ at ] gmail)
75
+
76
+ * Talk!
77
+ IRC (irc.freenode.com #sinatra)
78
+ Mailing List (sinatrarb@googlegroups.com)
79
+
80
+ * Contribute
81
+
82
+ We're using git as our scm.. cuz.. it rocks. You can get the latest source from http://repo.or.cz/w/sinatra.git
83
+
84
+ NOTE: You can also get tar'd snapshots of each commit there too. So technically you don't need git to get the latest code.
85
+
86
+ It's probably going to happen.. you'll find a bug. Please help by:
87
+
88
+ * Sending a message to sintrarb@googlegroups.com with BUG: at the start of the subject (I'm working on a better tracking system)
89
+ * Please send patches or pull requests to (blake { dot } mizerany [ at ] gmail) don't forget the dot com. ;)
90
+
91
+ == Thanks!
92
+
93
+ - Ezra Zygmuntowicz (http://brainspl.at) for answering all those random questions over IM and all the poached code
94
+ - Ditto to Chris Wanstrath (errtheblog.com) and helping me keep things simple, and some cool tricks
95
+ - Ari Lerner over at CitrusByte for ideas, code, and enthusiasm
96
+ - Koshi (http://www.songbirdnest.com/jkoshi/blog) here at POTI, Inc. for the Sinatra mark
97
+ - Pete Golibersuch for the hat logo
98
+ - John Philip Green (http://www.linkedin.com/in/johngreen) for motivation and evangelism
99
+ - The team here at songbirdnest.com for cool ideas
@@ -0,0 +1,36 @@
1
+ require 'rake/testtask'
2
+ require 'ftools'
3
+ require 'hoe'
4
+
5
+ Version = '0.1.0'
6
+
7
+ begin
8
+ require 'rubygems'
9
+ gem 'echoe'
10
+ ENV['RUBY_FLAGS'] = ""
11
+ require 'echoe'
12
+
13
+ Echoe.new('sinatra') do |p|
14
+ p.rubyforge_name = 'bmizerany'
15
+ p.dependencies = ['mongrel >=1.0.1', 'rack >=0.2.0']
16
+ p.summary = "Sinatra is a classy web-framework dressed in a DSL"
17
+ p.description = "Sinatra is a classy web-framework dressed in a DSL"
18
+ p.url = "http://sinatra.rubyforge.org/"
19
+ p.author = 'Blake Mizerany'
20
+ p.email = "blake.mizerany@gmail.com"
21
+ p.test_pattern = 'test/**/*_test.rb'
22
+ p.include_rakefile = true
23
+ p.rdoc_pattern = ['README', 'LICENSE'] << Dir.glob('lib/**/*.rb') << Dir.glob('vendor/**/*.rb')
24
+ p.docs_host = "bmizerany@rubyforge.org:/var/www/gforge-projects/sinatra/"
25
+ end
26
+
27
+ rescue LoadError
28
+ end
29
+
30
+ desc 'Clear all the log files from here down'
31
+ task :remove_logs do
32
+ Dir.glob(Dir.pwd + '/**/*.log') do |logfile|
33
+ FileUtils.rm(logfile)
34
+ puts 'Removed: %s' % logfile
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'rake/testtask'
2
+ require 'ftools'
3
+ require 'hoe'
4
+
5
+ Version = '0.1.0'
6
+
7
+ begin
8
+ require 'rubygems'
9
+ gem 'echoe'
10
+ ENV['RUBY_FLAGS'] = ""
11
+ require 'echoe'
12
+
13
+ Echoe.new('sinatra') do |p|
14
+ p.rubyforge_name = 'bmizerany'
15
+ p.dependencies = ['mongrel >=1.0.1', 'rack >=0.2.0']
16
+ p.summary = "Sinatra is a classy web-framework dressed in a DSL"
17
+ p.description = "Sinatra is a classy web-framework dressed in a DSL"
18
+ p.url = "http://sinatra.rubyforge.org/"
19
+ p.author = 'Blake Mizerany'
20
+ p.email = "blake.mizerany@gmail.com"
21
+ p.test_pattern = 'test/**/*_test.rb'
22
+ p.include_rakefile = true
23
+ p.rdoc_pattern = ['README', 'LICENSE'] << Dir.glob('lib/**/*.rb') << Dir.glob('vendor/**/*.rb')
24
+ p.docs_host = "bmizerany@rubyforge.org:/var/www/gforge-projects/sinatra/"
25
+ end
26
+
27
+ rescue LoadError
28
+ end
29
+
30
+ desc 'Clear all the log files from here down'
31
+ task :remove_logs do
32
+ Dir.glob(Dir.pwd + '/**/*.log') do |logfile|
33
+ FileUtils.rm(logfile)
34
+ puts 'Removed: %s' % logfile
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
2
+ require 'sinatra'
3
+
4
+ production do
5
+ sessions :off
6
+ end
7
+
8
+ get '/' do
9
+ "Hello World!"
10
+ end
11
+
12
+ get '/erb.xml' do
13
+ header 'Content-Type' => 'application/xml'
14
+ '<this_is_xml/>'
15
+ end
16
+
17
+ get '/erb' do
18
+ erb :hello
19
+ end
20
+
21
+ get '/erb2' do
22
+ erb 'Hello <%= params[:name].capitalize || "World" %> 2!'
23
+ end
24
+
25
+ # Custom 404
26
+
27
+ # get 404 do
28
+ # 'Custom 404!!!!'
29
+ # end
30
+
@@ -0,0 +1 @@
1
+ Hello <%= params[:name].capitalize || 'World' %>!
@@ -0,0 +1,38 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
2
+ require 'sinatra'
3
+
4
+ get '/' do
5
+ @items = session[:items] || []
6
+ haml <<-haml
7
+ %script window.document.getElementById('new_item').focus();
8
+ %h1 Sinatra's todo list
9
+ %ul
10
+ - @items.each_with_index do |item, index|
11
+ %li.item
12
+ %div
13
+ = item
14
+ %form{:action => "/" + index.to_s, :method => 'POST'}
15
+ %input{:type => 'hidden', :name => '_method', :value => 'DELETE'}
16
+ %input{:type => 'submit', :value => 'delete'}
17
+ %form{:action => '/clear', :method => 'POST'}
18
+ %input{:value => 'clear', :type => :submit}
19
+ %form{:action => '/', :method => 'POST'}
20
+ %input{:type => 'textbox', :name => :new_item, :id => 'new_item'}
21
+ %input{:type => 'submit'}
22
+ haml
23
+ end
24
+
25
+ post '/' do
26
+ (session[:items] ||= []) << params[:new_item] unless params[:new_item].to_s.strip.empty?
27
+ redirect '/'
28
+ end
29
+
30
+ post '/clear' do
31
+ session[:items].clear
32
+ redirect '/'
33
+ end
34
+
35
+ delete '/:id' do
36
+ session[:items].delete_at(params[:id].to_i)
37
+ redirect '/'
38
+ end
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html>
5
+ <head>
6
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
+ <title>Sinatra has taken the stage!</title>
8
+ </head>
9
+
10
+ <body>
11
+ <style type="text/css" media="screen">
12
+ body {
13
+ color: #333;
14
+ font-size: 1.5em;
15
+ }
16
+
17
+ #content {
18
+ margin: 0 auto;
19
+ text-align: center;
20
+ width: 500px;
21
+ }
22
+
23
+ #content pre {
24
+ text-align: left;
25
+ background-color: #D8D8D8;
26
+ padding: 10px;
27
+ }
28
+ </style>
29
+ <div id="content">
30
+ <div id="banner">
31
+ <img src="http://sinatra.rubyforge.org/logo.png">
32
+ </div>
33
+ <div id="content">
34
+ <h3>Sing this diddy to move on:</h3>
35
+ <pre>
36
+ get "/" do
37
+ ... your code here ..
38
+ end</pre>
39
+ </div>
40
+ </div>
41
+ </body>
42
+ </html>
@@ -0,0 +1,9 @@
1
+ <h2>Error!</h2>
2
+
3
+ <h3>
4
+ <%= @error.message %>
5
+ </h3>
6
+
7
+ <div id="backtrace">
8
+ <%= @error.backtrace.join('<br/>') %>
9
+ </div>
Binary file
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html>
5
+
6
+ <head>
7
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
8
+ <title>Not Found :: Sinatra</title>
9
+ </head>
10
+
11
+ <body id="not_found">
12
+
13
+ <style type="text/css" media="screen">
14
+ body {
15
+ background-color: #fff;
16
+ }
17
+
18
+ .message {
19
+ padding: 10px;
20
+
21
+ font-size: 20px;
22
+ font-color: #333;
23
+ }
24
+
25
+ #content {
26
+ }
27
+
28
+ .message pre {
29
+ font-size: 15px;
30
+ text-align: left;
31
+
32
+ background-color: #ccc;
33
+
34
+ padding: 10px;
35
+ }
36
+ </style>
37
+
38
+ <div id="container">
39
+ <div id="content">
40
+ <div class='message'>
41
+ <h3>Sinatra doesn't know this diddy, but he's a quick study.</h3>
42
+ <p>Sing this one:</p>
43
+ <pre><%= request.request_method.downcase %> '<%= request.path_info %>' do
44
+ html "Replace this with your code."
45
+ end</pre>
46
+ </div>
47
+ </div>
48
+ </div>
49
+
50
+ </body>
51
+
52
+ </html>
@@ -0,0 +1,47 @@
1
+ # Copyright (c) 2007 Blake Mizerany
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without
6
+ # restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the
9
+ # Software is furnished to do so, subject to the following
10
+ # conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ # OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ %w(rubygems rack).each do |library|
25
+ begin
26
+ require library
27
+ rescue LoadError
28
+ raise "== Sinatra cannot run without #{library} installed"
29
+ end
30
+ end
31
+
32
+ SINATRA_ROOT = File.dirname(__FILE__) + '/..'
33
+
34
+ require File.dirname(__FILE__) + '/sinatra/loader'
35
+
36
+ Sinatra::Loader.load_files Dir.glob(SINATRA_ROOT + '/lib/sinatra/core_ext/*.rb')
37
+ Sinatra::Loader.load_files Dir.glob(SINATRA_ROOT + '/lib/sinatra/rack_ext/*.rb')
38
+ Sinatra::Loader.load_files Dir.glob(SINATRA_ROOT + '/lib/sinatra/*.rb')
39
+ Sinatra::Loader.load_files Dir.glob(SINATRA_ROOT + '/vendor/*/init.rb')
40
+
41
+ Sinatra::Environment.prepare
42
+
43
+ at_exit do
44
+ Sinatra::Environment.prepare_loggers unless Sinatra::Options.environment == :test
45
+ Sinatra::Irb.start! if Sinatra::Options.console
46
+ Sinatra::Server.new.start unless Sinatra::Server.running
47
+ end