wbzyl-sinatra-math 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/README.markdown +178 -0
- data/Rakefile +44 -0
- data/VERSION.yml +4 -0
- data/config.rb +27 -0
- data/config.ru +2 -0
- data/examples/app.rb +27 -0
- data/examples/euler.ru +2 -0
- data/examples/mathlobster.rb +12 -0
- data/examples/mathlobster.ru +2 -0
- data/examples/menagerie.rb +28 -0
- data/examples/phi.ru +2 -0
- data/examples/pi.ru +2 -0
- data/examples/rapp.ru +3 -0
- data/examples/sqrt2.ru +2 -0
- data/lib/sinatra-math.rb +26 -0
- data/lib/sinatra-math/euler.rb +16 -0
- data/lib/sinatra-math/phi.rb +16 -0
- data/lib/sinatra-math/pi.rb +16 -0
- data/lib/sinatra-math/sqrt2.rb +16 -0
- data/lib/views/euler.erb +3 -0
- data/lib/views/index.erb +1 -0
- data/lib/views/layout.erb +8 -0
- data/lib/views/phi.erb +3 -0
- data/lib/views/pi.erb +3 -0
- data/lib/views/sqrt2.erb +3 -0
- metadata +109 -0
data/.gitignore
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# Sinatra Math Menagerie
|
2
|
+
|
3
|
+
This gem contains four modular Sinatra applications:
|
4
|
+
|
5
|
+
* Sinatra::Pi
|
6
|
+
* Sinatra::Euler
|
7
|
+
* Sinatra::Sqrt2
|
8
|
+
* Sinatra::Phi
|
9
|
+
|
10
|
+
These applications can be used to play with:
|
11
|
+
|
12
|
+
* experiment with new and existing Rack Middleware
|
13
|
+
* combine modular Sinatra app with Rack::Builder
|
14
|
+
* embed one Rack application into another Rack application.
|
15
|
+
|
16
|
+
Build an install the gem with:
|
17
|
+
|
18
|
+
rake install
|
19
|
+
|
20
|
+
|
21
|
+
## Examples
|
22
|
+
|
23
|
+
The directory `examples` contains several ready to run applications.
|
24
|
+
For example, run the *pi.ru* file with:
|
25
|
+
|
26
|
+
rackup pi.ru -p 3000
|
27
|
+
|
28
|
+
And see the result at:
|
29
|
+
|
30
|
+
http://localhost:3000
|
31
|
+
|
32
|
+
To get more digits input:
|
33
|
+
|
34
|
+
http://localhost:3000/?prec=256
|
35
|
+
|
36
|
+
Have a fun!
|
37
|
+
|
38
|
+
|
39
|
+
### Playing with Rack::Builder\#map
|
40
|
+
|
41
|
+
`Rack::Builder#map` mounts a stack of rack application/middlewares the
|
42
|
+
specified path or URI and all the children paths under it.
|
43
|
+
|
44
|
+
# app.rb
|
45
|
+
require 'sinatra-math'
|
46
|
+
require 'rack/lobster'
|
47
|
+
|
48
|
+
App = Rack::Builder.new do
|
49
|
+
use Rack::ShowExceptions
|
50
|
+
use Rack::Lint
|
51
|
+
use Rack::CommonLogger
|
52
|
+
|
53
|
+
map '/math' do
|
54
|
+
map '/euler' do
|
55
|
+
run Sinatra::Euler.new
|
56
|
+
end
|
57
|
+
|
58
|
+
map '/pi' do
|
59
|
+
run Sinatra::Pi.new
|
60
|
+
end
|
61
|
+
|
62
|
+
map '/sqrt2' do
|
63
|
+
run Sinatra::Sqrt2.new
|
64
|
+
end
|
65
|
+
|
66
|
+
map '/phi' do
|
67
|
+
run Sinatra::Phi.new
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
map '/lobster' do
|
72
|
+
run Rack::Lobster.new
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
In *app.rb* we use nesting to mount `Sinatra::Euler` under '/math/euler',
|
78
|
+
`Sinatra::Pi` under '/math/pi' etc.
|
79
|
+
Additionaly we mount *rack/lobster.rb* under '/lobster':
|
80
|
+
|
81
|
+
Run *app.rb* with:
|
82
|
+
|
83
|
+
rackup app.rb -p 3000
|
84
|
+
|
85
|
+
and watch the results at:
|
86
|
+
|
87
|
+
http://localhost:3000/math/euler
|
88
|
+
http://localhost:3000/math/pi?prec=1024
|
89
|
+
etc.
|
90
|
+
http://localhost:3000/lobster
|
91
|
+
|
92
|
+
Alternatively, create this rackup file:
|
93
|
+
|
94
|
+
# rapp.ru
|
95
|
+
require 'app'
|
96
|
+
run App
|
97
|
+
|
98
|
+
and run it with:
|
99
|
+
|
100
|
+
rackup rapp.ru -s thin -p 3000
|
101
|
+
|
102
|
+
or
|
103
|
+
|
104
|
+
thin --rackup rapp.ru -p 3000 start
|
105
|
+
|
106
|
+
Note, the use of the *thin* server.
|
107
|
+
|
108
|
+
The same results can be obtained in two steps.
|
109
|
+
First, create *menagerie.rb* file:
|
110
|
+
|
111
|
+
# menagerie.rb
|
112
|
+
require 'sinatra-math'
|
113
|
+
|
114
|
+
Menagerie = Rack::Builder.new do
|
115
|
+
use Rack::ShowExceptions
|
116
|
+
use Rack::Lint
|
117
|
+
use Rack::CommonLogger
|
118
|
+
|
119
|
+
map '/euler' do
|
120
|
+
run Sinatra::Euler.new
|
121
|
+
end
|
122
|
+
|
123
|
+
map '/pi' do
|
124
|
+
run Sinatra::Pi.new
|
125
|
+
end
|
126
|
+
|
127
|
+
map '/sqrt2' do
|
128
|
+
run Sinatra::Sqrt2.new
|
129
|
+
end
|
130
|
+
|
131
|
+
map '/phi' do
|
132
|
+
run Sinatra::Phi.new
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
Next, create *mathlobster.rb* file:
|
137
|
+
|
138
|
+
# mathlobster.rb
|
139
|
+
require 'menagerie'
|
140
|
+
require 'rack/lobster'
|
141
|
+
|
142
|
+
Mathlobster = Rack::Builder.new do
|
143
|
+
map '/math' do
|
144
|
+
run Menagerie
|
145
|
+
end
|
146
|
+
|
147
|
+
map '/lobster' do
|
148
|
+
run Rack::Lobster.new
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
and run it with:
|
153
|
+
|
154
|
+
rackup mathlobster.rb -p 3000
|
155
|
+
|
156
|
+
Alternatively, create this rackup file:
|
157
|
+
|
158
|
+
# mathlobster.ru
|
159
|
+
require 'mathlobster'
|
160
|
+
run Mathlobster
|
161
|
+
|
162
|
+
and run it with:
|
163
|
+
|
164
|
+
rackup mathlobster.ru -s thin -p 3000
|
165
|
+
|
166
|
+
or
|
167
|
+
|
168
|
+
thin --rackup mathlobster.ru -p 3000 start
|
169
|
+
|
170
|
+
|
171
|
+
### Playing with Rack Middleware
|
172
|
+
|
173
|
+
TODO
|
174
|
+
|
175
|
+
|
176
|
+
### Mounting apps which include Datamapper, ActiveRecord..
|
177
|
+
|
178
|
+
TODO
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '/lib')
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require "rake/clean"
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
|
11
|
+
gem.name = "sinatra-math"
|
12
|
+
gem.summary = "Several modular Sinatra apps to play with and iteratively construct new Rack apps."
|
13
|
+
gem.email = "matwb@univ.gda.pl"
|
14
|
+
gem.homepage = "http://github.com/wbzyl/sinatra-math"
|
15
|
+
gem.authors = ["Wlodek Bzyl"]
|
16
|
+
gem.description = <<-EOF
|
17
|
+
This gem contains four modular Sinatra applications:
|
18
|
+
Pi, Euler, Sqrt2, Phi (golden ratio).
|
19
|
+
|
20
|
+
These applications can be used to play with:
|
21
|
+
* experiment with new and existing Rack Middleware
|
22
|
+
* combine modular Sinatra app with Rack::Builder
|
23
|
+
* embed one Rack application into another Rack application
|
24
|
+
EOF
|
25
|
+
|
26
|
+
gem.add_runtime_dependency 'sinatra', '>= 0.9.2'
|
27
|
+
gem.add_runtime_dependency 'rack', '>=1.0.0'
|
28
|
+
|
29
|
+
gem.add_development_dependency 'rack-test', '>=0.3.0'
|
30
|
+
|
31
|
+
# gem is a Gem::Specification
|
32
|
+
# refer to http://www.rubygems.org/read/chapter/20 for additional settings
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
puts "Jeweler not available."
|
36
|
+
puts "Install it with:"
|
37
|
+
puts " sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
38
|
+
end
|
39
|
+
|
40
|
+
Rake::TestTask.new(:test) do |t|
|
41
|
+
t.libs << 'lib' << 'test'
|
42
|
+
t.pattern = 'test/**/*_test.rb'
|
43
|
+
t.verbose = false
|
44
|
+
end
|
data/VERSION.yml
ADDED
data/config.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sinatra-math'
|
2
|
+
require 'rack/lobster'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
class Pi < Sinatra::Base
|
6
|
+
set :logging, true
|
7
|
+
end
|
8
|
+
# see sinatra-math.rb
|
9
|
+
class Sqrt2 < Sinatra::Base
|
10
|
+
set :app_file, "/usr/lib/ruby/gems/1.8/gems/sinatra-math-0.0.4/lib"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
App = Rack::Builder.new do
|
15
|
+
map '/math' do
|
16
|
+
map '/pi' do
|
17
|
+
run Sinatra::Pi.new
|
18
|
+
end
|
19
|
+
map '/sqrt2' do
|
20
|
+
run Sinatra::Sqrt2.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
map '/lobster' do
|
25
|
+
run Rack::Lobster.new
|
26
|
+
end
|
27
|
+
end
|
data/config.ru
ADDED
data/examples/app.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sinatra-math'
|
2
|
+
require 'rack/lobster'
|
3
|
+
|
4
|
+
App = Rack::Builder.new do
|
5
|
+
map '/math' do
|
6
|
+
map '/euler' do
|
7
|
+
run Sinatra::Euler.new
|
8
|
+
end
|
9
|
+
|
10
|
+
map '/pi' do
|
11
|
+
run Sinatra::Pi.new
|
12
|
+
end
|
13
|
+
|
14
|
+
map '/sqrt2' do
|
15
|
+
run Sinatra::Sqrt2.new
|
16
|
+
end
|
17
|
+
|
18
|
+
map '/phi' do
|
19
|
+
run Sinatra::Phi.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
map '/lobster' do
|
24
|
+
run Rack::Lobster.new
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/examples/euler.ru
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'sinatra-math'
|
2
|
+
|
3
|
+
# module Sinatra
|
4
|
+
# class Pi < Sinatra::Base
|
5
|
+
# set :logging, true
|
6
|
+
# end
|
7
|
+
# end
|
8
|
+
|
9
|
+
Menagerie = Rack::Builder.new do
|
10
|
+
use Rack::Lint
|
11
|
+
|
12
|
+
map '/euler' do
|
13
|
+
run Sinatra::Euler.new
|
14
|
+
end
|
15
|
+
|
16
|
+
map '/pi' do
|
17
|
+
use Rack::CommonLogger
|
18
|
+
run Sinatra::Pi.new
|
19
|
+
end
|
20
|
+
|
21
|
+
map '/sqrt2' do
|
22
|
+
run Sinatra::Sqrt2.new
|
23
|
+
end
|
24
|
+
|
25
|
+
map '/phi' do
|
26
|
+
run Sinatra::Phi.new
|
27
|
+
end
|
28
|
+
end
|
data/examples/phi.ru
ADDED
data/examples/pi.ru
ADDED
data/examples/rapp.ru
ADDED
data/examples/sqrt2.ru
ADDED
data/lib/sinatra-math.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra-math/pi'
|
3
|
+
require 'sinatra-math/euler'
|
4
|
+
require 'sinatra-math/phi'
|
5
|
+
require 'sinatra-math/sqrt2'
|
6
|
+
|
7
|
+
module Sinatra
|
8
|
+
class Pi < Sinatra::Base
|
9
|
+
set :app_file, __FILE__
|
10
|
+
set :static, true
|
11
|
+
end
|
12
|
+
|
13
|
+
class Euler < Sinatra::Base
|
14
|
+
set :app_file, __FILE__
|
15
|
+
end
|
16
|
+
|
17
|
+
class Phi < Sinatra::Base
|
18
|
+
set :static, true
|
19
|
+
end
|
20
|
+
|
21
|
+
class Sqrt2 < Sinatra::Base
|
22
|
+
set :views, Proc.new { File.join(root, "lib/views") }
|
23
|
+
set :public, Proc.new { File.join(root, "lib/public") }
|
24
|
+
set :static, true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
require 'bigdecimal/math'
|
3
|
+
include BigMath
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
class Euler < Sinatra::Base
|
7
|
+
|
8
|
+
get '/?' do
|
9
|
+
prec = params[:prec].to_i
|
10
|
+
@euler = E(prec + 1).to_s("10F")
|
11
|
+
@cname = 'E'
|
12
|
+
erb :euler
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
require 'bigdecimal/math'
|
3
|
+
include BigMath
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
class Phi < Sinatra::Base
|
7
|
+
|
8
|
+
get '/?' do
|
9
|
+
prec = params[:prec].to_i
|
10
|
+
@phi = ((BigDecimal('5').sqrt(prec + 1) + 1) / 2).to_s("10F")
|
11
|
+
@cname = 'golden ratio'
|
12
|
+
erb :phi
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
require 'bigdecimal/math'
|
3
|
+
include BigMath
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
class Pi < Sinatra::Base
|
7
|
+
|
8
|
+
get '/?' do
|
9
|
+
prec = params[:prec].to_i
|
10
|
+
@pi = PI(prec + 1).to_s("10F")
|
11
|
+
@cname = 'PI'
|
12
|
+
erb :pi, :layout => :layout2
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
require 'bigdecimal/math'
|
3
|
+
include BigMath
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
class Sqrt2 < Sinatra::Base
|
7
|
+
|
8
|
+
get '/?' do
|
9
|
+
prec = params[:prec].to_i
|
10
|
+
@sqrt2 = BigDecimal('2').sqrt(prec + 1).to_s("10F")
|
11
|
+
@cname = 'square root of 2'
|
12
|
+
erb :sqrt2
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/views/euler.erb
ADDED
data/lib/views/index.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Math constants</h1>
|
data/lib/views/phi.erb
ADDED
data/lib/views/pi.erb
ADDED
data/lib/views/sqrt2.erb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wbzyl-sinatra-math
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wlodek Bzyl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sinatra
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rack-test
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.3.0
|
44
|
+
version:
|
45
|
+
description: "This gem contains four modular Sinatra applications: Pi, Euler, Sqrt2, Phi (golden ratio). These applications can be used to play with: * experiment with new and existing Rack Middleware * combine modular Sinatra app with Rack::Builder * embed one Rack application into another Rack application"
|
46
|
+
email: matwb@univ.gda.pl
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.markdown
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- README.markdown
|
56
|
+
- Rakefile
|
57
|
+
- VERSION.yml
|
58
|
+
- config.rb
|
59
|
+
- config.ru
|
60
|
+
- examples/app.rb
|
61
|
+
- examples/euler.ru
|
62
|
+
- examples/mathlobster.rb
|
63
|
+
- examples/mathlobster.ru
|
64
|
+
- examples/menagerie.rb
|
65
|
+
- examples/phi.ru
|
66
|
+
- examples/pi.ru
|
67
|
+
- examples/rapp.ru
|
68
|
+
- examples/sqrt2.ru
|
69
|
+
- lib/sinatra-math.rb
|
70
|
+
- lib/sinatra-math/euler.rb
|
71
|
+
- lib/sinatra-math/phi.rb
|
72
|
+
- lib/sinatra-math/pi.rb
|
73
|
+
- lib/sinatra-math/sqrt2.rb
|
74
|
+
- lib/views/euler.erb
|
75
|
+
- lib/views/index.erb
|
76
|
+
- lib/views/layout.erb
|
77
|
+
- lib/views/phi.erb
|
78
|
+
- lib/views/pi.erb
|
79
|
+
- lib/views/sqrt2.erb
|
80
|
+
has_rdoc: false
|
81
|
+
homepage: http://github.com/wbzyl/sinatra-math
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options:
|
84
|
+
- --charset=UTF-8
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
version:
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "0"
|
98
|
+
version:
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.2.0
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Several modular Sinatra apps to play with and iteratively construct new Rack apps.
|
106
|
+
test_files:
|
107
|
+
- examples/menagerie.rb
|
108
|
+
- examples/app.rb
|
109
|
+
- examples/mathlobster.rb
|