An extensible static site generator.
Stasis is a perfect complement to modern dynamic frameworks:
- Use Stasis to generate your HTML and other assets.
- Serve that data in the most performant way possible (usually Nginx).
- Use your dynamic framework to serve data to the client (usually JSON).
- Use your dynamic framework (or
cron
) to regenerate Stasis pages as needed.
Stasis is not your typical "one to one" markup renderer. Render to any number of dynamic paths. Access your database. Pull data from an API. Get crazy.
gem install stasis
Stasis uses Tilt to support the following template engines:
ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
-------------------------- ----------------- ----------------------------
ERB .erb none (included ruby stdlib)
Interpolated String .str none (included ruby core)
Haml .haml haml
Sass .sass haml
Less CSS .less less
Builder .builder builder
Liquid .liquid liquid
RDiscount .markdown rdiscount
RedCloth .textile redcloth
RDoc .rdoc rdoc
Radius .radius radius
Markaby .mab markaby
Nokogiri .nokogiri nokogiri
CoffeeScript .coffee coffee-script (+node coffee)
Slim .slim slim (>= 0.7)
The spec project implements all of the features in this README.
Create a directory for your project, and within that directory, a markup file:
Welcome <%= '!' * 3 %>
Open your terminal, cd
into your project directory, and run the stasis
command:
stasis
You now have a public
directory with rendered markup:
public/
view.html
view.html.erb
If the file extension is a supported markup file, it renders into public
.
If the file extension is unsupported, it copies into public
.
The only reserved filename in a Stasis project is controller.rb
.
You can have a controller.rb
at any directory level:
controller.rb
index.html.erb
pages/
controller.rb
page.html.erb
Controllers at the same directory level or above execute for a particular markup file.
For example, page.html.erb
uses both controllers, but index.html.erb
only uses the top-level controller.
Define before
and after
render callbacks within your controller:
# Call before any file renders
before do
@what_is_rendering = "any file"
end
# Call before any ERB file renders
before /.*erb/ do
@what_is_rendering = "ERB file"
end
# Call only before view.html.erb renders
before 'view.html.erb' do
@what_is_rendering = "the view"
end
<%= @what_is_rendering %>
Let's say we want view.html.erb
to be our front page:
destination 'view.html.erb' => '/index.html'
# or
before 'view.html.erb' do
@destination = '/index.html'
end
Sometimes you will want to ignore certain files entirely (no render, no copy).
For example, you'll often want to ignore filenames with an underscore at the beginning (partials):
ignore /_.*/
# or
before /_.*/ do
@ignore = true
end
Create the layout markup:
<html>
<body><%= yield %></body>
</html>
# set default layout for all views
layout 'layout.html.erb'
# or set layout for specific view
layout 'view.html.erb' => 'layout.html.erb'
# or
before 'view.html.erb' do
@layout = 'layout.html.erb'
end
Layout files are automatically ignored (don't want to render a layout.html
file).
Define helper methods within your controllers.
helpers do
def active?(path)
@source == path
end
end
<% if active?('view.html.erb') %>
Rendering view.html.erb
<% end -%>
You may want some files to render or copy before others:
priority 'view.html.erb' => 1, /.*css/ => 2, /.*js/ => 2
The default priority is 0
.
Render other files within a callback, helper, or view:
<%= render '_partial.html.erb', :locals => { :x => 'y' } %>
Use the following methods in your controllers:
after
before
destination
ignore
layout
priority
Use the following methods within a callback, helper, or view:
render
Use the following class variables in your callbacks, helpers, or views:
@destination
@layout
@source
Only alter these class variables from a before
callback.
To continuously render files as you change them, run:
stasis -c
To start Stasis in web server mode, run:
stasis -p 3000
In your browser, visit http://localhost:3000.
In web server mode, Stasis continuously renders (-c
).