synfeld 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/History.txt +15 -0
- data/README.rdoc +206 -0
- data/README.txt +206 -0
- data/Rakefile +74 -0
- data/TODO +1 -0
- data/example/public/erb_files/erb_test.erb +16 -0
- data/example/public/haml_files/haml_test.haml +15 -0
- data/example/public/haml_files/home.haml +19 -0
- data/example/public/html_files/html_test.html +14 -0
- data/example/public/images/beef_interstellar_thm.jpg +0 -0
- data/example/public/images/rails.png +0 -0
- data/example/try_me.rb +65 -0
- data/example/try_me.ru +6 -0
- data/lib/synfeld/base.rb +281 -0
- data/lib/synfeld.rb +17 -0
- data/lib/synfeld_info.rb +51 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/synfeld_spec.rb +7 -0
- data/synfeld.gemspec +50 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- data/test/test_synfeld.rb +0 -0
- data/work/rackmount-test.ru +59 -0
- metadata +134 -0
data/.gitignore
ADDED
data/History.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
== *Synfeld*
|
2
|
+
|
3
|
+
by {Steven Swerling}[http://tab-a.slot-z.net]
|
4
|
+
|
5
|
+
{rdoc}[http://tab-a.slot-z.net] | {github}[http://www.github.com/swerling/synfeld]
|
6
|
+
|
7
|
+
== Description
|
8
|
+
|
9
|
+
Synfeld is a web application framework that does practically nothing.
|
10
|
+
|
11
|
+
Synfeld is little more than a small wrapper for Rack::Mount (see http://github.com/josh/rack-mount). If you want a web framework that is mostly just going to serve up json blobs, and occasionally serve up some simple content (eg. help files) and media, Synfeld makes that easy.
|
12
|
+
|
13
|
+
The sample app below shows pretty much everything there is to know about synfeld, in particular:
|
14
|
+
|
15
|
+
* How to define routes.
|
16
|
+
* Simple rendering of erb, haml, html, json, and static files.
|
17
|
+
* In the case of erb and haml, passing variables into the template is demonstrated.
|
18
|
+
* A dynamic action where the status code, headers, and body are created 'manually' (/my/special/route below)
|
19
|
+
* A simple way of creating format sensitive routes (/alphabet.html vs. /alphabet.json)
|
20
|
+
* The erb demo link also demos the rendering of a partial (not visible in the code below, you have to look at the template file examples/public/erb_files/erb_test.erb).
|
21
|
+
|
22
|
+
== Synopsis/Example
|
23
|
+
|
24
|
+
Here is an example Synfeld application (foo_app.rb):
|
25
|
+
|
26
|
+
require 'synfeld'
|
27
|
+
require 'json'
|
28
|
+
|
29
|
+
class FooApp < Synfeld::App
|
30
|
+
|
31
|
+
def add_routes
|
32
|
+
add_route "/yap/:yap_variable", :action => "yap"
|
33
|
+
add_route "/html_test", :action => "html_test"
|
34
|
+
add_route "/haml_test", :action => "haml_test"
|
35
|
+
add_route "/erb_test", :action => "erb_test"
|
36
|
+
add_route '/alphabet.:format', :action => "alphabet"
|
37
|
+
add_route "/my/special/route", :action => "my_special_route",
|
38
|
+
:extra_parm1 => 'really',
|
39
|
+
:extra_parm2 => 'truly'
|
40
|
+
add_route '/', :action => "home"
|
41
|
+
end
|
42
|
+
|
43
|
+
# files are looked up relative to the root directory specified in initialize
|
44
|
+
def home
|
45
|
+
render_haml('haml_files/home.haml')
|
46
|
+
end
|
47
|
+
|
48
|
+
def yap
|
49
|
+
"yap, #{self.params[:yap_variable]}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def html_test
|
53
|
+
render_html('html_files/html_test.html')
|
54
|
+
end
|
55
|
+
|
56
|
+
def haml_test
|
57
|
+
render_haml('haml_files/haml_test.haml', :ran100 => Kernel.rand(100) + 1, :time => Time.now)
|
58
|
+
end
|
59
|
+
|
60
|
+
def erb_test
|
61
|
+
render_erb('erb_files/erb_test.erb', :ran100 => Kernel.rand(100) + 1, :time => Time.now)
|
62
|
+
end
|
63
|
+
|
64
|
+
def alphabet
|
65
|
+
alphabet = ('a'..'z').collect{|ch|ch}
|
66
|
+
case params[:format]
|
67
|
+
when 'html'
|
68
|
+
return "<html><body>#{alphabet.join("<br/>")}</body></html>"
|
69
|
+
when 'json'
|
70
|
+
hash = {:desc => 'here is the alphabet', :alphabet => alphabet}
|
71
|
+
render_json hash.to_json
|
72
|
+
else
|
73
|
+
raise "Format not recognized: #{params[:format]}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def my_special_route
|
78
|
+
self.response[:status_code] = 200
|
79
|
+
self.response[:headers]['Content-Type'] = 'text/html'
|
80
|
+
self.response[:body] = <<-HTML
|
81
|
+
<html>
|
82
|
+
<body>I'm <i>special</i>,
|
83
|
+
#{self.params[:extra_parm1]} and #{self.params[:extra_parm2]}</body>
|
84
|
+
</html>
|
85
|
+
HTML
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
And here is an example rack config, foo_app.ru:
|
90
|
+
|
91
|
+
require '/path/to/foo_app.rb'
|
92
|
+
use Rack::CommonLogger, logger = Logger.new('/tmp/synfeld.log')
|
93
|
+
foo_app = FooApp.new( :logger => logger, :root_dir => '/path/to/root/dir' )
|
94
|
+
run foo_app.as_rack_app
|
95
|
+
|
96
|
+
Run FooApp w/ rackup or shotgun:
|
97
|
+
|
98
|
+
rackup foo_app.ru -p 3000
|
99
|
+
|
100
|
+
or
|
101
|
+
|
102
|
+
shotgun foo_app.ru -p 3000
|
103
|
+
|
104
|
+
== Features
|
105
|
+
|
106
|
+
==== The Router
|
107
|
+
|
108
|
+
When a Synfeld application starts up, it will call your app's 'add_routes' method, where you have to create your routes using the #add_route method. Example calls to add_route:
|
109
|
+
|
110
|
+
1. add_route %r{/some/path/(?:<somevar>.*)}, :action => "haml_test"
|
111
|
+
2. add_route "/some/otherpath/:somevar", :action => "haml_test"
|
112
|
+
3. add_route "/yet/anotherpath/:var", :action => "haml_test", :method => 'post', :furthermore => 'art is dead'
|
113
|
+
|
114
|
+
* At minimum, you have to provide the route and the :action to #add_route.
|
115
|
+
* When a route is passed as a regex (the 1st add_route line above), it is passed straight through to rackmount as is, so rackmount's rules apply.
|
116
|
+
* When using the convenience notation of the second add_route line above, the '/some/path/:somevar' is converted to a rackmount regex route under the covers, and :somevar will be passed to your app as a param (this is shown in the example code's #yap and #my_special_route methods).
|
117
|
+
* The 3rd add_route example shows how you can set any additional parameters on the route by adding associations onto the end of the route (this is also shown in #my_special_route in the example application above).
|
118
|
+
* If you happen to have a parameter called ':method', it will determine the request method required for the route (eg. 'get', 'put', 'post'). If the :method is not passed in, 'get' is assumed.
|
119
|
+
|
120
|
+
Note that rack-mount is an evolving project, so the examples above may have to be tweaked a bit in the future.
|
121
|
+
|
122
|
+
==== The Response
|
123
|
+
|
124
|
+
When a Synfeld application handles a rack request, it
|
125
|
+
|
126
|
+
1. Duplicates itself (so it's thread safe)
|
127
|
+
2. Sets @response, @params, @env (@env is just the rack env)
|
128
|
+
3. Calls the action that the route that matched.
|
129
|
+
|
130
|
+
The @response is a hash used to return the rack status code, headers hash, and body. Actions may do what they please with the response. Default response:
|
131
|
+
|
132
|
+
@response = {
|
133
|
+
:status_code => 200,
|
134
|
+
:headers => {'Content-Type' => 'text/html'},
|
135
|
+
:body => nil
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
Actions are expected to side-effect the :status_code, :headers, and :body if the defaults are not appropriate. As a convenience, if an action returns a string, it is assumed that that string is to be used as the response[:body]. An exception is thrown if the :body is not set to something. The 'Content-Length' header will be derived from the body's size.
|
140
|
+
|
141
|
+
As the example app above shows, you can serve templated content in the form of 'haml' or 'erb' files (the #erb_test and #haml_test methods in the code above).
|
142
|
+
|
143
|
+
Synfeld can currenty serve up the following types of static files:
|
144
|
+
|
145
|
+
js, css, png, gif, jpg, jpeg, html
|
146
|
+
|
147
|
+
Synfeld can currently render the following dynamic content:
|
148
|
+
|
149
|
+
erb, haml, json
|
150
|
+
|
151
|
+
Additional file types can be added upon request. Or you can just look at the synfeld code, which is tiny, then roll your own render method.
|
152
|
+
|
153
|
+
You can pass local variables to erb and haml.
|
154
|
+
|
155
|
+
Rendering 'partials' is trivial and is demonstrated in the included sample application file examples/public/erb_files/erb_test.erb.
|
156
|
+
|
157
|
+
==== That's It
|
158
|
+
|
159
|
+
Synfeld just gives you a thread-safe rack-based web framework that consists of just a little more than a router. There's really not much to see. If you want caching, security, session access, etc, it is assumed you will add those as Rack middleware.
|
160
|
+
|
161
|
+
== Problems
|
162
|
+
|
163
|
+
None known.
|
164
|
+
|
165
|
+
== Requirements
|
166
|
+
|
167
|
+
* ruby (either 1.8.X or 1.9.X)
|
168
|
+
* ruby, rubygems, rack, rack-router
|
169
|
+
* For rack-router, see http://github.com/carllerche/rack-router
|
170
|
+
|
171
|
+
== Install
|
172
|
+
|
173
|
+
1. [install rack if necessary]
|
174
|
+
2. gem install josh-rack-mount --source=http://gems.github.com
|
175
|
+
3. gem install swerling-synfeld --source http://gems.github.com
|
176
|
+
|
177
|
+
(note: I noticed sometimes josh-rack-mount will complain about rack version
|
178
|
+
not being high enough, even if you are already on version 1.0.0. If that happens,
|
179
|
+
you have to clone the rack-mount repo locally and just build the rack-mount gem
|
180
|
+
yourself)
|
181
|
+
|
182
|
+
== License
|
183
|
+
|
184
|
+
(the MIT License)
|
185
|
+
|
186
|
+
Copyright (c) 2009 Steven Swerling
|
187
|
+
|
188
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
189
|
+
a copy of this software and associated documentation files (the
|
190
|
+
'Software'), to deal in the Software without restriction, including
|
191
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
192
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
193
|
+
permit persons to whom the Software is furnished to do so, subject to
|
194
|
+
the following conditions:
|
195
|
+
|
196
|
+
The above copyright notice and this permission notice shall be
|
197
|
+
included in all copies or substantial portions of the Software.
|
198
|
+
|
199
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
200
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
201
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
202
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
203
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
204
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
205
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
206
|
+
|
data/README.txt
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
== *Synfeld*
|
2
|
+
|
3
|
+
by {Steven Swerling}[http://tab-a.slot-z.net]
|
4
|
+
|
5
|
+
{rdoc}[http://tab-a.slot-z.net] | {github}[http://www.github.com/swerling/synfeld]
|
6
|
+
|
7
|
+
== Description
|
8
|
+
|
9
|
+
Synfeld is a web application framework that does practically nothing.
|
10
|
+
|
11
|
+
Synfeld is little more than a small wrapper for Rack::Mount (see http://github.com/josh/rack-mount). If you want a web framework that is mostly just going to serve up json blobs, and occasionally serve up some simple content (eg. help files) and media, Synfeld makes that easy.
|
12
|
+
|
13
|
+
The sample app below shows pretty much everything there is to know about synfeld, in particular:
|
14
|
+
|
15
|
+
* How to define routes.
|
16
|
+
* Simple rendering of erb, haml, html, json, and static files.
|
17
|
+
* In the case of erb and haml, passing variables into the template is demonstrated.
|
18
|
+
* A dynamic action where the status code, headers, and body are created 'manually' (/my/special/route below)
|
19
|
+
* A simple way of creating format sensitive routes (/alphabet.html vs. /alphabet.json)
|
20
|
+
* The erb demo link also demos the rendering of a partial (not visible in the code below, you have to look at the template file examples/public/erb_files/erb_test.erb).
|
21
|
+
|
22
|
+
== Synopsis/Example
|
23
|
+
|
24
|
+
Here is an example Synfeld application (foo_app.rb):
|
25
|
+
|
26
|
+
require 'synfeld'
|
27
|
+
require 'json'
|
28
|
+
|
29
|
+
class FooApp < Synfeld::App
|
30
|
+
|
31
|
+
def add_routes
|
32
|
+
add_route "/yap/:yap_variable", :action => "yap"
|
33
|
+
add_route "/html_test", :action => "html_test"
|
34
|
+
add_route "/haml_test", :action => "haml_test"
|
35
|
+
add_route "/erb_test", :action => "erb_test"
|
36
|
+
add_route '/alphabet.:format', :action => "alphabet"
|
37
|
+
add_route "/my/special/route", :action => "my_special_route",
|
38
|
+
:extra_parm1 => 'really',
|
39
|
+
:extra_parm2 => 'truly'
|
40
|
+
add_route '/', :action => "home"
|
41
|
+
end
|
42
|
+
|
43
|
+
# files are looked up relative to the root directory specified in initialize
|
44
|
+
def home
|
45
|
+
render_haml('haml_files/home.haml')
|
46
|
+
end
|
47
|
+
|
48
|
+
def yap
|
49
|
+
"yap, #{self.params[:yap_variable]}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def html_test
|
53
|
+
render_html('html_files/html_test.html')
|
54
|
+
end
|
55
|
+
|
56
|
+
def haml_test
|
57
|
+
render_haml('haml_files/haml_test.haml', :ran100 => Kernel.rand(100) + 1, :time => Time.now)
|
58
|
+
end
|
59
|
+
|
60
|
+
def erb_test
|
61
|
+
render_erb('erb_files/erb_test.erb', :ran100 => Kernel.rand(100) + 1, :time => Time.now)
|
62
|
+
end
|
63
|
+
|
64
|
+
def alphabet
|
65
|
+
alphabet = ('a'..'z').collect{|ch|ch}
|
66
|
+
case params[:format]
|
67
|
+
when 'html'
|
68
|
+
return "<html><body>#{alphabet.join("<br/>")}</body></html>"
|
69
|
+
when 'json'
|
70
|
+
hash = {:desc => 'here is the alphabet', :alphabet => alphabet}
|
71
|
+
render_json hash.to_json
|
72
|
+
else
|
73
|
+
raise "Format not recognized: #{params[:format]}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def my_special_route
|
78
|
+
self.response[:status_code] = 200
|
79
|
+
self.response[:headers]['Content-Type'] = 'text/html'
|
80
|
+
self.response[:body] = <<-HTML
|
81
|
+
<html>
|
82
|
+
<body>I'm <i>special</i>,
|
83
|
+
#{self.params[:extra_parm1]} and #{self.params[:extra_parm2]}</body>
|
84
|
+
</html>
|
85
|
+
HTML
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
And here is an example rack config, foo_app.ru:
|
90
|
+
|
91
|
+
require '/path/to/foo_app.rb'
|
92
|
+
use Rack::CommonLogger, logger = Logger.new('/tmp/synfeld.log')
|
93
|
+
foo_app = FooApp.new( :logger => logger, :root_dir => '/path/to/root/dir' )
|
94
|
+
run foo_app.as_rack_app
|
95
|
+
|
96
|
+
Run FooApp w/ rackup or shotgun:
|
97
|
+
|
98
|
+
rackup foo_app.ru -p 3000
|
99
|
+
|
100
|
+
or
|
101
|
+
|
102
|
+
shotgun foo_app.ru -p 3000
|
103
|
+
|
104
|
+
== Features
|
105
|
+
|
106
|
+
==== The Router
|
107
|
+
|
108
|
+
When a Synfeld application starts up, it will call your app's 'add_routes' method, where you have to create your routes using the #add_route method. Example calls to add_route:
|
109
|
+
|
110
|
+
1. add_route %r{/some/path/(?:<somevar>.*)}, :action => "haml_test"
|
111
|
+
2. add_route "/some/otherpath/:somevar", :action => "haml_test"
|
112
|
+
3. add_route "/yet/anotherpath/:var", :action => "haml_test", :method => 'post', :furthermore => 'art is dead'
|
113
|
+
|
114
|
+
* At minimum, you have to provide the route and the :action to #add_route.
|
115
|
+
* When a route is passed as a regex (the 1st add_route line above), it is passed straight through to rackmount as is, so rackmount's rules apply.
|
116
|
+
* When using the convenience notation of the second add_route line above, the '/some/path/:somevar' is converted to a rackmount regex route under the covers, and :somevar will be passed to your app as a param (this is shown in the example code's #yap and #my_special_route methods).
|
117
|
+
* The 3rd add_route example shows how you can set any additional parameters on the route by adding associations onto the end of the route (this is also shown in #my_special_route in the example application above).
|
118
|
+
* If you happen to have a parameter called ':method', it will determine the request method required for the route (eg. 'get', 'put', 'post'). If the :method is not passed in, 'get' is assumed.
|
119
|
+
|
120
|
+
Note that rack-mount is an evolving project, so the examples above may have to be tweaked a bit in the future.
|
121
|
+
|
122
|
+
==== The Response
|
123
|
+
|
124
|
+
When a Synfeld application handles a rack request, it
|
125
|
+
|
126
|
+
1. Duplicates itself (so it's thread safe)
|
127
|
+
2. Sets @response, @params, @env (@env is just the rack env)
|
128
|
+
3. Calls the action that the route that matched.
|
129
|
+
|
130
|
+
The @response is a hash used to return the rack status code, headers hash, and body. Actions may do what they please with the response. Default response:
|
131
|
+
|
132
|
+
@response = {
|
133
|
+
:status_code => 200,
|
134
|
+
:headers => {'Content-Type' => 'text/html'},
|
135
|
+
:body => nil
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
Actions are expected to side-effect the :status_code, :headers, and :body if the defaults are not appropriate. As a convenience, if an action returns a string, it is assumed that that string is to be used as the response[:body]. An exception is thrown if the :body is not set to something. The 'Content-Length' header will be derived from the body's size.
|
140
|
+
|
141
|
+
As the example app above shows, you can serve templated content in the form of 'haml' or 'erb' files (the #erb_test and #haml_test methods in the code above).
|
142
|
+
|
143
|
+
Synfeld can currenty serve up the following types of static files:
|
144
|
+
|
145
|
+
js, css, png, gif, jpg, jpeg, html
|
146
|
+
|
147
|
+
Synfeld can currently render the following dynamic content:
|
148
|
+
|
149
|
+
erb, haml, json
|
150
|
+
|
151
|
+
Additional file types can be added upon request. Or you can just look at the synfeld code, which is tiny, then roll your own render method.
|
152
|
+
|
153
|
+
You can pass local variables to erb and haml.
|
154
|
+
|
155
|
+
Rendering 'partials' is trivial and is demonstrated in the included sample application file examples/public/erb_files/erb_test.erb.
|
156
|
+
|
157
|
+
==== That's It
|
158
|
+
|
159
|
+
Synfeld just gives you a thread-safe rack-based web framework that consists of just a little more than a router. There's really not much to see. If you want caching, security, session access, etc, it is assumed you will add those as Rack middleware.
|
160
|
+
|
161
|
+
== Problems
|
162
|
+
|
163
|
+
None known.
|
164
|
+
|
165
|
+
== Requirements
|
166
|
+
|
167
|
+
* ruby (either 1.8.X or 1.9.X)
|
168
|
+
* ruby, rubygems, rack, rack-router
|
169
|
+
* For rack-router, see http://github.com/carllerche/rack-router
|
170
|
+
|
171
|
+
== Install
|
172
|
+
|
173
|
+
1. [install rack if necessary]
|
174
|
+
2. gem install josh-rack-mount --source=http://gems.github.com
|
175
|
+
3. gem install swerling-synfeld --source http://gems.github.com
|
176
|
+
|
177
|
+
(note: I noticed sometimes josh-rack-mount will complain about rack version
|
178
|
+
not being high enough, even if you are already on version 1.0.0. If that happens,
|
179
|
+
you have to clone the rack-mount repo locally and just build the rack-mount gem
|
180
|
+
yourself)
|
181
|
+
|
182
|
+
== License
|
183
|
+
|
184
|
+
(the MIT License)
|
185
|
+
|
186
|
+
Copyright (c) 2009 Steven Swerling
|
187
|
+
|
188
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
189
|
+
a copy of this software and associated documentation files (the
|
190
|
+
'Software'), to deal in the Software without restriction, including
|
191
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
192
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
193
|
+
permit persons to whom the Software is furnished to do so, subject to
|
194
|
+
the following conditions:
|
195
|
+
|
196
|
+
The above copyright notice and this permission notice shall be
|
197
|
+
included in all copies or substantial portions of the Software.
|
198
|
+
|
199
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
200
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
201
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
202
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
203
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
204
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
205
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
206
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
+
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
+
# are where the options are used.
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bones'
|
7
|
+
Bones.setup
|
8
|
+
rescue LoadError
|
9
|
+
begin
|
10
|
+
load 'tasks/setup.rb'
|
11
|
+
rescue LoadError
|
12
|
+
raise RuntimeError, '### please install the "bones" gem ###'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ensure_in_path 'lib'
|
17
|
+
require 'synfeld_info'
|
18
|
+
|
19
|
+
task :default => 'spec:run'
|
20
|
+
|
21
|
+
PROJ.name = 'synfeld'
|
22
|
+
PROJ.authors = 'Steven Swerling'
|
23
|
+
PROJ.email = 'sswerling@yahoo.com'
|
24
|
+
PROJ.url = 'http://tab-a.slot-z.net'
|
25
|
+
PROJ.version = Synfeld::VERSION
|
26
|
+
PROJ.rubyforge.name = 'synfeld'
|
27
|
+
PROJ.gem.dependencies = ['rack', 'rack-router']
|
28
|
+
PROJ.rdoc.opts = ["--inline-source"]
|
29
|
+
PROJ.rdoc.exclude = ["^tasks/setup\.rb$", "lib/synfeld_info.rb"]
|
30
|
+
|
31
|
+
PROJ.spec.opts << '--color'
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
require 'fileutils'
|
36
|
+
def this_dir; File.join(File.dirname(__FILE__)); end
|
37
|
+
def doc_dir; File.join(this_dir, 'rdoc'); end
|
38
|
+
def tab_a_doc_dir; File.join(this_dir, '../tab-a/public/synfeld/rdoc'); end
|
39
|
+
|
40
|
+
task :default => 'spec:run'
|
41
|
+
task :myclobber => [:clobber] do
|
42
|
+
mydir = File.join(File.dirname(__FILE__))
|
43
|
+
sh "rm -rf #{File.join(mydir, 'pkg')}"
|
44
|
+
sh "rm -rf #{File.join(mydir, 'doc')}"
|
45
|
+
sh "rm -rf #{File.join(mydir, 'rdoc')}"
|
46
|
+
sh "rm -rf #{File.join(mydir, 'ext/*.log')}"
|
47
|
+
sh "rm -rf #{File.join(mydir, 'ext/*.o')}"
|
48
|
+
sh "rm -rf #{File.join(mydir, 'ext/*.so')}"
|
49
|
+
sh "rm -rf #{File.join(mydir, 'ext/Makefile')}"
|
50
|
+
sh "rm -rf #{File.join(mydir, 'ext/Makefile')}"
|
51
|
+
sh "cp #{File.join(mydir, 'README.rdoc')} #{File.join(mydir, 'README.txt')}" # concession to bones
|
52
|
+
end
|
53
|
+
task :mypackage => [:myclobber] do
|
54
|
+
Rake::Task['gem:package'].invoke
|
55
|
+
end
|
56
|
+
task :mydoc => [:myclobber] do
|
57
|
+
FileUtils.rm_f doc_dir()
|
58
|
+
#sh "cd #{this_dir()} && rdoc -o rdoc --inline-source --format=html -T hanna README.rdoc lib/**/*.rb"
|
59
|
+
this_dir = File.dirname(__FILE__) + '/'
|
60
|
+
files = []
|
61
|
+
files += Dir[File.join(this_dir, 'lib/**/*.rb')].map{|fn| fn.gsub(this_dir,'')}
|
62
|
+
files += Dir[File.join(this_dir, 'example/**/*.*')].map{|fn| fn.gsub(this_dir,'')}
|
63
|
+
files += ['README.rdoc']
|
64
|
+
files = files.reject{|fn| fn =~ /jpg/ }.sort
|
65
|
+
sh "cd #{this_dir()} && rdoc -o rdoc --inline-source #{files.flatten.join(" ")}"
|
66
|
+
end
|
67
|
+
task :taba => [:mydoc] do
|
68
|
+
this_dir = File.join(File.dirname(__FILE__))
|
69
|
+
FileUtils.rm_rf tab_a_doc_dir
|
70
|
+
FileUtils.cp_r doc_dir, tab_a_doc_dir
|
71
|
+
end
|
72
|
+
task :mygemspec => [:myclobber] do
|
73
|
+
Rake::Task['gem:spec'].invoke
|
74
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Create a sourceforge gem and move all the docs over there from slot-z.com.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<html>
|
2
|
+
<body>
|
3
|
+
<div>
|
4
|
+
<h3> Here is an erb test</h3>
|
5
|
+
Here is the time: <%= time %>
|
6
|
+
<br/>ran100: <%= ran100 %> (local variable passed in)
|
7
|
+
<br/><a href="/">home</a>
|
8
|
+
<br/>
|
9
|
+
<br/>
|
10
|
+
Here is the home page rendered as a partial:
|
11
|
+
<div style="margin-left: 50px">
|
12
|
+
<%= render_haml('haml_files/home.haml') %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
%html
|
2
|
+
%body
|
3
|
+
|
4
|
+
%ul
|
5
|
+
%li
|
6
|
+
%a{:href => 'http://www.github.com/swerling/synfeld'} synfeld on github
|
7
|
+
%li
|
8
|
+
%a{:href => '/haml_test'} test a haml file
|
9
|
+
%li
|
10
|
+
%a{:href => '/erb_test'} test an erb file
|
11
|
+
%li
|
12
|
+
%a{:href => '/html_test'} test an html file
|
13
|
+
%li
|
14
|
+
%a{:href => '/my/special/route'} test of non-static action
|
15
|
+
%li
|
16
|
+
%a{:href => '/alphabet.json'} alphabet as json
|
17
|
+
%li
|
18
|
+
%a{:href => '/alphabet.html'} alphabet as html
|
19
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<html>
|
2
|
+
<body>
|
3
|
+
<h1>This is: html_test.html</h1>
|
4
|
+
|
5
|
+
<p>
|
6
|
+
<h3>Not much to see here</h3>
|
7
|
+
Just testing render of a html file.
|
8
|
+
<a href='http://www.github.com/swerling/synfeld'>synfeld on github</a>
|
9
|
+
<br/>Serve up a static: <a href='http://www.achewood.com/'> <img src='images/beef_interstellar_thm.jpg'/> </a>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
</body>
|
13
|
+
</html>
|
14
|
+
|
Binary file
|
Binary file
|
data/example/try_me.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/synfeld.rb'))
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
# This is the sample Synfeld::App described in the README.rdoc
|
5
|
+
class TryMe < Synfeld::App
|
6
|
+
|
7
|
+
def add_routes
|
8
|
+
add_route "/yap/:yap_variable", :action => "yap"
|
9
|
+
add_route "/html_test", :action => "html_test"
|
10
|
+
add_route "/haml_test", :action => "haml_test"
|
11
|
+
add_route "/erb_test", :action => "erb_test"
|
12
|
+
add_route '/alphabet.:format', :action => "alphabet"
|
13
|
+
add_route "/my/special/route", :action => "my_special_route",
|
14
|
+
:extra_parm1 => 'really',
|
15
|
+
:extra_parm2 => 'truly'
|
16
|
+
add_route '/', :action => "home"
|
17
|
+
end
|
18
|
+
|
19
|
+
# files are looked up relative to the root directory specified in initialize
|
20
|
+
def home
|
21
|
+
render_haml('haml_files/home.haml')
|
22
|
+
end
|
23
|
+
|
24
|
+
def yap
|
25
|
+
"yap, #{self.params[:yap_variable]}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def html_test
|
29
|
+
render_html('html_files/html_test.html')
|
30
|
+
end
|
31
|
+
|
32
|
+
def haml_test
|
33
|
+
render_haml('haml_files/haml_test.haml', :ran100 => Kernel.rand(100) + 1, :time => Time.now)
|
34
|
+
end
|
35
|
+
|
36
|
+
def erb_test
|
37
|
+
render_erb('erb_files/erb_test.erb', :ran100 => Kernel.rand(100) + 1, :time => Time.now)
|
38
|
+
end
|
39
|
+
|
40
|
+
def alphabet
|
41
|
+
alphabet = ('a'..'z').collect{|ch|ch}
|
42
|
+
case params[:format]
|
43
|
+
when 'html'
|
44
|
+
return "<html><body>#{alphabet.join("<br/>")}</body></html>"
|
45
|
+
when 'json'
|
46
|
+
hash = {:desc => 'here is the alphabet', :alphabet => alphabet}
|
47
|
+
render_json hash.to_json
|
48
|
+
else
|
49
|
+
raise "Format not recognized: #{params[:format]}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def my_special_route
|
54
|
+
self.response[:status_code] = 200
|
55
|
+
self.response[:headers]['Content-Type'] = 'text/html'
|
56
|
+
self.response[:body] = <<-HTML
|
57
|
+
<html>
|
58
|
+
<body>I'm <i>special</i>,
|
59
|
+
#{self.params[:extra_parm1]} and #{self.params[:extra_parm2]}</body>
|
60
|
+
</html>
|
61
|
+
HTML
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
data/example/try_me.ru
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require ::File.join(::File.dirname(__FILE__),'try_me.rb')
|
2
|
+
use Rack::CommonLogger, logger = Logger.new('/tmp/synfeld.log')
|
3
|
+
#use Rack::Reloader, 0
|
4
|
+
try_me = TryMe.new( :logger => logger,
|
5
|
+
:root_dir => ::File.expand_path(::File.join(::File.dirname(__FILE__), 'public')))
|
6
|
+
run try_me.as_rack_app
|