swerling-synfeld 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,8 @@
1
1
  pkg/
2
+ rdoc/
2
3
  doc/
3
4
  ext/Makefile
4
5
  ext/mkmf.log
5
6
  ext/*.o
6
7
  ext/*.so
8
+ *.swp
@@ -0,0 +1,167 @@
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
+ Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router). If you want a web framework that is mostly just going to serve up json blobs, and occasionally serve up some simple content (eg. for help files) and media, Synfeld makes that easy. If you need session variables, a mailer, uploading, etc, look elsewhere.
12
+
13
+ The sample app below shows pretty much everything that synfeld can do.
14
+
15
+ Very alpha-ish stuff here. Seems to work though.
16
+
17
+ == SYNOPSIS:
18
+
19
+ Here is an example Synfeld application (foo_app.rb):
20
+
21
+ class FooApp < Synfeld::App
22
+
23
+ def initialize
24
+ super(:root_dir => File.expand_path(File.join(File.dirname(__FILE__), 'public')),
25
+ :logger => Logger.new(STDOUT))
26
+ end
27
+
28
+ def router
29
+ return @router ||= Rack::Router.new(nil, {}) do |r|
30
+ r.map "/yap/:yap_variable", :get, :to => self, :with => { :action => "yap" }
31
+ r.map "/my/special/route", :get, :to => self, :with => { :action => "my_special_route" }
32
+ r.map "/html_test", :get, :to => self, :with => { :action => "html_test" }
33
+ r.map "/haml_test", :get, :to => self, :with => { :action => "haml_test" }
34
+ r.map "/erb_test", :get, :to => self, :with => { :action => "erb_test" }
35
+
36
+ # These next 2 have to come last
37
+ r.map "/:anything_else", :get, :to => self, :with => { :action => "handle_static" }
38
+ r.map "/", :get, :to => self, :with => { :action => "home" }
39
+ end
40
+ end
41
+
42
+ # files are looked up relative to the root directory specified in initialize
43
+ def home
44
+ serve('haml_files/home.haml')
45
+ end
46
+
47
+ def my_special_route
48
+ self.response[:status_code] = 200
49
+ self.response[:headers]['Content-Type'] = 'text/html'
50
+ self.response[:body] = <<-HTML
51
+ <html>
52
+ <body>I'm <i>special</i>.</body>
53
+ </html>
54
+ HTML
55
+ end
56
+
57
+ def yap
58
+ "yap, #{self.params[:yap_variable]}"
59
+ end
60
+
61
+ def html_test
62
+ serve('html_files/html_test.html')
63
+ end
64
+
65
+ def haml_test
66
+ serve('haml_files/haml_test.haml', {:ran100 => Kernel.rand(100) + 1, :time => Time.now})
67
+ end
68
+
69
+ def erb_test
70
+ serve('erb_files/erb_test.erb', {:ran100 => Kernel.rand(100) + 1, :time => Time.now})
71
+ end
72
+
73
+
74
+ end
75
+
76
+ And here is an example rack config, foo_app.ru:
77
+
78
+ require '/path/to/foo_app.rb'
79
+ run FooApp.new.as_rack_app
80
+
81
+ Run FooApp w/ rackup or shotgun:
82
+
83
+ rackup --server=thin foo.ru -p 3000
84
+
85
+ or
86
+
87
+ shotgun --server=thin foo.ru -p 3000
88
+
89
+ == FEATURES
90
+
91
+ When a Synfeld application handles a rack request, it
92
+
93
+ 1. Duplicates self (so it's thread safe)
94
+ 2. Sets @response, @params, @env (the rack env)
95
+ 3. Calls the action that Rack::Router route that matched. If the action returns a String, that is used for the @response[:body]
96
+
97
+ 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:
98
+
99
+ @response = {
100
+ :status_code => 200,
101
+ :headers => {'Content-Type' => 'text/html'},
102
+ :body => nil
103
+ }
104
+
105
+
106
+ 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 the :body. An exception is thrown if the :body is not set to something.
107
+
108
+ As the example app above shows, you can "serve" templated content in the form of 'haml' or 'erb' files.
109
+
110
+ Requests are bound to the first matching route. The 'handle_static' action considers the request path to be a path to a file relative to the 'root_dir' specified in initialize (see example app below).
111
+
112
+ Can currenty serve up the following types of static files:
113
+
114
+ js, css, png, gif, jpg, jpeg, html
115
+
116
+ Can currently render the following dynamic content:
117
+
118
+ erb, haml
119
+
120
+ Synfeld does not do partials, but you can set local variables for dynamic content.
121
+
122
+ That's it. Really not much to see here. Just gives you a thread-safe rack-based web framework that consists of little more than a router.
123
+
124
+ == PROBLEMS
125
+
126
+ None known.
127
+
128
+ == REQUIREMENTS:
129
+
130
+ * ruby, rubygems, rack, rack-router
131
+ * For rack-router, see http://github.com/carllerche/rack-router
132
+
133
+ == INSTALL:
134
+
135
+ First install rack and rack-router.
136
+
137
+ There's no gem for rack-router at the moment,
138
+ to you will have to clone it and build it yourself.
139
+
140
+ Then:
141
+
142
+ gem install swerling-synfeld --source http://gems.github.com
143
+
144
+ == LICENSE:
145
+
146
+ (The MIT License)
147
+
148
+ Copyright (c) 2009 Steven Swerling
149
+
150
+ Permission is hereby granted, free of charge, to any person obtaining
151
+ a copy of this software and associated documentation files (the
152
+ 'Software'), to deal in the Software without restriction, including
153
+ without limitation the rights to use, copy, modify, merge, publish,
154
+ distribute, sublicense, and/or sell copies of the Software, and to
155
+ permit persons to whom the Software is furnished to do so, subject to
156
+ the following conditions:
157
+
158
+ The above copyright notice and this permission notice shall be
159
+ included in all copies or substantial portions of the Software.
160
+
161
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
162
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
163
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
164
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
165
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
166
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
167
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.txt CHANGED
@@ -1,12 +1,16 @@
1
1
  synfeld
2
- by Steven Swerling
3
- http://tab-a.slot-z.net
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]
4
6
 
5
7
  == DESCRIPTION:
6
8
 
7
- Synfeld is an application framework that does almost nothing, and it ain't all that classy.
9
+ Synfeld is a web application framework that does practically nothing.
10
+
11
+ Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router). If you want a web framework that is mostly just going to serve up json blobs, and occasionally serve up some simple content (eg. for help files) and media, Synfeld makes that easy. If you need session variables, a mailer, uploading, etc, look elsewhere.
8
12
 
9
- Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router)
13
+ The sample app below shows pretty much everything that synfeld can do.
10
14
 
11
15
  Very alpha-ish stuff here. Seems to work though.
12
16
 
@@ -14,39 +18,64 @@ Very alpha-ish stuff here. Seems to work though.
14
18
 
15
19
  Here is an example Synfeld application (foo_app.rb):
16
20
 
17
- require 'synfeld'
18
-
19
21
  class FooApp < Synfeld::App
20
22
 
23
+ def initialize
24
+ super(:root_dir => File.expand_path(File.join(File.dirname(__FILE__), 'public')),
25
+ :logger => Logger.new(STDOUT))
26
+ end
27
+
21
28
  def router
22
- @router ||= Rack::Router.new(nil, {}) do |r|
23
- r.map "/yip/", :get, :to => self, :with => { :action => "yip" }
24
- r.map "/yap/:yap_variable", :get, :to => self, :with => { :action => "yapfoo" }
25
- r.map "/yap/", :get, :to => self, :with => { :action => "yap" }
26
- r.map "/:anything", :get, :to => self, :with => { :action => "no_route" }
27
- r.map "/", :get, :to => self, :with => { :action => "home" }
29
+ return @router ||= Rack::Router.new(nil, {}) do |r|
30
+ r.map "/yap/:yap_variable", :get, :to => self, :with => { :action => "yap" }
31
+ r.map "/my/special/route", :get, :to => self, :with => { :action => "my_special_route" }
32
+ r.map "/html_test", :get, :to => self, :with => { :action => "html_test" }
33
+ r.map "/haml_test", :get, :to => self, :with => { :action => "haml_test" }
34
+ r.map "/erb_test", :get, :to => self, :with => { :action => "erb_test" }
35
+
36
+ # These next 2 have to come last
37
+ r.map "/:anything_else", :get, :to => self, :with => { :action => "handle_static" }
38
+ r.map "/", :get, :to => self, :with => { :action => "home" }
28
39
  end
29
40
  end
30
41
 
31
- def yip; "yip"; end
32
- def yap; "yap"; end
33
- def home; "home"; end
42
+ # files are looked up relative to the root directory specified in initialize
43
+ def home
44
+ serve('haml_files/home.haml')
45
+ end
34
46
 
35
- def no_route
36
- # Note: 'self.env' is the rack env
37
- self.response[:body] = "route not found for: '#{self.env['REQUEST_URI']}'"
38
- self.response[:status_code] = 404
47
+ def my_special_route
48
+ self.response[:status_code] = 200
49
+ self.response[:headers]['Content-Type'] = 'text/html'
50
+ self.response[:body] = <<-HTML
51
+ <html>
52
+ <body>I'm <i>special</i>.</body>
53
+ </html>
54
+ HTML
39
55
  end
40
56
 
41
- def yapfoo
42
- "yapfoo, #{self.params[:yap_variable]}"
57
+ def yap
58
+ "yap, #{self.params[:yap_variable]}"
43
59
  end
44
60
 
61
+ def html_test
62
+ serve('html_files/html_test.html')
63
+ end
64
+
65
+ def haml_test
66
+ serve('haml_files/haml_test.haml', {:ran100 => Kernel.rand(100) + 1, :time => Time.now})
67
+ end
68
+
69
+ def erb_test
70
+ serve('erb_files/erb_test.erb', {:ran100 => Kernel.rand(100) + 1, :time => Time.now})
71
+ end
72
+
73
+
45
74
  end
46
75
 
47
76
  And here is an example rack config, foo_app.ru:
48
77
 
49
- require 'foo_app'
78
+ require '/path/to/foo_app.rb'
50
79
  run FooApp.new.as_rack_app
51
80
 
52
81
  Run FooApp w/ rackup or shotgun:
@@ -61,12 +90,11 @@ Run FooApp w/ rackup or shotgun:
61
90
 
62
91
  When a Synfeld application handles a rack request, it
63
92
 
64
- 1. Duplicates self (so it's thread safe)
65
- 2. Sets @response, @params, @env (the rack env)
93
+ 1. Duplicates self (so it's thread safe)
94
+ 2. Sets @response, @params, @env (the rack env)
66
95
  3. Calls the action that Rack::Router route that matched. If the action returns a String, that is used for the @response[:body]
67
96
 
68
- The @response is a hash used to return rack status code, headers hash, and body. Actions may do what they please with
69
- the response. Default response:
97
+ 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:
70
98
 
71
99
  @response = {
72
100
  :status_code => 200,
@@ -75,11 +103,23 @@ the response. Default response:
75
103
  }
76
104
 
77
105
 
78
- Actions are expected to side-effect the :status_code, :headers, and :body. As a convenience, if an action returns a
79
- string, it is assumed that that string is the :body. An exception is thrown if the :body is not set to something.
106
+ 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 the :body. An exception is thrown if the :body is not set to something.
107
+
108
+ As the example app above shows, you can "serve" templated content in the form of 'haml' or 'erb' files.
109
+
110
+ Requests are bound to the first matching route. The 'handle_static' action considers the request path to be a path to a file relative to the 'root_dir' specified in initialize (see example app below).
111
+
112
+ Can currenty serve up the following types of static files:
80
113
 
81
- That's it. Really not much to see here. Just gives you a thread-safe rack-based web framework that consists of
82
- nothing but a router.
114
+ js, css, png, gif, jpg, jpeg, html
115
+
116
+ Can currently render the following dynamic content:
117
+
118
+ erb, haml
119
+
120
+ Synfeld does not do partials, but you can set local variables for dynamic content.
121
+
122
+ That's it. Really not much to see here. Just gives you a thread-safe rack-based web framework that consists of little more than a router.
83
123
 
84
124
  == PROBLEMS
85
125
 
@@ -87,18 +127,19 @@ None known.
87
127
 
88
128
  == REQUIREMENTS:
89
129
 
90
- * rack
91
- * Rack::Router (the rack-router gem), see http://github.com/carllerche/rack-router
130
+ * ruby, rubygems, rack, rack-router
131
+ * For rack-router, see http://github.com/carllerche/rack-router
92
132
 
93
133
  == INSTALL:
94
134
 
95
- * first install rack and rack-router
96
- * gem install synfeld
97
-
98
- == Acknowledgements:
135
+ First install rack and rack-router.
136
+
137
+ There's no gem for rack-router at the moment,
138
+ to you will have to clone it and build it yourself.
139
+
140
+ Then:
99
141
 
100
- rack and rack-router were used, obviously.
101
- 'bones' used for gem generation.
142
+ gem install swerling-synfeld --source http://gems.github.com
102
143
 
103
144
  == LICENSE:
104
145
 
data/Rakefile CHANGED
@@ -30,16 +30,37 @@ PROJ.rdoc.exclude = ["^tasks/setup\.rb$", "lib/synfeld_info.rb"]
30
30
 
31
31
  PROJ.spec.opts << '--color'
32
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
+
33
40
  task :default => 'spec:run'
34
- namespace :my do
35
- namespace :gem do
36
- task :package => [:clobber] do
37
- this_dir = File.join(File.dirname(__FILE__))
38
- sh "rm -rf #{File.join(this_dir, 'pkg')}"
39
- sh "rm -rf #{File.join(this_dir, 'doc')}"
40
- sh "cp #{File.join(this_dir, 'README.txt')} #{File.join(this_dir, 'README.rdoc')} "
41
- Rake::Task['gem:package'].invoke
42
- end
43
- end
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
+ end
52
+ task :mypackage => [:myclobber] do
53
+ Rake::Task['gem:package'].invoke
54
+ end
55
+ task :mydoc => [:myclobber] do
56
+ FileUtils.rm_f doc_dir()
57
+ sh "cd #{this_dir()} && rdoc -o rdoc --inline-source --format=html -T hanna README.rdoc lib/**/*.rb"
58
+ end
59
+ task :taba => [:mydoc] do
60
+ this_dir = File.join(File.dirname(__FILE__))
61
+ FileUtils.rm_rf tab_a_doc_dir
62
+ FileUtils.cp_r doc_dir, tab_a_doc_dir
63
+ end
64
+ task :mygemspec => [:myclobber] do
65
+ Rake::Task['gem:spec'].invoke
44
66
  end
