Homeostasis

asset stamping, blogs, front-matter, hooks, & more

Stasis is a powerful static site generator. Homeostasis is a collection of plugins extending Stasis. Check out Homeostasis' source code on GitHub. Homeostasis is still in alpha development.

Installation

$ gem install homeostasis
$ vim /path/to/project/controller.rb

# /path/to/project/controller.rb
require 'homeostasis'

Install the gem as normal and require it at the beginning of your controller.rb file.

Asset Stamping

# default configuration
Homeostasis::Asset.config(
  replace_matcher: /\.(html|css|js)$/i,
  matcher: /\.(jpg|png|gif|css|js)$/i)

Homeostasis::Asset.concat('both.js', %w(one.js two.js))
Homeostasis::Asset.concat('both.css', %w(one.css two.css))

Asset stamping assumes that your project lives in a git repository. By default, assets are files with extensions:

They'll be stamped like script.js => script.sha1.js. Homeostasis will search in HTML, CSS, and JS source files and replace assets with their sha1 stamped filenames.

Multiple assets can also be concatenated into a single file (useful for CSS and JavaScript).

Before & After All Hooks

before_all do
  # called exactly once before all files are rendered
end

after_all do
  # called exactly once after all files are rendered
end

before_all and after_all are similar to the before method, except they're hooked into site-wide creation instead of each single file.

Blogs

# controller.rb
Homeostasis::Blog.config(
  :directory => 'blog', # directory of posts, required
  :url => 'http://example.com', # site url, required
  :title => 'Blog Title',
  :desc => 'Blog Description for RSS feed')

# blog/yyyy-mm-dd-permalink.md
---
title: Post Title Goes Here
---
Post body goes here.

# blog/index.html.haml
- blog_posts.each do |post|
  %span.date post['date'].strftime("%m/%d/%Y")
  %a{:href => post['path']}= post['title']

Write your blog posts in markdown (or even Haml). Homeostasis will generate an RSS feed for you at /blog/rss.xml.

Templates also get access to a blog_posts method which includes a list of all posts.

Front-matter YAML

# controller.rb
Homeostasis::Front.config(matcher: /\.erb|\.haml|\.html|\.md$/)

# random haml file
---
title: Lorem Ipsum
desc:  Quick fox over lazy dog.
---
%div
  Page continues as normal here
%h1= front['title']
%p= front['desc']

Views and actions in controllers get access to the front method, a hash with access to the front-matter YAML of the current file.

There's also front_site, which provides site-wide access to all front-matter YAML.

By default, front-matter YAML is only checked on files with extensions: erb, haml, html, and md. You can configure this by using Homeostasis::Front#config.

Multi Templates

# example.html.md.erb
**Sample Markdown <%= 1 + 2 %>**

# public/example.html
<strong>Sample Markdown 3</strong>

Use multiple file extensions and have Tilt automatically process them. Files ending with .html.md.erb will be processed with ERB, followed by Markdown.

Sitemaps

# controller.rb
Homeostasis::Sitemap.config(
  url: 'http://example.com',  # required
  lastmod: false              # default is true
)

# view-file.html.haml
---
changefreq: monthly
priority: 0.9
private: false
---

A sitemap will be generated in public/sitemap.xml. Configuration is required.

Use private: true in a file's front-matter YAML to avoid generating an entry in the sitemap. You can also use changefreq and priority.

Trailing Slashes

# sample .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [R=permanent,L]

Turns every page into a directory with an index.html file, enforcing trailing slashes. This pairs well with the provided htaccess file.

For example: index.html =>index.html, blog.html => blog/index.html, about.html => about/index.html.


Homeostasis is released under the BSD License and developed by Hugh Bien.