serve 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +11 -0
- data/Gemfile +17 -14
- data/Gemfile.lock +53 -26
- data/LICENSE +1 -1
- data/QUICKSTART.rdoc +137 -27
- data/README.rdoc +115 -23
- data/VERSION +1 -1
- data/bin/serve +3 -3
- data/lib/serve.rb +2 -5
- data/lib/serve/application.rb +7 -6
- data/lib/serve/handlers/dynamic_handler.rb +40 -42
- data/lib/serve/handlers/less_handler.rb +19 -0
- data/lib/serve/handlers/sass_handler.rb +5 -0
- data/lib/serve/out.rb +19 -1
- data/lib/serve/project.rb +2 -2
- data/lib/serve/rack.rb +58 -18
- data/lib/serve/router.rb +43 -0
- data/lib/serve/templates/config.ru +14 -10
- data/lib/serve/view_helpers.rb +36 -24
- data/spec/fixtures/directory/index.html +1 -0
- data/spec/fixtures/hello.html +1 -0
- data/spec/fixtures/stylesheets/application.sass +3 -0
- data/spec/router_spec.rb +60 -0
- data/spec/spec_helper.rb +0 -1
- metadata +50 -39
- data/lib/serve/file_resolver.rb +0 -48
- data/lib/serve/handlers/markdown_handler.rb +0 -10
- data/lib/serve/handlers/static_handler.rb +0 -22
- data/lib/serve/handlers/textile_handler.rb +0 -10
- data/lib/serve/rails.rb +0 -4
- data/lib/serve/rails/configuration.rb +0 -69
- data/lib/serve/rails/mount.rb +0 -38
- data/lib/serve/rails/routing.rb +0 -25
- data/lib/serve/rails/serve_controller.rb +0 -52
- data/lib/serve/response_cache.rb +0 -170
- data/spec/response_cache_spec.rb +0 -248
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
= Change Log
|
2
2
|
|
3
|
+
== 1.1.0 (May 25, 2010)
|
4
|
+
|
5
|
+
* Use latest versions of dependencies [jlong]
|
6
|
+
* Added support for locals in partials [heikki]
|
7
|
+
* Added limited support for Radius [jlong]
|
8
|
+
* Added support for LESS [jlong]
|
9
|
+
* Added support for ERubis [jlong]
|
10
|
+
* Rewrote the way that Serve resolves file names [jlong]
|
11
|
+
* Incorporated Tilt so that other template languages can be added with ease. [jlong]
|
12
|
+
* Added limited support for Slim [fleadope, jlong]
|
13
|
+
|
3
14
|
== 1.0.0 (November 3, 2010)
|
4
15
|
|
5
16
|
* Various tweaks and fixes [jlong]
|
data/Gemfile
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem 'rake', '~> 0.
|
4
|
-
gem 'rack', '~> 1.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# activesupport 3.0.x
|
10
|
-
gem 'activesupport', '~> 3.0.1'
|
11
|
-
gem 'tzinfo', '~> 0.3.23'
|
12
|
-
gem 'i18n', '~> 0.4.2'
|
3
|
+
gem 'rake', '~> 0.9.0'
|
4
|
+
gem 'rack', '~> 1.3.0'
|
5
|
+
gem 'tilt', '~> 1.3.1'
|
6
|
+
gem 'activesupport', '~> 3.0.7'
|
7
|
+
gem 'tzinfo', '~> 0.3.27'
|
8
|
+
gem 'i18n', '~> 0.6.0'
|
13
9
|
|
14
10
|
group :development do
|
11
|
+
gem 'rspec', '~> 2.6.0'
|
15
12
|
gem 'jeweler', '~> 1.4.0'
|
16
|
-
gem 'haml', '~> 3.
|
17
|
-
gem '
|
18
|
-
gem '
|
19
|
-
|
13
|
+
gem 'haml', '~> 3.1.1'
|
14
|
+
gem 'sass', '~> 3.1.1'
|
15
|
+
gem 'compass', '~> 0.11.1'
|
16
|
+
gem 'slim', '~> 0.9.4'
|
17
|
+
gem 'rdiscount', '~> 1.6.8'
|
18
|
+
gem 'RedCloth', '~> 4.2.7'
|
19
|
+
gem 'erubis', '~> 2.7.0'
|
20
|
+
gem 'less', '~> 1.2.21'
|
21
|
+
gem 'radius', '~> 0.6.1'
|
22
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,45 +1,72 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
RedCloth (4.2.7)
|
5
|
+
activesupport (3.0.7)
|
6
|
+
chunky_png (1.2.0)
|
7
|
+
compass (0.11.1)
|
8
|
+
chunky_png (~> 1.1)
|
9
|
+
fssm (>= 0.2.7)
|
10
|
+
sass (~> 3.1)
|
7
11
|
diff-lcs (1.1.2)
|
12
|
+
erubis (2.7.0)
|
13
|
+
fssm (0.2.7)
|
8
14
|
gemcutter (0.6.1)
|
9
15
|
git (1.2.5)
|
10
|
-
haml (3.
|
11
|
-
i18n (0.
|
16
|
+
haml (3.1.1)
|
17
|
+
i18n (0.6.0)
|
12
18
|
jeweler (1.4.0)
|
13
19
|
gemcutter (>= 0.1.0)
|
14
20
|
git (>= 1.2.5)
|
15
21
|
rubyforge (>= 2.0.0)
|
16
22
|
json_pure (1.4.6)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rspec
|
27
|
-
rspec-core (~> 2.0
|
28
|
-
rspec-expectations (~> 2.0
|
23
|
+
less (1.2.21)
|
24
|
+
mutter (>= 0.4.2)
|
25
|
+
treetop (>= 1.4.2)
|
26
|
+
mutter (0.5.3)
|
27
|
+
polyglot (0.3.1)
|
28
|
+
rack (1.3.0)
|
29
|
+
radius (0.6.1)
|
30
|
+
rake (0.9.0)
|
31
|
+
rdiscount (1.6.8)
|
32
|
+
rspec (2.6.0)
|
33
|
+
rspec-core (~> 2.6.0)
|
34
|
+
rspec-expectations (~> 2.6.0)
|
35
|
+
rspec-mocks (~> 2.6.0)
|
36
|
+
rspec-core (2.6.3)
|
37
|
+
rspec-expectations (2.6.0)
|
38
|
+
diff-lcs (~> 1.1.2)
|
39
|
+
rspec-mocks (2.6.0)
|
29
40
|
rubyforge (2.0.4)
|
30
41
|
json_pure (>= 1.1.7)
|
31
|
-
|
42
|
+
sass (3.1.1)
|
43
|
+
slim (0.9.4)
|
44
|
+
temple (~> 0.3.0)
|
45
|
+
tilt (~> 1.2)
|
46
|
+
temple (0.3.0)
|
47
|
+
tilt (1.3.1)
|
48
|
+
treetop (1.4.9)
|
49
|
+
polyglot (>= 0.3.1)
|
50
|
+
tzinfo (0.3.27)
|
32
51
|
|
33
52
|
PLATFORMS
|
34
53
|
ruby
|
35
54
|
|
36
55
|
DEPENDENCIES
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
56
|
+
RedCloth (~> 4.2.7)
|
57
|
+
activesupport (~> 3.0.7)
|
58
|
+
compass (~> 0.11.1)
|
59
|
+
erubis (~> 2.7.0)
|
60
|
+
haml (~> 3.1.1)
|
61
|
+
i18n (~> 0.6.0)
|
41
62
|
jeweler (~> 1.4.0)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
63
|
+
less (~> 1.2.21)
|
64
|
+
rack (~> 1.3.0)
|
65
|
+
radius (~> 0.6.1)
|
66
|
+
rake (~> 0.9.0)
|
67
|
+
rdiscount (~> 1.6.8)
|
68
|
+
rspec (~> 2.6.0)
|
69
|
+
sass (~> 3.1.1)
|
70
|
+
slim (~> 0.9.4)
|
71
|
+
tilt (~> 1.3.1)
|
72
|
+
tzinfo (~> 0.3.27)
|
data/LICENSE
CHANGED
data/QUICKSTART.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
=
|
1
|
+
= Serve Quickstart - Prototyping Rails Applications
|
2
2
|
|
3
3
|
|
4
4
|
<b>This is tutorial is incomplete. Help us finish it!</b>
|
@@ -28,22 +28,71 @@ mockups :: Fireworks or Photoshop web app mockups go here
|
|
28
28
|
prototype :: The HTML prototype for the web app goes here
|
29
29
|
application :: The actual Rails application is here
|
30
30
|
|
31
|
-
Let's go ahead and
|
31
|
+
Let's go ahead and setup the directory for the prototype. We'll use the `serve create` command to create the initial project directory and files:
|
32
|
+
|
33
|
+
$ serve create prototype
|
34
|
+
|
35
|
+
This should output:
|
36
|
+
|
37
|
+
create prototype
|
38
|
+
create prototype/public
|
39
|
+
create prototype/tmp
|
40
|
+
create prototype/views
|
41
|
+
create prototype/config.ru
|
42
|
+
create prototype/LICENSE
|
43
|
+
create prototype/.gitignore
|
44
|
+
create prototype/compass.config
|
45
|
+
create prototype/README.markdown
|
46
|
+
create prototype/public/images
|
47
|
+
create prototype/public/javascripts
|
48
|
+
create prototype/public/stylesheets
|
49
|
+
create prototype/sass
|
50
|
+
create prototype/sass/application.sass
|
51
|
+
create prototype/views/_layout.html.erb
|
52
|
+
create prototype/views/hello.html.erb
|
53
|
+
create prototype/views/view_helpers.rb
|
54
|
+
create prototype/views/index.redirect
|
55
|
+
|
56
|
+
You'll note that the `serve create` command creates a directory structure that is somewhat similar to a Rails project:
|
57
|
+
|
58
|
+
prototype/
|
59
|
+
|
|
60
|
+
+-- config.ru # Rack configuration file
|
61
|
+
|
|
62
|
+
+-- compass.config # Compass configuration file
|
63
|
+
|
|
64
|
+
+-- public/ # Directories for static assets
|
65
|
+
| |
|
66
|
+
| +-- stylesheets/ # Compiled stylesheets
|
67
|
+
| |
|
68
|
+
| +-- images/
|
69
|
+
| |
|
70
|
+
| `-- javascripts/
|
71
|
+
|
|
72
|
+
+-- sass/ # Store Sass source files here
|
73
|
+
| |
|
74
|
+
| `-- application.sass # Example Sass file for application
|
75
|
+
|
|
76
|
+
+-- tmp/ # Needed for Passenger (mod_passenger)
|
77
|
+
| |
|
78
|
+
| `-- restart.txt
|
79
|
+
|
|
80
|
+
`-- views/ # Store your ERB, Haml, etc. here
|
81
|
+
|
|
82
|
+
+-- _layout.html.erb # Example layout
|
83
|
+
|
|
84
|
+
+-- hello.html.erb # Example view
|
85
|
+
|
|
86
|
+
`-- view_helpers.rb # Example view helpers
|
87
|
+
|
88
|
+
Views and layouts for your prototype application belong in the "views" directory. The "public" directory is for static assets -- resources like images or javascripts that don't need server side processing. The "sass" directory is the place where you should store Sass source files (if you use those). Serve will automatically compile Sass and SCSS files stored here into <tt>public/stylesheets</tt> directory.
|
32
89
|
|
33
|
-
$ mkdir prototype
|
34
|
-
|
35
|
-
Rails apps generally store images, javascripts, and stylesheets in the top level directories by the same name. Let's go ahead and mirror those directories for our prototype:
|
36
|
-
|
37
|
-
$ cd prototype
|
38
|
-
$ mkdir images
|
39
|
-
$ mkdir javascripts
|
40
|
-
$ mkdir stylesheets
|
41
90
|
|
42
91
|
== Creating Our First Screen
|
43
92
|
|
44
93
|
Now that we have the prototype directory set up, let's create our first page so that you can get a feel for how Serve works. This will be a simple HTML login page for our application.
|
45
94
|
|
46
|
-
|
95
|
+
In the "views" directory, create a file named "login.html.erb" and insert the following source code:
|
47
96
|
|
48
97
|
<form action="/dashboard/" method="put">
|
49
98
|
<p>
|
@@ -77,28 +126,18 @@ By default the `serve` command automatically serves files from the directory tha
|
|
77
126
|
|
78
127
|
http://localhost:4000
|
79
128
|
|
80
|
-
You should see a simple directory listing. It will look similar to this:
|
81
|
-
|
82
|
-
Name Last modified Size
|
83
|
-
----------------------------------------------------------
|
84
|
-
Parent Directory 2008/02/23 15:35 -
|
85
|
-
images/ 2008/02/23 15:35 -
|
86
|
-
javascripts/ 2008/02/23 15:35 -
|
87
|
-
login.html.erb 2008/02/23 15:36 346
|
88
|
-
stylesheets/ 2008/02/23 15:35 -
|
89
|
-
|
90
129
|
Now navigate to the following URL:
|
91
130
|
|
92
131
|
http://localhost:4000/login/
|
93
132
|
|
94
|
-
You should see the contents of the login page. Note that Serve allows you to refer to pages without their extension. This allows you to use URLs in your documents that correspond
|
133
|
+
You should see the contents of the login page. Note that Serve allows you to refer to pages without their extension. This allows you to use URLs in your documents that correspond to the URLs that Rails uses by default.
|
95
134
|
|
96
135
|
|
97
136
|
== Layouts
|
98
137
|
|
99
|
-
One thing to note about the source that I gave you for the login page. I intentionally left out the <html>, <head>, and <body> tags because they belong a layout---not the source file. Let's go ahead and
|
138
|
+
One thing to note about the source that I gave you for the login page. I intentionally left out the <html>, <head>, and <body> tags because they belong a layout---not the source file. Let's go ahead and define that layout now.
|
100
139
|
|
101
|
-
|
140
|
+
Replace the contents of the file named "_layout.html.erb" in the "views" directory of your prototype with the following:
|
102
141
|
|
103
142
|
<html>
|
104
143
|
<head>
|
@@ -110,9 +149,9 @@ Insert the following HTML into a file named "_layout.html.erb" in the root direc
|
|
110
149
|
</body>
|
111
150
|
</html>
|
112
151
|
|
113
|
-
This layout includes a small amount of ERB
|
152
|
+
This layout includes a small amount of ERB. ERB stands for Embedded Ruby. ERB allows you to embed Ruby code into a web page to dynamically render content. In our case, we are using it in the layout to indicate the title of the web page and to insert the content of the page at the appropriate point. You can use ERB in layout or view files.
|
114
153
|
|
115
|
-
Embedded Ruby is delineated with the opening and closing sequence <% and %> respectively. Sequences that begin with an addition equals sign insert their output directly into the HTML. In this case we want to render the @title variable as the title in the head and as the first heading in the document body. The yield keyword is used to insert the content of the page at that point.
|
154
|
+
Embedded Ruby is delineated with the opening and closing sequence <% and %> respectively. Sequences that begin with an addition equals sign insert their output directly into the HTML. In this case we want to render the @title variable as the title in the head and as the first heading in the document body. The `yield` keyword is used to insert the content of the page at that point.
|
116
155
|
|
117
156
|
We need to make one small change to our login page before continuing. Insert the following line at the top of login.html.erb file:
|
118
157
|
|
@@ -124,8 +163,79 @@ This will set the @title variable for the login page. Now, switch back to your W
|
|
124
163
|
|
125
164
|
The page should now have a title and heading that both read "Login".
|
126
165
|
|
127
|
-
== Content
|
166
|
+
== Content regions with `content_for`
|
167
|
+
|
168
|
+
Let's add a sidebar to the login page. To do this in a layout friendly way, we will use the `content_for` helper method to define the sidebar.
|
169
|
+
|
170
|
+
Add the following code to the bottom of login.html.erb:
|
171
|
+
|
172
|
+
<% content_for :sidebar do %>
|
173
|
+
<h3>New Around Here?</h3>
|
174
|
+
<p>No problem! Just <a href="/signup/">create an account</a>.</p>
|
175
|
+
<% end %>
|
176
|
+
|
177
|
+
This defines a new content region of the page that we can render wherever we want in the layout. The :sidebar symbol defines the name of the content region.
|
128
178
|
|
179
|
+
Now to modify the layout to work with this new content region. In _layout.html.erb replace the code:
|
180
|
+
|
181
|
+
<h1><%= @title %>/h1>
|
182
|
+
<%= yield %>
|
183
|
+
|
184
|
+
With the following:
|
185
|
+
|
186
|
+
<div id="content">
|
187
|
+
<h1><%= @title %>/h1>
|
188
|
+
<%= yield %>
|
189
|
+
</div>
|
190
|
+
<div id="sidebar">
|
191
|
+
<%= yield :sidebar %>
|
192
|
+
</div>
|
193
|
+
|
194
|
+
This defines two new divs for the content and sidebar portions of the document. The first call to `yield` renders the content portion of a view (everything apart from regions defined by calls to `content_for`). The second call to `yield` passes the name of our content region as a symbol. When yield is called with a symbol, it renders the associated content region. In our case `yield :sidebar` causes Serve to render the content that we defined for the :sidebar region at that point in the layout.
|
195
|
+
|
196
|
+
Now add a block for inline styles to the "head" of the layout:
|
197
|
+
|
198
|
+
<styles>
|
199
|
+
#content { float: left; width: 60%; }
|
200
|
+
#sidebar { float: right; width: 40%; }
|
201
|
+
</styles>
|
202
|
+
|
203
|
+
We could certainly put this in it's own file (in the public/stylesheets directory), but for the purposes of this demonstration, it works just as well in the head of the document.
|
204
|
+
|
205
|
+
The full layout file should now look like this:
|
206
|
+
|
207
|
+
<html>
|
208
|
+
<head>
|
209
|
+
<title><%= @title %></title>
|
210
|
+
<styles>
|
211
|
+
#content { float: left; width: 60%; }
|
212
|
+
#sidebar { float: right; width: 40%; }
|
213
|
+
</styles>
|
214
|
+
</head>
|
215
|
+
<body>
|
216
|
+
<div id="content">
|
217
|
+
<h1><%= @title %>/h1>
|
218
|
+
<%= yield %>
|
219
|
+
</div>
|
220
|
+
<div id="sidebar">
|
221
|
+
<%= yield :sidebar %>
|
222
|
+
</div>
|
223
|
+
</body>
|
224
|
+
</html>
|
225
|
+
|
226
|
+
Now switch back to your Web browser at:
|
227
|
+
|
228
|
+
http://localhost:4000/login/
|
229
|
+
|
230
|
+
And check out the new multi-column layout on the login page.
|
129
231
|
|
130
232
|
|
131
233
|
== Partials
|
234
|
+
|
235
|
+
<%= render 'footer' %>
|
236
|
+
|
237
|
+
== View Helpers
|
238
|
+
|
239
|
+
view_helpers.rb
|
240
|
+
|
241
|
+
This tutorial is incomplete. Patches are welcome!
|
data/README.rdoc
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
= Serve - A Rapid Prototyping Framework for Web Applications
|
2
2
|
|
3
|
+
link:/downloads/jlong/serve/logo-hifi-1.png
|
4
|
+
|
3
5
|
Serve is a small Rack-based web server that makes it easy to serve HTML, ERB,
|
4
|
-
or
|
6
|
+
Haml, or Slim templates from any directory.
|
5
7
|
|
6
8
|
But Serve is much more than a simple web server.
|
7
9
|
|
8
10
|
Serve's primary purpose is to provide a rapid prototyping framework for Web
|
9
|
-
applications (specifically Rails apps). It is designed to
|
11
|
+
applications (specifically Rails apps). It is designed to complement web
|
10
12
|
application development and enforce a strict separation of concerns between
|
11
13
|
designer and developer. Using Serve allows the designer to work in a separate
|
12
14
|
prototype project, while the developer can work on the actual application and
|
@@ -30,8 +32,8 @@ MVC stack -- the views. Serve basically allows you to have a separate project
|
|
30
32
|
just for designing the views for the application. When views are ready, they
|
31
33
|
can be copied over from the prototype to the application almost as is. This
|
32
34
|
process is eased since Serve has full support for partials and layouts with
|
33
|
-
either ERB or
|
34
|
-
appropriate libraries are installed.
|
35
|
+
either ERB or Haml. Serve can also handle SASS, Slim, Textile, and Markdown
|
36
|
+
if the appropriate libraries are installed.
|
35
37
|
|
36
38
|
|
37
39
|
== Installation
|
@@ -45,12 +47,12 @@ Some systems, like the Mac, may require that you type:
|
|
45
47
|
|
46
48
|
sudo gem install serve
|
47
49
|
|
48
|
-
If you are new to the command prompt see:
|
50
|
+
If you are a Mac user and are new to the command prompt see:
|
49
51
|
|
50
|
-
http://
|
52
|
+
http://wiseheartdesign.com/articles/2010/11/12/the-designers-guide-to-the-osx-command-prompt/
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
+
Google "command prompt windows" if you are on a PC to find a simple
|
55
|
+
tutorial.
|
54
56
|
|
55
57
|
|
56
58
|
== Usage
|
@@ -163,18 +165,53 @@ the `compass watch` command to generate your stylesheets. Your stylesheets
|
|
163
165
|
will be compiled on the fly with Serve.
|
164
166
|
|
165
167
|
|
166
|
-
==
|
168
|
+
== Layouts
|
167
169
|
|
168
|
-
Serve
|
170
|
+
In Serve layouts work a little differently than they do in Rails. Because there are no
|
171
|
+
controllers to derive layout names from, Serve relies on the directory structure to
|
172
|
+
determine the layout associated with a specific view. Serve layouts are stored in
|
173
|
+
"_layout.erb" or "_layout.haml" files. Serve searches for a layout file in the same
|
174
|
+
directory as the view. If it fails to find one there, it traverses up the directory
|
175
|
+
tree searching each parent directory until it finds the "nearest" layout.
|
169
176
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
177
|
+
For example, assuming following directory structure:
|
178
|
+
|
179
|
+
views/
|
180
|
+
|
|
181
|
+
A) +-- _layout.erb
|
182
|
+
|
|
183
|
+
+-- index.erb
|
184
|
+
|
|
185
|
+
`-- about/
|
186
|
+
|
|
187
|
+
B) +-- _layout.erb
|
188
|
+
|
|
189
|
+
`-- index.erb
|
190
|
+
|
191
|
+
For "views/about/index.erb" Serve will use layout B. If layout B did not exist,
|
192
|
+
Serve would go up the directory tree and discover layout A which it would use to
|
193
|
+
render the view.
|
194
|
+
|
195
|
+
For "views/index.erb" Serve would immediately discover and use layout A because it
|
196
|
+
is in the same directory.
|
197
|
+
|
198
|
+
So Serve searches up the directory tree for the nearest layout file, and uses that
|
199
|
+
file to render the view. This is convenient because it allows you to structure your
|
200
|
+
Serve project in a way that allows entire "branches" of to share the same layout
|
201
|
+
and "branches" lower down can override the layout used.
|
202
|
+
|
203
|
+
|
204
|
+
== Partials
|
205
|
+
|
206
|
+
Partials in Serve work much like they do in Rails. Prefix your partials with an
|
207
|
+
underscore ("_") and use the <tt>render</tt> helper method in your views to render
|
208
|
+
the partial:
|
209
|
+
|
210
|
+
<%= render "footer" %>
|
211
|
+
|
212
|
+
Or,
|
213
|
+
|
214
|
+
<%= render "/shared/footer" %>
|
178
215
|
|
179
216
|
|
180
217
|
== View Helpers
|
@@ -190,7 +227,62 @@ module and define your helper methods there:
|
|
190
227
|
end
|
191
228
|
|
192
229
|
Helpers have full access to the request and response objects so you can easily
|
193
|
-
read and manipulate headers.
|
230
|
+
read and manipulate headers or do other fancy tricks.
|
231
|
+
|
232
|
+
Serve provides a number of stock helpers to make it easier for you to prototype
|
233
|
+
Rails applications:
|
234
|
+
|
235
|
+
# Escape Helpers
|
236
|
+
html_escape(string) # escape HTML in string
|
237
|
+
h(string) # alias for html_escape
|
238
|
+
json_escape(string) # escape invalid JSON characters in string
|
239
|
+
j(string) # alias for json_escape
|
240
|
+
|
241
|
+
# Content Helpers
|
242
|
+
capture(&block) # Capture a block inside of a view or layout
|
243
|
+
content_for(symbol, &block) # Capture a block and store it by symbol
|
244
|
+
content_for?(symbol) # Has content been captured for symbol?
|
245
|
+
get_content_for(symbol) # Retrieve content for symbol (equivalent to `yield symbol`)
|
246
|
+
set_content_for(symbol, string) # Set content for symbol to string
|
247
|
+
|
248
|
+
# Flash Helpers
|
249
|
+
flash # fake flash for request
|
250
|
+
|
251
|
+
# Param Helpers
|
252
|
+
params # access params for request
|
253
|
+
boolean_param(key) # retrieve value of a boolean param (true/false)
|
254
|
+
|
255
|
+
# Render Helpers
|
256
|
+
render(partial) # Render a partial
|
257
|
+
|
258
|
+
# Tag Helpers
|
259
|
+
content_tag(name, content, ...) # a double HTML tag
|
260
|
+
tag(name, ...) # a single HTML tag
|
261
|
+
image_tag(src, ...) # an HTML image tag
|
262
|
+
image(name, ...) # shorthand for standard image tag
|
263
|
+
javascript_tag(...) # a javascript tag
|
264
|
+
link_to(name, href, ...) # a link to name at href
|
265
|
+
link_to_function(name, ...) # a link to a function
|
266
|
+
mail_to(email_address, ...) # a mailto link
|
267
|
+
|
268
|
+
For more information, see:
|
269
|
+
|
270
|
+
https://github.com/jlong/serve/blob/master/lib/serve/view_helpers.rb
|
271
|
+
|
272
|
+
|
273
|
+
== File Types
|
274
|
+
|
275
|
+
Serve does special processing for files with following extensions:
|
276
|
+
|
277
|
+
textile :: Evaluates the document as Textile (requires the Redcloth gem)
|
278
|
+
markdown :: Evaluates the document as Markdown (requires the Bluecloth gem)
|
279
|
+
erb :: Evaluates the document as ERB
|
280
|
+
haml :: Evaluates the document as Haml (requires the Haml gem)
|
281
|
+
slim :: Evaluates the document using the Slim template language (requires the Slim gem)
|
282
|
+
sass :: Evaluates the document as Sass (requires the Haml gem)
|
283
|
+
scss :: Evaluates the document as SCSS (requires the Haml gem)
|
284
|
+
email :: Evaluates the document as if it is an e-mail message; the format is identical to a plain/text e-mail message's source
|
285
|
+
redirect :: Redirects to the URL contained in the document
|
194
286
|
|
195
287
|
|
196
288
|
== More Information
|
@@ -200,13 +292,13 @@ the GitHub wiki:
|
|
200
292
|
|
201
293
|
http://wiki.github.com/jlong/serve
|
202
294
|
|
203
|
-
|
295
|
+
Have questions? Feel free to ask them on the mailing list:
|
204
296
|
|
205
|
-
http://
|
297
|
+
http://groups.google.com/group/serve-users
|
206
298
|
|
207
299
|
|
208
300
|
== License
|
209
301
|
|
210
|
-
Serve is released under the MIT license and is copyright (c) 2007-
|
302
|
+
Serve is released under the MIT license and is copyright (c) 2007-2011
|
211
303
|
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.
|
304
|
+
Evans and others. A copy of the MIT license can be found in the LICENSE file.
|