serve 0.11.2 → 0.11.3

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.
@@ -1,5 +1,9 @@
1
1
  = Change Log
2
2
 
3
+ == 0.11.3 (May 26, 2010)
4
+
5
+ * Check for config.ru and use the `rackup` command instead if present.
6
+
3
7
  == 0.11.2 (May 25, 2010)
4
8
 
5
9
  * Add dependency on Rack to gemspec [jlong]
@@ -1,56 +1,136 @@
1
- = Serve
1
+ = Serve - A Rapid Prototyping Framework for Web Applications
2
2
 
3
- Serve is a small web server (based on WEBrick) that makes it easy to serve
4
- HTML, ERB, or HAML from any directory.
3
+ Serve is a small Rack-based web server that makes it easy to serve HTML, ERB, or HAML from any directory.
5
4
 
6
- Serve is an ideal tool for building HTML prototypes of Rails applications. One
7
- of the advantages of developing an HTML prototype is the opportunity to
8
- explore the flow of an application before developing the backend. The “Design
9
- First” approach also allows for substantial problem solving in the design
10
- phase and the ability to estimate features with accuracy. When views are
11
- ready, they can be copied over from the HTML prototype to the application
12
- almost as is. This process is eased since Serve has full support for partials
13
- and layouts with either ERB or HAML.
5
+ But Serve is much more than a simple web server.
14
6
 
15
- Serve can also handle SASS, Textile, and Markdown if the appropriate gems are
16
- installed.
7
+ Serve's primary purpose is to provide a rapid prototyping framework for Web
8
+ applications (specifically Rails apps). It is designed to compliment web
9
+ application development and enforce a strict separation of concerns between
10
+ designer and developer. Using Serve allows the designer to work in a separate
11
+ prototype project, while the developer can work on the actual application and
12
+ utilize resources from the prototype as needed. This allows the designer to
13
+ focus on presentation and flow, while the developer can focus on
14
+ implementation.
15
+
16
+ This "Design First" approach can help a designer identify and fix a large
17
+ number of problems before a feature is ever touched by the developer. Once a
18
+ feature has been completed in the prototype project it can also be estimated
19
+ with a high degree of accuracy.
20
+
21
+ A Serve prototype can work much like the finished application and be virtually
22
+ indistinguishable. The only difference being that state is not saved as a user
23
+ clicks around.
24
+
25
+ Serve can be used alongside any Web development framework, but Rails
26
+ developers will find it especially familiar. One way of thinking about Serve
27
+ is that it is essentially a Rails application with only one part of the Rails
28
+ MVC stack -- the views. Serve basically allows you to have a separate project
29
+ just for designing the views for the application. When views are ready, they
30
+ can be copied over from the prototype to the application almost as is. This
31
+ process is eased since Serve has full support for partials and layouts with
32
+ either ERB or HAML. Serve can also handle SASS, Textile, and Markdown if the
33
+ appropriate libraries are installed.
34
+
35
+
36
+ == Installation
37
+
38
+ Serve is distributed as a Ruby gem and can be installed from the command prompt. Just type:
39
+
40
+ gem install serve
41
+
42
+ Some systems, like the Mac, may require that you type:
43
+
44
+ sudo gem install serve
45
+
46
+ If you are new to the command prompt see:
47
+
48
+ http://kb.iu.edu/data/amog.html
49
+
50
+ You may also want to google "command prompt windows" if you are on a PC or
51
+ "command prompt osx" if you are on a Mac to find a simple tutorial.
17
52
 
18
53
 
19
54
  == Usage
20
55
 
21
- At a command prompt all you need to type to start serve is:
56
+ Once the gem is installed the `serve` command will be available from the command prompt. To launch Serve, just type the command and press enter:
22
57
 
23
- $ serve
58
+ serve
24
59
 
25
- This will launch a WEBrick server which you can access from any Web browser at
26
- the following address:
60
+ This will launch a simple web server which you can access from any web browser
61
+ at the following address:
27
62
 
28
63
  http://localhost:4000