45
-
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ Try using USHER as the router
2
+ http://github.com/joshbuddy/usher/tree/master
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <body>
3
+ <div>
4
+ <h3> Here is an erb test</h3>
5
+ Here is the time: <%= time %>
6
+ <br/>ran100: <%= ran100 %>
7
+ <br/><a href="/">home</a>
8
+ </div>
9
+ </body>
10
+ </html>
@@ -0,0 +1,15 @@
1
+ %html
2
+ %body
3
+
4
+ %h1 This is: haml_test.haml.
5
+ %p
6
+ Random number is
7
+ %i= ran100.to_s
8
+ %p
9
+ Time is
10
+ %span=time.to_s
11
+
12
+ %p
13
+ %h3 Test render of haml file
14
+ %a{:href => 'http://www.github.com/swerling/synfeld'} synfeld on github
15
+
@@ -0,0 +1,15 @@
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 ('my_special_route')
15
+
@@ -0,0 +1,13 @@
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
+ </p>
10
+
11
+ </body>
12
+ </html>
13
+
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/synfeld.rb'))
2
+
3
+ class TryMe < Synfeld::App
4
+
5
+ def initialize
6
+ super(:root_dir => File.expand_path(File.join(File.dirname(__FILE__), 'public')),
7
+ :logger => Logger.new(STDOUT))
8
+ end
9
+
10
+ def router
11
+ return @router ||= Rack::Router.new(nil, {}) do |r|
12
+ r.map "/yap/:yap_variable", :get, :to => self, :with => { :action => "yap" }
13
+ r.map "/my/special/route", :get, :to => self, :with => { :action => "my_special_route" }
14
+ r.map "/html_test", :get, :to => self, :with => { :action => "html_test" }
15
+ r.map "/haml_test", :get, :to => self, :with => { :action => "haml_test" }
16
+ r.map "/erb_test", :get, :to => self, :with => { :action => "erb_test" }
17
+
18
+ # These next 2 have to come last
19
+ r.map "/:anything_else", :get, :to => self, :with => { :action => "handle_static" }
20
+ r.map "/", :get, :to => self, :with => { :action => "home" }
21
+ end
22
+ end
23
+
24
+ # files are looked up relative to the root directory specified in initialize
25
+ def home
26
+ serve('haml_files/home.haml')
27
+ end
28
+
29
+ def my_special_route
30
+ self.response[:status_code] = 200
31
+ self.response[:headers]['Content-Type'] = 'text/html'
32
+ self.response[:body] = <<-HTML
33
+ <html>
34
+ <body>I'm <i>special</i>.</body>
35
+ </html>
36
+ HTML
37
+ end
38
+
39
+ def yap
40
+ "yap, #{self.params[:yap_variable]}"
41
+ end
42
+
43
+ def html_test
44
+ serve('html_files/html_test.html')
45
+ end
46
+
47
+ def haml_test
48
+ serve('haml_files/haml_test.haml', {:ran100 => Kernel.rand(100) + 1, :time => Time.now})
49
+ end
50
+
51
+ def erb_test
52
+ serve('erb_files/erb_test.erb', {:ran100 => Kernel.rand(100) + 1, :time => Time.now})
53
+ end
54
+
55
+
56
+ end
57
+
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__),'try_me.rb')
2
+ run TryMe.new.as_rack_app
@@ -3,10 +3,11 @@ require 'logger'
3
3
 
4
4
  # gems dependencies
5
5
  require 'rubygems'
6
+
6
7
  require 'rack'
7
8
  require 'rack/router'
8
9
 
9
10
  # my files (require_all_libs_relative_to is a bones util method in synfeld_info.rb)
10
- require 'synfeld_info'
11
+ require File.join(File.dirname(__FILE__), 'synfeld_info')
11
12
  Synfeld.require_all_libs_relative_to(__FILE__)
12
13
 
@@ -19,7 +19,7 @@ module Synfeld
19
19
  # The params that the matching Rack::Router route set.
20
20
  #
21
21
  class App
22
- attr_accessor :response, :params, :env, :logger
22
+ attr_accessor :response, :params, :env, :root_dir, :logger
23
23
 
24
24
  # Options:
25
25
  # :logger => where to log to.
@@ -27,6 +27,9 @@ module Synfeld
27
27
  # can pass that logger in if you want). Default: Logger.new(STDOUT)
28
28
  def initialize(opts = {})
29
29
  @logger = opts[:logger] || Logger.new(STDOUT)
30
+ @root_dir = opts[:root_dir]
31
+ raise "You have to pass in the location of the 'root_dir', where all the files in your synfeld app are located" if self.root_dir.nil?
32
+ #Haml::Template.options[:format] = :html5
30
33
  end
31
34
 
32
35
  # the router for this Synfeld::App. Subclasses are _required_ to override this.
@@ -36,7 +39,10 @@ module Synfeld
36
39
  end
37
40
 
38
41
  # Alias for #router
39
- def as_rack_app; self.router; end # alias_method doesn't seem to work here (it doesnt call the subclass)
42
+ def as_rack_app
43
+ self.router
44
+ # TODO: add the no_route handler here. But waiting for rack-router to settle this issue.
45
+ end
40
46
 
41
47
  # The rack #call method
42
48
  def call(env)
@@ -87,9 +93,105 @@ module Synfeld
87
93
  [response[:status_code], response[:headers], response[:body]]
88
94
  end
89
95
 
96
+ # send an error message to the log prepended by "Synfeld: "
97
+ def whine msg
98
+ logger.error("Synfeld laments: " + msg)
99
+ return msg
100
+ end
101
+
102
+
90
103
  # :startdoc:
91
- end
92
- end
104
+
105
+ def serve(fn, local = {})
106
+ full_fn = fn
107
+ full_fn = File.join(self.root_dir, fn) unless File.exist?(full_fn)
108
+ if File.exist?(full_fn)
109
+ ext = fn.split('.').last.downcase
110
+
111
+ self.content_type!(ext)
112
+
113
+ case ext
114
+ when 'html'; return serve_html(full_fn)
115
+ when 'haml'; return serve_haml(full_fn, local)
116
+ when 'erb'; return serve_erb(full_fn, local)
117
+ else raise "Unrecognized file type: '#{ext}'";
118
+ end
119
+ else
120
+ raise "Could not find file '#{fn}' (full path '#{full_fn}')"
121
+ end
122
+
123
+ end
124
+
125
+ def serve_html(fn)
126
+ File.read(fn)
127
+ end
128
+
129
+ def serve_haml(fn, locals = {})
130
+
131
+ if not defined? Haml
132
+ begin
133
+ require 'haml'
134
+ rescue LoadError => x
135
+ return self.whine("Haml is not installed, required in order to render '#{fn}'")
136
+ end
137
+ end
138
+
139
+ Haml::Engine.new(File.read(fn) ).render(Object.new, locals)
140
+ end
141
+
142
+ def serve_erb(fn, locals = {})
143
+
144
+ if not defined? Erb
145
+ begin
146
+ require 'erb'
147
+ rescue LoadError => x
148
+ return self.whine("Erb is not installed, required in order to render '#{fn}'")
149
+ end
150
+ end
151
+
152
+ template = ERB.new File.read(fn)
153
+
154
+ bind = binding
155
+ locals.each do |n,v|
156
+ raise "Locals must be symbols. Not a symbol: #{n.inspect}" unless n.is_a?(Symbol)
157
+ eval("#{n} = locals[:#{n}]", bind)
158
+ end
159
+ template.result(bind)
160
+ end
161
+
162
+ def handle_static
163
+ fn = File.expand_path(File.join(root_dir, self.env['REQUEST_URI']))
164
+ #puts fn # dbg
165
+ if File.exist?(fn) and not File.directory?(fn)
166
+ self.content_type!(fn.split('.').last)
167
+ File.read(fn)
168
+ else
169
+ return self.no_route
170
+ end
171
+ end
172
+
173
+ def content_type!(ext)
174
+ case ext.downcase
175
+ when 'html'; t = 'text/html'
176
+ when 'haml'; t = 'text/html'
177
+ when 'js'; t = 'text/javascript'
178
+ when 'css'; t = 'text/css'
179
+ when 'png'; t = 'image/png'
180
+ when 'gif'; t = 'image/gif'
181
+ when 'jpg'; t = 'image/jpeg'
182
+ when 'jpeg'; t = 'image/jpeg'
183
+ end
184
+ (self.response[:headers]['Content-Type'] = t) if t
185
+ end
186
+
187
+ def no_route
188
+ self.response[:body] = "route not found for: '#{self.env['REQUEST_URI']}'"
189
+ self.response[:status_code] = 404
190
+ end
191
+
192
+ end # class App
193
+
194
+ end # mod Synfeld
93
195
 
94
196
 
95
197
 
@@ -5,7 +5,7 @@ module Synfeld
5
5
 
6
6
  # :stopdoc:
7
7
 
8
- VERSION = '0.0.1'
8
+ VERSION = '0.0.2'
9
9
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
10
10
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
11
11
 
@@ -1,27 +1,29 @@
1
1
  # -*- encoding: utf-8 -*-
2
- #
3
2
 
4
3
  Gem::Specification.new do |s|
5
4
  s.name = %q{synfeld}
6
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
7
6
 
8
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
8
  s.authors = ["Steven Swerling"]
10
- s.date = %q{2009-07-18}
11
- s.description = %q{Synfeld is an application framework that does almost nothing, and it ain't all that classy.
9
+ s.date = %q{2009-08-29}
10
+ s.description = %q{Synfeld is a web application framework that does practically nothing.
12
11
 
13
- Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router)
12
+ Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router). If you want a web framework that is mostly just going to serve up json blobs, and occasionally serve up some simple content (eg. for help files) and media, Synfeld makes that easy. If you need session variables, a mailer, uploading, etc, look elsewhere.
13
+
14
+ The sample app below shows pretty much everything that synfeld can do.
14
15
 
15
16
  Very alpha-ish stuff here. Seems to work though.}
16
17
  s.email = %q{sswerling@yahoo.com}
17
- s.extra_rdoc_files = ["History.txt", "README.txt"]
18
- s.files = [".gitignore", "History.txt", "README.txt", "Rakefile", "example/foo_app.rb", "example/foo_app.ru", "lib/synfeld.rb", "lib/synfeld/base.rb", "lib/synfeld_info.rb", "spec/spec_helper.rb", "spec/synfeld_spec.rb", "synfeld.gemspec", "test/test_synfeld.rb"]
18
+ s.extra_rdoc_files = ["History.txt", "README.rdoc", "README.txt"]
19
+ s.files = [".gitignore", "History.txt", "README.rdoc", "README.txt", "Rakefile", "TODO", "example/public/erb_files/erb_test.erb", "example/public/haml_files/haml_test.haml", "example/public/haml_files/home.haml", "example/public/html_files/html_test.html", "example/try_me.rb", "example/try_me.ru", "lib/synfeld.rb", "lib/synfeld/base.rb", "lib/synfeld_info.rb", "spec/spec_helper.rb", "spec/synfeld_spec.rb", "synfeld.gemspec", "test/test_synfeld.rb"]
20
+ s.has_rdoc = true
19
21
  s.homepage = %q{http://tab-a.slot-z.net}
20
22
  s.rdoc_options = ["--inline-source", "--main", "README.txt"]
21
23
  s.require_paths = ["lib"]
22
24
  s.rubyforge_project = %q{synfeld}
23
- s.rubygems_version = %q{1.3.3}
24
- s.summary = %q{Synfeld is an application framework that does almost nothing, and it ain't all that classy}
25
+ s.rubygems_version = %q{1.3.2}
26
+ s.summary = %q{Synfeld is a web application framework that does practically nothing}
25
27
  s.test_files = ["test/test_synfeld.rb"]
26
28
 
27
29
  if s.respond_to? :specification_version then
@@ -31,15 +33,15 @@ Very alpha-ish stuff here. Seems to work though.}
31
33
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
32
34
  s.add_runtime_dependency(%q<rack>, [">= 0"])
33
35
  s.add_runtime_dependency(%q<rack-router>, [">= 0"])
34
- s.add_development_dependency(%q<bones>, [">= 2.4.0"])
36
+ s.add_development_dependency(%q<bones>, [">= 2.5.1"])
35
37
  else
36
38
  s.add_dependency(%q<rack>, [">= 0"])
37
39
  s.add_dependency(%q<rack-router>, [">= 0"])
38
- s.add_dependency(%q<bones>, [">= 2.4.0"])
40
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
39
41
  end
40
42
  else
41
43
  s.add_dependency(%q<rack>, [">= 0"])
42
44
  s.add_dependency(%q<rack-router>, [">= 0"])
43
- s.add_dependency(%q<bones>, [">= 2.4.0"])
45
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
44
46
  end
45
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swerling-synfeld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Swerling
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-18 00:00:00 -07:00
12
+ date: 2009-08-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,9 +40,9 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 2.4.0
43
+ version: 2.5.1
44
44
  version:
45
- description: Synfeld is an application framework that does almost nothing, and it ain't all that classy. Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router) Very alpha-ish stuff here. Seems to work though.
45
+ description: Synfeld is a web application framework that does practically nothing. Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router). If you want a web framework that is mostly just going to serve up json blobs, and occasionally serve up some simple content (eg. for help files) and media, Synfeld makes that easy. If you need session variables, a mailer, uploading, etc, look elsewhere. The sample app below shows pretty much everything that synfeld can do. Very alpha-ish stuff here. Seems to work though.
46
46
  email: sswerling@yahoo.com
47
47
  executables: []
48
48
 
@@ -50,14 +50,21 @@ extensions: []
50
50
 
51
51
  extra_rdoc_files:
52
52
  - History.txt
53
+ - README.rdoc
53
54
  - README.txt
54
55
  files:
55
56
  - .gitignore
56
57
  - History.txt
58
+ - README.rdoc
57
59
  - README.txt
58
60
  - Rakefile
59
- - example/foo_app.rb
60
- - example/foo_app.ru
61
+ - TODO
62
+ - example/public/erb_files/erb_test.erb
63
+ - example/public/haml_files/haml_test.haml
64
+ - example/public/haml_files/home.haml
65
+ - example/public/html_files/html_test.html
66
+ - example/try_me.rb
67
+ - example/try_me.ru
61
68
  - lib/synfeld.rb
62
69
  - lib/synfeld/base.rb
63
70
  - lib/synfeld_info.rb
@@ -65,7 +72,7 @@ files:
65
72
  - spec/synfeld_spec.rb
66
73
  - synfeld.gemspec
67
74
  - test/test_synfeld.rb
68
- has_rdoc: false
75
+ has_rdoc: true
69
76
  homepage: http://tab-a.slot-z.net
70
77
  post_install_message:
71
78
  rdoc_options:
@@ -92,6 +99,6 @@ rubyforge_project: synfeld
92
99
  rubygems_version: 1.2.0
93
100
  signing_key:
94
101
  specification_version: 3
95
- summary: Synfeld is an application framework that does almost nothing, and it ain't all that classy
102
+ summary: Synfeld is a web application framework that does practically nothing
96
103
  test_files:
97
104
  - test/test_synfeld.rb
@@ -1,30 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'../lib/synfeld.rb')
2
-
3
- #
4
- # Example synfeld application
5
- #
6
- class FooApp < Synfeld::App
7
-
8
- def router
9
- return @router ||= Rack::Router.new(nil, {}) do |r|
10
- r.map "/yip/", :get, :to => self, :with => { :action => "yip" }
11
- r.map "/yap/:yap_variable", :get, :to => self, :with => { :action => "yapfoo" }
12
- r.map "/yap/", :get, :to => self, :with => { :action => "yap" }
13
- r.map "/:anything", :get, :to => self, :with => { :action => "no_route" }
14
- r.map "/", :get, :to => self, :with => { :action => "home" }
15
- end
16
- end
17
-
18
- def yip; "yip"; end
19
- def yap; "yap"; end
20
- def home; "home"; end
21
-
22
- def no_route
23
- self.response[:body] = "route not found for: '#{self.env['REQUEST_URI']}'"
24
- self.response[:status_code] = 404
25
- end
26
-
27
- def yapfoo
28
- "yapfoo, #{self.params[:yap_variable]}"
29
- end
30
- end
@@ -1,2 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'foo_app.rb')
2
- run FooApp.new.as_rack_app