Skip to content
This repository
Newer
Older
100644 192 lines (127 sloc) 4.358 kb
1ea33667 »
2011-03-06 First commit
1 Stasis
2 ======
4ab38af8 »
2009-11-06 [gem_template] First commit
3
1ea33667 »
2011-03-06 First commit
4 A general-purpose static site generator.
5
6 Philosophy
7 ----------
8
9 My preferred stack = static markup/assets (Nginx) + services (Node.js).
10
11 Stasis helps with the first part of the equation. It can even get fairly dynamic if you need it to.
4ab38af8 »
2009-11-06 [gem_template] First commit
12
085cb142 »
2009-11-09 [gem_template] Updating README
13 Requirements
14 ------------
4ab38af8 »
2009-11-06 [gem_template] First commit
15
1ea33667 »
2011-03-06 First commit
16 gem install stasis
17
18 Supported Template Engines
19 --------------------------
20
21 Stasis uses [Tilt](https://github.com/rtomayko/tilt) to support the following template engines:
22
23 ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
24 -------------------------- ----------------- ----------------------------
25 ERB .erb none (included ruby stdlib)
26 Interpolated String .str none (included ruby core)
27 Haml .haml haml
28 Sass .sass haml
29 Less CSS .less less
30 Builder .builder builder
31 Liquid .liquid liquid
32 RDiscount .markdown rdiscount
33 RedCloth .textile redcloth
34 RDoc .rdoc rdoc
35 Radius .radius radius
36 Markaby .mab markaby
37 Nokogiri .nokogiri nokogiri
38 CoffeeScript .coffee coffee-script (+node coffee)
39 Slim .slim slim (>= 0.7)
40
41 Example
42 -------
43
f50ec06e »
2011-03-12 README
44 Our [spec project](https://github.com/winton/stasis/tree/master/spec/fixtures/project) implements all the features below.
45
46 Get Started
47 -----------
48
1ea33667 »
2011-03-06 First commit
49 Create a directory for your project and a markup file:
50
51 ### view.erb
52
53 Welcome <%= '!' * 3 %>
54
55 Generate Static Files
56 ---------------------
57
58 Open your terminal, `cd` into your project directory, and run the `stasis` command:
59
60 stasis
61
62 You now have a `public` directory with rendered markup:
63
64 public/
65 view.html
66 view.erb
67
68 Controllers
69 -----------
70
71 The only reserved filename in a Stasis project is `controller.rb`.
72
f50ec06e »
2011-03-12 README
73 You can have a `controller.rb` at any directory level:
74
75 controller.rb
76 index.erb
77 pages/
78 controller.rb
79 page.erb
80
81 Callbacks
82 ---------
83
84 Define `before` and `after` render callbacks within your controller:
85
1ea33667 »
2011-03-06 First commit
86 ### controller.rb
87
88 # Call before any file renders
89
90 before do
91 @title = 'Default Title'
92 end
93
94 # Call only before view.erb renders
95
96 before 'view.erb' do
97 @title = 'My Site'
98 end
99
100 ### view.erb
101
102 Welcome to <%= @title %>!
103
f50ec06e »
2011-03-12 README
104 Change the Destination
105 ----------------------
1ea33667 »
2011-03-06 First commit
106
f50ec06e »
2011-03-12 README
107 Let's say we want `view.erb` to be our front page:
1ea33667 »
2011-03-06 First commit
108
f50ec06e »
2011-03-12 README
109 ### controller.rb
1ea33667 »
2011-03-06 First commit
110
f50ec06e »
2011-03-12 README
111 before 'view.erb' do
112 @destination = '/index.html'
113 end
1ea33667 »
2011-03-06 First commit
114
115 Layouts
116 -------
117
118 Create the layout markup:
119
120 ### layout.erb
121
122 <html>
123 <head>
124 <title><%= @title %></title>
125 </head>
126 <body><%= yield %></body>
127 </html>
128
129 ### controller.rb
130
131 before 'view.erb' do
132 @layout = 'layout.erb'
133 @title = 'My Site'
134 end
135
136 before 'layout.erb' do
f50ec06e »
2011-03-12 README
137 @destination = nil
1ea33667 »
2011-03-06 First commit
138 end
139
140 We want `view.erb` to use the layout, so we set `@layout = 'layout.erb'`.
141
f50ec06e »
2011-03-12 README
142 We do not want a `public/layout.html` file, so we set `@destination = nil`.
1ea33667 »
2011-03-06 First commit
143
f50ec06e »
2011-03-12 README
144 Helpers
145 -------
1ea33667 »
2011-03-06 First commit
146
f50ec06e »
2011-03-12 README
147 Define helper methods within your controllers.
1ea33667 »
2011-03-06 First commit
148
149 ### controller.rb
150
f50ec06e »
2011-03-12 README
151 helpers do
152 def active?(path)
153 @source == path
154 end
1ea33667 »
2011-03-06 First commit
155 end
156
f50ec06e »
2011-03-12 README
157 ### layout.erb
158
159 <%= active?('view.erb') %>
160
161 Class Variables
162 ---------------
163
164 To summarize, the following class variables have a special purpose in a Stasis project:
165
166 * `@destination` - Get/set the destination path within `public/`
167 * `@layout` - Get/set a file path to use as the layout
168 * `@source` - Get/set the file path that is being rendered
1ea33667 »
2011-03-06 First commit
169
170 Continuous Rendering
171 --------------------
172
173 To continuously render files as you change them, run:
174
175 stasis -c
176
177 Web Server
178 ----------
4ab38af8 »
2009-11-06 [gem_template] First commit
179
1ea33667 »
2011-03-06 First commit
180 To start Stasis in web server mode, run:
4ab38af8 »
2009-11-06 [gem_template] First commit
181
1ea33667 »
2011-03-06 First commit
182 stasis -p 3000
085cb142 »
2009-11-09 [gem_template] Updating README
183
1ea33667 »
2011-03-06 First commit
184 In your browser, visit [http://localhost:3000](http://localhost:3000).
085cb142 »
2009-11-09 [gem_template] Updating README
185
1ea33667 »
2011-03-06 First commit
186 In web server mode, Stasis continuously renders (`-c`).
085cb142 »
2009-11-09 [gem_template] Updating README
187
f50ec06e »
2011-03-12 README
188 Other Topics:
189 -------------
085cb142 »
2009-11-09 [gem_template] Updating README
190
f50ec06e »
2011-03-12 README
191 * [Callback Execution Order](https://github.com/winton/stasis/wiki/Callback-Execution-Order).
192 * [Run Stasis Programmatically](https://github.com/winton/stasis/wiki/Run-Stasis-Programmatically)
Something went wrong with that request. Please try again.