29
64
 
30
65
  Once the server is going it will output a running log of its activity. To
31
66
  stop the server at any time, type CTRL+C at the command prompt. By default the
32
67
  serve command serves up files from the current directory. To change this
33
- behavior, `cd` to the appropriate directory before starting serve.
34
-
68
+ behavior, `cd` to the appropriate directory before starting serve or pass the directory as the final parameter to the command:
35
69
 
36
- == Advanced Options
70
+ serve project_directory
37
71
 
38
- The serve command automatically binds to 0.0.0.0 (localhost) and uses port
72
+ The `serve` command automatically binds to 0.0.0.0 (localhost) and uses port
39
73
  4000 by default. To serve files over a different IP (that is bound to your
40
74
  computer) or port specify those options on the command line:
41
75
 
42
- $ serve 4000 # a custom port
43
-
44
- $ serve 192.168.1.6 # a custom IP
45
-
46
- $ serve 192.168.1.6:4000 # a custom IP and port
76
+ serve 4000 # a custom port
77
+
78
+ serve 192.168.1.6 # a custom IP
79
+
80
+ serve 192.168.1.6:4000 # a custom IP and port
47
81
 
48
82
  For your convenience if the file "script/server" exists in the current
49
83
  directory the serve command will start that instead of launching a WEBrick
50
- server. You can specify the environment that you want to start the server
51
- with as an option on the command line:
52
-
53
- $ serve production # start script/server in production mode
84
+ server. You can specify the environment that you want to start the server with
85
+ as an option on the command line:
86
+
87
+ serve production # start script/server in production mode
88
+
89
+
90
+ == Rack and Passenger
91
+
92
+ Advanced users may also want to run Serve as a Rack application. To do this
93
+ you will need to create a "config.ru" file in the root of your Serve project.
94
+ Here is an example "config.ru" file:
95
+
96
+ #\ -p 4000
97
+
98
+ gem 'activesupport', '2.3.5'
99
+ gem 'serve'
100
+
101
+ require 'serve'
102
+ require 'serve/rack'
103
+
104
+ # Middleware
105
+ use Rack::ShowStatus # Nice looking 404s and other messages
106
+ use Rack::ShowExceptions # Nice looking errors
107
+
108
+ # The project root directory
109
+ root = File.dirname(__FILE__)
110
+
111
+ # Rack Application
112
+ run Rack::Cascade.new([
113
+ Serve::RackAdapter.new(root), # Handle ERB, HAML, and other Serve files
114
+ Rack::Directory.new(root) # Directory listings and everything else
115
+ ])
116
+
117
+ Assuming that you have Rack installed, you will then be able to start your
118
+ application with the `rackup` command. Type `rackup --help` for more
119
+ information.
120
+
121
+ If you would like to run Serve as a Rack application with Passenger you will
122
+ need to create two additional directories: "tmp" and "public". In the temp
123
+ directory put an empty "restart.txt" file. In the public directory put your
124
+ static assets like images and javascripts (anything that does not require
125
+ special processing by Serve). You may also want to replace the last four lines of "config.ru" with a single reference to the Serve::RackAdapter:
126
+
127
+ run Serve::RackAdapter.new(root)
128
+
129
+ By default, Passenger applications serve static assets from the "public"
130
+ directory so there is no need to use the Rack::Directory application to handle
131
+ those. If you need directory listings your Web server probably provides
132
+ something specifically for this purpose and there is no need to rely on Rack
133
+ for this.
54
134
 
55
135
 
56
136
  == File Types
@@ -69,9 +149,9 @@ redirect :: Redirects to the URL contained in the document
69
149
 
70
150
  == View Helpers
71
151
 
72
- If you drop a file called view_helpers.rb in the root of a project, you can
73
- define custom helpers for your Haml and ERB views. Just declare the
74
- ViewHelpers module and begin declaring your helpers:
152
+ If you drop a file called "view_helpers.rb" in the root of a project, you can
153
+ define custom helpers for your Haml and ERB views. Just create a ViewHelpers
154
+ module and define your helper methods there:
75
155
 
