serve 0.11.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +12 -0
- data/Gemfile +15 -10
- data/Gemfile.lock +30 -16
- data/LICENSE +2 -1
- data/README.rdoc +78 -47
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/lib/serve/application.rb +95 -12
- data/lib/serve/javascripts.rb +62 -0
- data/lib/serve/out.rb +38 -0
- data/lib/serve/project.rb +176 -0
- data/lib/serve/templates/LICENSE +20 -0
- data/lib/serve/templates/README.markdown +46 -0
- data/lib/serve/templates/_layout.html.erb +11 -0
- data/lib/serve/templates/application.sass +12 -0
- data/lib/serve/templates/compass.config +28 -0
- data/lib/serve/templates/config.ru +35 -0
- data/lib/serve/templates/gitignore +24 -0
- data/lib/serve/templates/hello.html.erb +3 -0
- data/lib/serve/templates/index.redirect +1 -0
- data/lib/serve/templates/view_helpers.rb +5 -0
- data/spec/application_spec.rb +36 -7
- data/spec/project_spec.rb +107 -0
- data/spec/spec_helper.rb +1 -6
- metadata +64 -17
- data/spec/spec.opts +0 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
= Change Log
|
2
2
|
|
3
|
+
== 1.0.0 (November 3, 2010)
|
4
|
+
|
5
|
+
* Various tweaks and fixes [jlong]
|
6
|
+
* Added `serve convert` command for converting Compass projects. [revans]
|
7
|
+
* Added `serve create` command for bootstrapping projects. See README for details. Yay! [revans]
|
8
|
+
* Added option to use Thin if Mongrel isn't installed [benatkin]
|
9
|
+
|
10
|
+
== 0.11.7 (July 22, 2010)
|
11
|
+
|
12
|
+
* Use latest version of Rack
|
13
|
+
* Use Mongrel instead of Webrick by default
|
14
|
+
|
3
15
|
== 0.11.6 (June 13, 2010)
|
4
16
|
|
5
17
|
* Support for activesupport 3.x [railsjedi]
|
data/Gemfile
CHANGED
@@ -1,14 +1,19 @@
|
|
1
|
-
source "http://
|
1
|
+
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem
|
4
|
-
gem
|
5
|
-
gem "rspec", "1.3.0"
|
6
|
-
gem "rack", "1.1.0"
|
3
|
+
gem 'rake', '~> 0.8.7'
|
4
|
+
gem 'rack', '~> 1.2.1'
|
7
5
|
|
8
6
|
# activesupport 2.x
|
9
|
-
# gem
|
7
|
+
# gem 'activesupport', '2.3.5'
|
10
8
|
|
11
|
-
# activesupport 3.x
|
12
|
-
gem
|
13
|
-
gem
|
14
|
-
gem
|
9
|
+
# activesupport 3.0.x
|
10
|
+
gem 'activesupport', '~> 3.0.1'
|
11
|
+
gem 'tzinfo', '~> 0.3.23'
|
12
|
+
gem 'i18n', '~> 0.4.2'
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem 'jeweler', '~> 1.4.0'
|
16
|
+
gem 'haml', '~> 3.0.23'
|
17
|
+
gem 'compass', '~> 0.10.6'
|
18
|
+
gem 'rspec', '~> 2.0.1'
|
19
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,45 @@
|
|
1
1
|
GEM
|
2
|
-
remote: http://
|
2
|
+
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (3.0.
|
5
|
-
|
6
|
-
|
4
|
+
activesupport (3.0.1)
|
5
|
+
compass (0.10.6)
|
6
|
+
haml (>= 3.0.4)
|
7
|
+
diff-lcs (1.1.2)
|
8
|
+
gemcutter (0.6.1)
|
7
9
|
git (1.2.5)
|
8
|
-
|
10
|
+
haml (3.0.23)
|
11
|
+
i18n (0.4.2)
|
9
12
|
jeweler (1.4.0)
|
10
13
|
gemcutter (>= 0.1.0)
|
11
14
|
git (>= 1.2.5)
|
12
15
|
rubyforge (>= 2.0.0)
|
13
|
-
json_pure (1.4.
|
14
|
-
rack (1.1
|
16
|
+
json_pure (1.4.6)
|
17
|
+
rack (1.2.1)
|
15
18
|
rake (0.8.7)
|
16
|
-
rspec (
|
19
|
+
rspec (2.0.1)
|
20
|
+
rspec-core (~> 2.0.1)
|
21
|
+
rspec-expectations (~> 2.0.1)
|
22
|
+
rspec-mocks (~> 2.0.1)
|
23
|
+
rspec-core (2.0.1)
|
24
|
+
rspec-expectations (2.0.1)
|
25
|
+
diff-lcs (>= 1.1.2)
|
26
|
+
rspec-mocks (2.0.1)
|
27
|
+
rspec-core (~> 2.0.1)
|
28
|
+
rspec-expectations (~> 2.0.1)
|
17
29
|
rubyforge (2.0.4)
|
18
30
|
json_pure (>= 1.1.7)
|
19
|
-
tzinfo (0.3.
|
31
|
+
tzinfo (0.3.23)
|
20
32
|
|
21
33
|
PLATFORMS
|
22
34
|
ruby
|
23
35
|
|
24
36
|
DEPENDENCIES
|
25
|
-
activesupport (
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
activesupport (~> 3.0.1)
|
38
|
+
compass (~> 0.10.6)
|
39
|
+
haml (~> 3.0.23)
|
40
|
+
i18n (~> 0.4.2)
|
41
|
+
jeweler (~> 1.4.0)
|
42
|
+
rack (~> 1.2.1)
|
43
|
+
rake (~> 0.8.7)
|
44
|
+
rspec (~> 2.0.1)
|
45
|
+
tzinfo (~> 0.3.23)
|
data/LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright (c) 2007-
|
1
|
+
Copyright (c) 2007-2010 John W. Long and Adam I. Williams
|
2
|
+
Portions contributed by Robert Evans and others
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
5
|
a copy of this software and associated documentation files (the
|
data/README.rdoc
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
= Serve - A Rapid Prototyping Framework for Web Applications
|
2
2
|
|
3
|
-
Serve is a small Rack-based web server that makes it easy to serve HTML, ERB,
|
3
|
+
Serve is a small Rack-based web server that makes it easy to serve HTML, ERB,
|
4
|
+
or HAML from any directory.
|
4
5
|
|
5
6
|
But Serve is much more than a simple web server.
|
6
7
|
|
@@ -35,7 +36,8 @@ appropriate libraries are installed.
|
|
35
36
|
|
36
37
|
== Installation
|
37
38
|
|
38
|
-
Serve is distributed as a Ruby gem and can be installed from the command
|
39
|
+
Serve is distributed as a Ruby gem and can be installed from the command
|
40
|
+
prompt. Just type:
|
39
41
|
|
40
42
|
gem install serve
|
41
43
|
|
@@ -53,7 +55,8 @@ You may also want to google "command prompt windows" if you are on a PC or
|
|
53
55
|
|
54
56
|
== Usage
|
55
57
|
|
56
|
-
Once the gem is installed the `serve` command will be available from the
|
58
|
+
Once the gem is installed the `serve` command will be available from the
|
59
|
+
command prompt. To launch Serve, just type the command and press enter:
|
57
60
|
|
58
61
|
serve
|
59
62
|
|
@@ -65,7 +68,8 @@ at the following address:
|
|
65
68
|
Once the server is going it will output a running log of its activity. To
|
66
69
|
stop the server at any time, type CTRL+C at the command prompt. By default the
|
67
70
|
serve command serves up files from the current directory. To change this
|
68
|
-
behavior, `cd` to the appropriate directory before starting serve or pass the
|
71
|
+
behavior, `cd` to the appropriate directory before starting serve or pass the
|
72
|
+
directory as the final parameter to the command:
|
69
73
|
|
70
74
|
serve project_directory
|
71
75
|
|
@@ -80,57 +84,83 @@ computer) or port specify those options on the command line:
|
|
80
84
|
serve 192.168.1.6:4000 # a custom IP and port
|
81
85
|
|
82
86
|
For your convenience if the file "script/server" exists in the current
|
83
|
-
directory the serve command will start that instead of launching a
|
87
|
+
directory the serve command will start that instead of launching a Ruby Web
|
84
88
|
server. You can specify the environment that you want to start the server with
|
85
89
|
as an option on the command line:
|
86
90
|
|
87
91
|
serve production # start script/server in production mode
|
88
92
|
|
89
93
|
|
90
|
-
==
|
94
|
+
== Creating a New Serve Project
|
91
95
|
|
92
|
-
|
93
|
-
|
94
|
-
|
96
|
+
For simple projects, you don't need to structure your files in a specific
|
97
|
+
way. All ERB, Haml, and Sass files will be processed wherever they are found
|
98
|
+
in the project root. But for more complex projects you may want to use Serve
|
99
|
+
with a `config.ru` file so that you can take advantage of other Rack
|
100
|
+
middleware and structure the project in a Rack compatible way.
|
95
101
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
102
|
+
To create a new Rack-based Serve project in the "mockups" directory, type the
|
103
|
+
following on the command line:
|
104
|
+
|
105
|
+
serve create mockups # create a new project in the mockups directory
|
106
|
+
|
107
|
+
This will create a new project with the following directory structure:
|
108
|
+
|
109
|
+
mockups/
|
110
|
+
|
|
111
|
+
+-- config.ru # Rack configuration file
|
112
|
+
|
|
113
|
+
+-- compass.config # Compass configuration file
|
114
|
+
|
|
115
|
+
+-- public/ # Directories for static assets
|
116
|
+
| |
|
117
|
+
| +-- stylesheets/ # Compiled stylesheets
|
118
|
+
| |
|
119
|
+
| +-- images/
|
120
|
+
| |
|
121
|
+
| `-- javascripts/
|
122
|
+
|
|
123
|
+
+-- sass/ # Store Sass source files here
|
124
|
+
| |
|
125
|
+
| `-- application.sass # Example Sass file for application
|
126
|
+
|
|
127
|
+
+-- tmp/ # Needed for Passenger (mod_passenger)
|
128
|
+
| |
|
129
|
+
| `-- restart.txt
|
130
|
+
|
|
131
|
+
`-- views/ # Store your ERB, Haml, etc. here
|
132
|
+
|
|
133
|
+
+-- _layout.html.erb # Example layout
|
134
|
+
|
|
135
|
+
+-- hello.html.erb # Example view
|
136
|
+
|
|
137
|
+
`-- view_helpers.rb # Example view helpers
|
138
|
+
|
139
|
+
If you would like to generate the project with a specific JavaScript framework
|
140
|
+
you can do so with the <tt>-j</tt> flag:
|
141
|
+
|
142
|
+
serve create mockups -j prototype
|
143
|
+
|
144
|
+
Available frameworks are: <tt>jquery</tt>, <tt>jquery-ui</tt>,
|
145
|
+
<tt>mootools</tt>, <tt>prototype</tt>, and <tt>scriptaculous</tt>.
|
146
|
+
|
147
|
+
The `serve create` command can be executed multiple times or on an existing
|
148
|
+
project without negative consequences.
|
149
|
+
|
150
|
+
|
151
|
+
== Upgrading a Compass Project to a Serve Project
|
116
152
|
|
117
|
-
|
118
|
-
|
119
|
-
information.
|
153
|
+
If you are a Compass user you can convert an existing Compass project to a
|
154
|
+
Serve project with the "convert" sub-command:
|
120
155
|
|
121
|
-
|
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:
|
156
|
+
serve convert mockups
|
126
157
|
|
127
|
-
|
158
|
+
This will rename and move a number of files for you and will turn your Compass
|
159
|
+
project into a Serve project.
|
128
160
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
something specifically for this purpose and there is no need to rely on Rack
|
133
|
-
for this.
|
161
|
+
Note that after upgrading a Compass project, you will no longer need to use
|
162
|
+
the `compass watch` command to generate your stylesheets. Your stylesheets
|
163
|
+
will be compiled on the fly with Serve.
|
134
164
|
|
135
165
|
|
136
166
|
== File Types
|
@@ -149,7 +179,7 @@ redirect :: Redirects to the URL contained in the document
|
|
149
179
|
|
150
180
|
== View Helpers
|
151
181
|
|
152
|
-
If you drop a file called "view_helpers.rb" in
|
182
|
+
If you drop a file called "view_helpers.rb" in your views directory, you can
|
153
183
|
define custom helpers for your Haml and ERB views. Just create a ViewHelpers
|
154
184
|
module and define your helper methods there:
|
155
185
|
|
@@ -159,7 +189,8 @@ module and define your helper methods there:
|
|
159
189
|
end
|
160
190
|
end
|
161
191
|
|
162
|
-
Helpers have full access to the request and response objects so you can
|
192
|
+
Helpers have full access to the request and response objects so you can easily
|
193
|
+
read and manipulate headers.
|
163
194
|
|
164
195
|
|
165
196
|
== More Information
|
@@ -177,5 +208,5 @@ http://github.com/jlong/serve
|
|
177
208
|
== License
|
178
209
|
|
179
210
|
Serve is released under the MIT license and is copyright (c) 2007-2010
|
180
|
-
John W. Long and Adam I. Williams.
|
181
|
-
the LICENSE file.
|
211
|
+
John W. Long and Adam I. Williams. Portions have been contributed by Robert
|
212
|
+
Evans and others. A copy of the MIT license can be found in the LICENSE file.
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/lib/serve/application.rb
CHANGED
@@ -18,6 +18,12 @@ module Serve
|
|
18
18
|
def run(args = ARGV)
|
19
19
|
@options = parse(args)
|
20
20
|
case
|
21
|
+
when options[:create]
|
22
|
+
require 'serve/project'
|
23
|
+
Serve::Project.new(options[:create]).create
|
24
|
+
when options[:convert]
|
25
|
+
require 'serve/project'
|
26
|
+
Serve::Project.new(options[:convert]).convert
|
21
27
|
when options[:version]
|
22
28
|
puts version
|
23
29
|
when options[:help]
|
@@ -43,6 +49,8 @@ module Serve
|
|
43
49
|
args = normalize_args(args)
|
44
50
|
options[:help] = extract_boolean(args, '-h', '--help')
|
45
51
|
options[:version] = extract_boolean(args, '-v', '--version')
|
52
|
+
options[:create] = extract_creation(args)
|
53
|
+
options[:convert] = extract_conversion(args)
|
46
54
|
options[:environment] = extract_environment(args)
|
47
55
|
options[:root] = extract_root(args)
|
48
56
|
options[:address] = extract_address(args)
|
@@ -58,23 +66,34 @@ module Serve
|
|
58
66
|
def help
|
59
67
|
program = File.basename($0)
|
60
68
|
[
|
69
|
+
"Serve is a rapid prototyping framework for Web applications. This is a basic ",
|
70
|
+
"help message containing pointers to more information.",
|
71
|
+
" ",
|
61
72
|
"Usage:",
|
73
|
+
" #{program} -h/--help",
|
74
|
+
" #{program} -v/--version",
|
62
75
|
" #{program} [port] [environment] [directory]",
|
63
76
|
" #{program} [address:port] [environment] [directory]",
|
64
77
|
" #{program} [address] [port] [environment] [directory]",
|
65
|
-
" #{program} [options]",
|
78
|
+
" #{program} command [arguments] [options]",
|
79
|
+
" ",
|
80
|
+
"Examples:",
|
81
|
+
" #{program} # start server on port 4000",
|
82
|
+
" #{program} 2100 # start server on port 2100",
|
83
|
+
" #{program} create mockups # create a Serve project in mockups directory",
|
84
|
+
" #{program} convert mockups # convert a Compass project in mockups",
|
66
85
|
" ",
|
67
86
|
"Description:",
|
68
|
-
" Starts a
|
69
|
-
"
|
87
|
+
" Starts a web server on the specified address and port with its document root ",
|
88
|
+
" set to the current working directory. (Optionally, you can specify the ",
|
70
89
|
" directory as the last parameter.) By default the command uses 0.0.0.0 for ",
|
71
90
|
" the address and 4000 for the port. This means that once the command has ",
|
72
91
|
" been started you can access the documents in the current directory with any ",
|
73
|
-
"
|
92
|
+
" web browser at:",
|
74
93
|
" ",
|
75
94
|
" http://localhost:4000/",
|
76
95
|
" ",
|
77
|
-
" If the haml, redcloth, or bluecloth gems are installed the command can
|
96
|
+
" If the haml, redcloth, or bluecloth gems are installed the command can handle ",
|
78
97
|
" Haml, Sass, SCSS, Textile, and Markdown for documents with haml, sass, scss, ",
|
79
98
|
" textile, and markdown file extensions.",
|
80
99
|
" ",
|
@@ -82,15 +101,31 @@ module Serve
|
|
82
101
|
" script will start that instead.",
|
83
102
|
" ",
|
84
103
|
" If a Rack configuration file (config.ru) exists in the current directory the ",
|
85
|
-
" script will start that using the rackup command.",
|
104
|
+
" script will start that using the `rackup` command.",
|
86
105
|
" ",
|
87
106
|
" A Rails or Rack app will start with the environment specified or the ",
|
88
107
|
" development environment if none is specified. Rails and Rack apps are ",
|
89
108
|
" started by default on port 3000.",
|
90
109
|
" ",
|
110
|
+
"Additional Commands:",
|
111
|
+
" In addition the functionality listed above the following commands are ",
|
112
|
+
" supported by Serve.",
|
113
|
+
" ",
|
114
|
+
" create",
|
115
|
+
" Creates a new Rack-based Serve project with support for Haml, Sass, and",
|
116
|
+
" Compass with the appropriate directory structure and configuration files.",
|
117
|
+
" ",
|
118
|
+
" convert",
|
119
|
+
" Converts an existing Compass project into a Rack-based Serve project.",
|
120
|
+
" ",
|
91
121
|
"Options:",
|
92
|
-
" -
|
93
|
-
"
|
122
|
+
" -j, --javascript The name of the JavaScript Framework you'd like to use.",
|
123
|
+
" (Only valid for create and convert commands.)",
|
124
|
+
" -h, --help Show this message and quit.",
|
125
|
+
" -v, --version Show the program version number and quit.",
|
126
|
+
" ",
|
127
|
+
"Further information:",
|
128
|
+
" http://github.com/jlong/serve/blob/master/README.rdoc"
|
94
129
|
].join("\n")
|
95
130
|
end
|
96
131
|
|
@@ -130,6 +165,36 @@ module Serve
|
|
130
165
|
Dir.pwd
|
131
166
|
end
|
132
167
|
|
168
|
+
def extract_javascript_framework(args, *opts)
|
169
|
+
framework = nil
|
170
|
+
opts.each do |opt|
|
171
|
+
framework = args.pop if args.delete(opt)
|
172
|
+
end
|
173
|
+
framework
|
174
|
+
end
|
175
|
+
|
176
|
+
def extract_creation(args)
|
177
|
+
if args.delete('create')
|
178
|
+
framework = extract_javascript_framework(args, '-j', '--javascript')
|
179
|
+
args.reverse!
|
180
|
+
{
|
181
|
+
:framework => framework,
|
182
|
+
:name => (args.first ? args.pop : 'mockups'),
|
183
|
+
:directory => (args.first ? File.expand_path(args.pop) : Dir.pwd)
|
184
|
+
}
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def extract_conversion(args)
|
189
|
+
if args.delete('convert')
|
190
|
+
framework = extract_javascript_framework(args, '-j', '--javascript')
|
191
|
+
{
|
192
|
+
:directory => (args.first ? File.expand_path(args.pop) : Dir.pwd),
|
193
|
+
:framework => framework
|
194
|
+
}
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
133
198
|
def rails_script_server
|
134
199
|
@rails_server_script ||= options[:root] + '/script/server'
|
135
200
|
end
|
@@ -165,10 +230,28 @@ module Serve
|
|
165
230
|
Rack::Directory.new(root)
|
166
231
|
])
|
167
232
|
end
|
168
|
-
|
169
|
-
|
170
|
-
|
233
|
+
begin
|
234
|
+
# Try Thin
|
235
|
+
thin = Rack::Handler.get('thin')
|
236
|
+
thin.run app, :Port => options[:port], :Host => options[:address] do |server|
|
237
|
+
puts "Thin #{Thin::VERSION::STRING} available at http://#{options[:address]}:#{options[:port]}"
|
238
|
+
end
|
239
|
+
rescue LoadError
|
240
|
+
begin
|
241
|
+
# Then Mongrel
|
242
|
+
mongrel = Rack::Handler.get('mongrel')
|
243
|
+
mongrel.run app, :Port => options[:port], :Host => options[:address] do |server|
|
244
|
+
puts "Mongrel #{Mongrel::Const::MONGREL_VERSION} available at http://#{options[:address]}:#{options[:port]}"
|
245
|
+
end
|
246
|
+
rescue LoadError
|
247
|
+
# Then WEBrick
|
248
|
+
puts "Install Mongrel or Thin for better performance."
|
249
|
+
webrick = Rack::Handler.get('webrick')
|
250
|
+
webrick.run app, :Port => options[:port], :Host => options[:address] do |server|
|
251
|
+
trap("INT") { server.shutdown }
|
252
|
+
end
|
253
|
+
end
|
171
254
|
end
|
172
255
|
end
|
173
256
|
end
|
174
|
-
end
|
257
|
+
end
|