haml-server 0.1 → 0.2
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/bin/haml-server +72 -16
- metadata +2 -2
data/bin/haml-server
CHANGED
@@ -8,6 +8,17 @@
|
|
8
8
|
#
|
9
9
|
# [1]: https://github.com/jlong/serve
|
10
10
|
|
11
|
+
#### Installation
|
12
|
+
|
13
|
+
# This is the easy part! Run this from your default ruby (or default RVM ruby)
|
14
|
+
# so you have access to `haml-server` from wherever you are.
|
15
|
+
#
|
16
|
+
# gem install haml-server
|
17
|
+
#
|
18
|
+
# You can also grab the code from [github][1].
|
19
|
+
#
|
20
|
+
# [1]: https://github.com/bernerdschaefer/haml-server
|
21
|
+
|
11
22
|
#### Usage
|
12
23
|
|
13
24
|
# Think of `haml-server` as `python -m SimpleHTTPServer`... but for `HAML`!
|
@@ -18,8 +29,10 @@
|
|
18
29
|
#
|
19
30
|
# Visiting `http://localhost:4567/` will render `index.haml`. Visiting
|
20
31
|
# `/path/to/resource` will render `path/to/resource.haml`. Simple.
|
21
|
-
|
22
|
-
|
32
|
+
|
33
|
+
##### Layouts
|
34
|
+
|
35
|
+
# You can also create a file called `layout.haml` to apply a layout to each of
|
23
36
|
# your pages:
|
24
37
|
#
|
25
38
|
# # layout.haml
|
@@ -27,6 +40,28 @@
|
|
27
40
|
# %body
|
28
41
|
# = yield
|
29
42
|
|
43
|
+
##### SASS
|
44
|
+
|
45
|
+
# If you want to use SASS templates, you can either define them inline using
|
46
|
+
# HAML's filters, like so:
|
47
|
+
#
|
48
|
+
# # index.haml
|
49
|
+
# %html
|
50
|
+
# %head
|
51
|
+
# :sass
|
52
|
+
# .content
|
53
|
+
# width: 10px
|
54
|
+
#
|
55
|
+
# Or you can write them to a standalone file, and then link to the same file
|
56
|
+
# but with ".css" instead of ".sass". So if you had `/stylesheets/screen.sass`,
|
57
|
+
# then you might do this in your layout:
|
58
|
+
#
|
59
|
+
# # layout.haml
|
60
|
+
# %html
|
61
|
+
# %head
|
62
|
+
# :css
|
63
|
+
# @import url(/stylesheets/screen.css);
|
64
|
+
|
30
65
|
#### The code
|
31
66
|
|
32
67
|
# `HAML`, check!
|
@@ -69,23 +104,44 @@ get "/favicon.ico" do
|
|
69
104
|
404
|
70
105
|
end
|
71
106
|
|
72
|
-
# This is our basic handler for all requests that come through to Sinatra.
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# one.
|
107
|
+
# This is our basic handler for all requests that come through to Sinatra.
|
108
|
+
# We'll extract the necessary path information, and then render either a haml
|
109
|
+
# or sass file.
|
76
110
|
handler = lambda do
|
77
|
-
path =
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
111
|
+
path = request.path_info
|
112
|
+
|
113
|
+
extension = File.extname(path)
|
114
|
+
|
115
|
+
# This is the most straight-forward way to remove the extension from a while
|
116
|
+
# while preserving it's original path information.
|
117
|
+
path = path.chomp(extension)
|
118
|
+
|
119
|
+
# If the path is empty, it's a request for the index page.
|
120
|
+
path = :index if path == "/"
|
121
|
+
|
122
|
+
# We're rendering templates, so we need to convert to a symbol for Sinatra --
|
123
|
+
# otherwise it will think we're rending a string.
|
124
|
+
path = path.to_sym
|
125
|
+
|
126
|
+
case extension
|
127
|
+
when ".css"
|
128
|
+
# If a request for, say, '/stylesheets/screen.css' wasn't matched by the
|
129
|
+
# public handler, then we try to render a sass template with the same name.
|
130
|
+
sass path
|
131
|
+
else
|
132
|
+
# Otherwise, we fall back to always rendering haml.
|
133
|
+
haml path
|
134
|
+
end
|
82
135
|
end
|
83
136
|
|
84
|
-
# Now we bind our handler to all of the `HTTP` verbs.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
137
|
+
# Now we bind our handler to all of the `HTTP` verbs. Matching against `//` is
|
138
|
+
# shorthand for matching all request paths: since `//` always returns true when
|
139
|
+
# matched against a string, our handler will run on every request. We could
|
140
|
+
# also write `get %r{/(.*)}, &handler`.. but that just looks ugly!
|
141
|
+
get //, &handler
|
142
|
+
put //, &handler
|
143
|
+
post //, &handler
|
144
|
+
delete //, &handler
|
89
145
|
|
90
146
|
# And that's it! We let Sinatra handle the rest: it will parse out any provided
|
91
147
|
# options (see `haml-server -h`) and then run the server for us.
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: haml-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: "0.
|
5
|
+
version: "0.2"
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bernerd Schaefer
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-24 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|