76
156
  module ViewHelpers
77
157
  def custom_method
@@ -79,23 +159,23 @@ ViewHelpers module and begin declaring your helpers:
79
159
  end
80
160
  end
81
161
 
162
+ Helpers have full access to the request and response objects so you can
82
163
 
83
- == Installation and Setup
84
-
85
- It is recommended that you install serve via RubyGems:
86
164
 
87
- $ sudo gem install serve
165
+ == More Information
88
166
 
167
+ You can find more information about Serve, including a detailed Screencast, on
168
+ the GitHub wiki:
89
169
 
90
- == More Information
170
+ http://wiki.github.com/jlong/serve
91
171
 
92
- For more information, be sure to look through the documentation over on the wiki: http://wiki.github.com/jlong/serve
172
+ All development takes place on GitHub:
93
173
 
94
- All development takes place on GitHub: http://github.com/jlong/serve
174
+ http://github.com/jlong/serve
95
175
 
96
176
 
97
177
  == License
98
178
 
99
179
  Serve is released under the MIT license and is copyright (c) 2007-2010
100
- John W. Long and Adam I. Williams. A copy of the MIT license can be found in
180
+ John W. Long and Adam I. Williams. A copy of the MIT license can be found in
101
181
  the LICENSE file.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.2
1
+ 0.11.3
@@ -24,8 +24,11 @@ module Serve
24
24
  puts help
25
25
  else
26
26
  Dir.chdir(options[:root])
27
- if rails_app?
27
+ case
28
+ when rails_app?
28
29
  run_rails_app
30
+ when rack_app?
31
+ run_rack_app
29
32
  else
30
33
  run_server
31
34
  end
@@ -76,9 +79,14 @@ module Serve
76
79
  " textile, and markdown file extensions.",
77
80
  " ",
78
81
  " If the Rails command script/server exists in the current directory the ",
79
- " script will start that instead with the specified environment or the ",
80
- " development environment if none is specified. Rails apps are started by ",
81
- " default on port 3000.",
82
+ " script will start that instead.",
83
+ " ",
84
+ " If a Rack configuration file (config.ru) exists in the current directory the ",
85
+ " script will start that using the rackup command.",
86
+ " ",
87
+ " A Rails or Rack app will start with the environment specified or the ",
88
+ " development environment if none is specified. Rails and Rack apps are ",
89
+ " started by default on port 3000.",
82
90
  " ",
83
91
  "Options:",
84
92
  " -h, --help Show this message and quit.",
@@ -105,7 +113,7 @@ module Serve
105
113
  end
106
114
 
107
115
  def extract_port(args)
108
- (args.delete(args.find {|a| /^\d\d\d*$/.match(a) }) || (rails_app? ? 3000 : 4000)).to_i
116
+ (args.delete(args.find {|a| /^\d\d\d*$/.match(a) }) || ((rails_app? or rack_app?) ? 3000 : 4000)).to_i
109
117
  end
110
118
 
111
119
  def extract_address(args)
@@ -134,6 +142,18 @@ module Serve
134
142
  system "#{rails_script_server} -p #{options[:port]} -b #{options[:address]} -e #{options[:environment]}"
135
143
  end
136
144
 
145
+ def rack_config
146
+ @rack_config ||= options[:root] + '/config.ru'
147
+ end
148
+
149
+ def rack_app?
150
+ File.file?(rack_config)
151
+ end
152
+
153
+ def run_rack_app
154
+ system "rackup -p #{options[:port]} -o #{options[:address]} -E #{options[:environment]} #{rack_config}"
155
+ end
156
+
137
157
  def run_server
138
158
  root = options[:root]
139
159
  app = Rack::Builder.new do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serve
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 11
9
- - 2
10
- version: 0.11.2
9
+ - 3
10
+ version: 0.11.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - John W. Long
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-05-25 00:00:00 -04:00
19
+ date: 2010-05-26 00:00:00 -04:00
20
20
  default_executable: serve
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency