Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 223 lines (144 sloc) 4.752 kb
1ea3366 @winton First commit
authored
1 Stasis
2 ======
4ab38af @winton [gem_template] First commit
authored
3
a2b7e5d @winton README
authored
4 Stasis is a dynamic framework for static sites.
37bbac2 @winton README
authored
5
a2b7e5d @winton README
authored
6 When coupled with [metastasis](https://github.com/winton/metastasis), Stasis can even respond to dynamic user input.
7
8 The end goal? Making a high-performance web framework that serves pages solely through Nginx.
1ea3366 @winton First commit
authored
9
0292263 @winton README, removing after filter
authored
10 Install
1ea3366 @winton First commit
authored
11 -------
12
d16d9eb @winton More work on web site
authored
13 Install via RubyGems:
1ea3366 @winton First commit
authored
14
d16d9eb @winton More work on web site
authored
15 <!-- language:console -->
16
17 $ gem install stasis
18
19 Templates
20 ---------
21
a880da8 @winton More work on web site
authored
22 At its most essential, Stasis takes a directory tree with [supported template files](#supported_markup_languages) and renders them.
23
d16d9eb @winton More work on web site
authored
24 Example directory structure:
25
26 <!-- language:console -->
1ea3366 @winton First commit
authored
27
0292263 @winton README, removing after filter
authored
28 project/
29 index.html.haml
a880da8 @winton More work on web site
authored
30 other.txt
1ea3366 @winton First commit
authored
31
a880da8 @winton More work on web site
authored
32 Run `stasis`:
d16d9eb @winton More work on web site
authored
33
a880da8 @winton More work on web site
authored
34 <!-- highlight:stasis language:console -->
1ea3366 @winton First commit
authored
35
37bbac2 @winton README
authored
36 $ cd project
37 $ stasis
1ea3366 @winton First commit
authored
38
a880da8 @winton More work on web site
authored
39 Stasis creates a `public` directory:
d16d9eb @winton More work on web site
authored
40
a880da8 @winton More work on web site
authored
41 <!-- highlight:public/ language:console -->
1ea3366 @winton First commit
authored
42
0292263 @winton README, removing after filter
authored
43 project/
a880da8 @winton More work on web site
authored
44 index.html.haml
45 other.txt
0292263 @winton README, removing after filter
authored
46 public/
47 index.html
a880da8 @winton More work on web site
authored
48 other.txt
c66b35b @winton More work
authored
49
a880da8 @winton More work on web site
authored
50 `index.html.haml` renders to `public/index.html`.
c66b35b @winton More work
authored
51
a880da8 @winton More work on web site
authored
52 `other.txt` is copied as-is because `.txt` is an unrecognized template extension.
1ea3366 @winton First commit
authored
53
54 Controllers
55 -----------
56
a880da8 @winton More work on web site
authored
57 Controllers contain Ruby code that is evaluated once before all templates render.
1ea3366 @winton First commit
authored
58
a880da8 @winton More work on web site
authored
59 Example directory structure:
60
61 <!-- highlight:controller.rb language:console -->
d16d9eb @winton More work on web site
authored
62
0292263 @winton README, removing after filter
authored
63 project/
64 controller.rb
65 index.html.haml
66 subdirectory/
67 controller.rb
68 index.html.haml
6a8dd75 @winton Before all working
authored
69
d16d9eb @winton More work on web site
authored
70 Before
71 ------
6a8dd75 @winton Before all working
authored
72
a880da8 @winton More work on web site
authored
73 Use `before` blocks within your `controller.rb` to execute code before templates render.
74
75 `controller.rb`:
f50ec06 @winton README
authored
76
0292263 @winton README, removing after filter
authored
77 before 'index.html.haml' do
78 @something = true
79 end
f50ec06 @winton README
authored
80
a880da8 @winton More work on web site
authored
81 `@something` is now available to the `index.html.haml` template.
37bbac2 @winton README
authored
82
a880da8 @winton More work on web site
authored
83 The `before` method can take any number of paths and/or regular expressions:
84
85 before 'index.html.haml', /.*html.erb/ do
86 @something = true
87 end
f50ec06 @winton README
authored
88
0292263 @winton README, removing after filter
authored
89 Layouts
90 -------
1ea3366 @winton First commit
authored
91
a880da8 @winton More work on web site
authored
92 `layout.html.haml`:
c66b35b @winton More work
authored
93
0292263 @winton README, removing after filter
authored
94 %html
95 %body= yield
96
a880da8 @winton More work on web site
authored
97 In your `controller.rb`, set the default layout:
0292263 @winton README, removing after filter
authored
98
99 layout 'layout.html.haml'
1ea3366 @winton First commit
authored
100
25ea4e2 @winton README, bin file working, `before` controller method accepts multiple pa...
authored
101 Set the layout for a particular template:
1ea3366 @winton First commit
authored
102
0292263 @winton README, removing after filter
authored
103 layout 'index.html.haml' => 'layout.html.haml'
1ea3366 @winton First commit
authored
104
a880da8 @winton More work on web site
authored
105 Use a regular expression:
1ea3366 @winton First commit
authored
106
a880da8 @winton More work on web site
authored
107 layout /.*html.haml/ => 'layout.html.haml'
1ea3366 @winton First commit
authored
108
a880da8 @winton More work on web site
authored
109 Set the layout from a `before` block:
1ea3366 @winton First commit
authored
110
0292263 @winton README, removing after filter
authored
111 before 'index.html.haml' do
112 layout 'layout.html.haml'
f50ec06 @winton README
authored
113 end
1ea3366 @winton First commit
authored
114
d16d9eb @winton More work on web site
authored
115 Render
116 ------
0292263 @winton README, removing after filter
authored
117
d16d9eb @winton More work on web site
authored
118 Within a template:
0292263 @winton README, removing after filter
authored
119
120 %html
121 %body= render '_partial.html.haml'
6a8dd75 @winton Before all working
authored
122
d16d9eb @winton More work on web site
authored
123 Within a `before` block:
0292263 @winton README, removing after filter
authored
124
125 before 'index.html.haml' do
126 @partial = render '_partial.html.haml'
6a8dd75 @winton Before all working
authored
127 end
128
d16d9eb @winton More work on web site
authored
129 Text:
1ea3366 @winton First commit
authored
130
0292263 @winton README, removing after filter
authored
131 render :text => 'Hello'
1ea3366 @winton First commit
authored
132
d16d9eb @winton More work on web site
authored
133 Local variables:
1ea3366 @winton First commit
authored
134
0292263 @winton README, removing after filter
authored
135 render 'index.html.haml', :locals => { :x => true }
1ea3366 @winton First commit
authored
136
d16d9eb @winton More work on web site
authored
137 Include a block for the template to `yield` to:
1ea3366 @winton First commit
authored
138
0292263 @winton README, removing after filter
authored
139 render 'index.html.haml' { 'Hello' }
6a8dd75 @winton Before all working
authored
140
0292263 @winton README, removing after filter
authored
141 Instead
142 -------
6a8dd75 @winton Before all working
authored
143
25ea4e2 @winton README, bin file working, `before` controller method accepts multiple pa...
authored
144 The `instead` method changes the output of the template being rendered:
6a8dd75 @winton Before all working
authored
145
0292263 @winton README, removing after filter
authored
146 before 'index.html.haml' do
147 instead render('subdirectory/index.html.haml')
1ea3366 @winton First commit
authored
148 end
149
f50ec06 @winton README
authored
150 Helpers
151 -------
1ea3366 @winton First commit
authored
152
a880da8 @winton More work on web site
authored
153 `controller.rb`:
1ea3366 @winton First commit
authored
154
f50ec06 @winton README
authored
155 helpers do
0292263 @winton README, removing after filter
authored
156 def say_hello
157 'Hello'
f50ec06 @winton README
authored
158 end
1ea3366 @winton First commit
authored
159 end
160
a880da8 @winton More work on web site
authored
161 The `say_hello` method is now available to all `before` blocks and templates.
162
163 Ignore
164 ------
165
166 Use the `ignore` method in your `controller.rb` to ignore certain paths.
167
168 Ignore filenames with an underscore at the beginning:
169
170 ignore /_.*/
171
c66b35b @winton More work
authored
172 Priority
173 --------
174
a880da8 @winton More work on web site
authored
175 Use the `priority` method in your `controller.rb` to change the file process order.
c66b35b @winton More work
authored
176
a880da8 @winton More work on web site
authored
177 Copy `.txt` files before rendering `index.html.erb`:
c66b35b @winton More work
authored
178
a880da8 @winton More work on web site
authored
179 priority /.*txt/ => 2, 'index.html.erb' => 1
c66b35b @winton More work
authored
180
a880da8 @winton More work on web site
authored
181 The default priority is `0` for all files.
c66b35b @winton More work
authored
182
d16d9eb @winton More work on web site
authored
183 More
184 ----
f50ec06 @winton README
authored
185
a880da8 @winton More work on web site
authored
186 ### Development Mode
1ea3366 @winton First commit
authored
187
25ea4e2 @winton README, bin file working, `before` controller method accepts multiple pa...
authored
188 To continuously regenerate your project as you modify files, run:
1ea3366 @winton First commit
authored
189
a880da8 @winton More work on web site
authored
190 <!-- highlight:-d language:console -->
d16d9eb @winton More work on web site
authored
191
a880da8 @winton More work on web site
authored
192 $ stasis -d
d16d9eb @winton More work on web site
authored
193
194 ### Supported Markup Languages
195
196 Stasis uses [Tilt](https://github.com/rtomayko/tilt) to support the following template engines:
197
198 <!-- language:console -->
199
200 ENGINE FILE EXTENSIONS
201 -------------------------- ----------------------
202 ERB .erb, .rhtml
203 Interpolated String .str
204 Erubis .erb, .rhtml, .erubis
205 Haml .haml
206 Sass .sass
207 Scss .scss
208 Less CSS .less
209 Builder .builder
210 Liquid .liquid
211 RDiscount .markdown, .mkd, .md
212 Redcarpet .markdown, .mkd, .md
213 BlueCloth .markdown, .mkd, .md
214 Kramdown .markdown, .mkd, .md
215 Maruku .markdown, .mkd, .md
216 RedCloth .textile
217 RDoc .rdoc
218 Radius .radius
219 Markaby .mab
220 Nokogiri .nokogiri
221 CoffeeScript .coffee
222 Creole (Wiki markup) .creole
223 Yajl .yajl
Something went wrong with that request. Please try again.