This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Middleman 3 Cheatsheet

A quick reference guide for Middleman v3: static site generator configuration, Compass, asset pipelines, page layout routing, and build optimizations.

· Published

[!NOTE] Archived Version: This cheatsheet covers Middleman v3. For newer installations, refer to Middleman v4+ documentation.

Middleman is a static site generator written in Ruby using modern web development shortcuts and standards.

Configuration (config.rb)

Directories & Assets

set :css_dir, "stylesheets"
set :js_dir, "javascripts"
set :images_dir, "images"

# Automatic image dimension tags on image_tag helper
activate :automatic_image_sizes

Compass Integration

compass_config do |config|
  config.output_style = :compact
end

Page Routing & Layouts

# Disable layout for raw HTML or XML templates
page "/sitemap.xml", layout: false

# Assign alternate layout
page "/admin/*", layout: :admin_layout

# Group multiple paths under one layout
with_layout :docs do
  page "/guides/*"
  page "/api/*"
end

# Fake proxy pages
page "/about.html", proxy: "/template-page.html" do
  @page_title = "About Us"
end

Custom Helpers

helpers do
  def format_currency(amount)
    "$%.2f" % amount
  end
end

Build Configuration

Optimize assets only when running middleman build:

configure :build do
  activate :minify_css
  activate :minify_javascript
  activate :cache_buster
  activate :relative_assets

  # Prefix assets with custom CDN path
  # set :http_path, "https://cdn.example.com/"
end

References

Related topics