Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

turn your sinatra app into a static website (<75loc)

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 readme.rdoc
Octocat-spinner-32 sinatra-static.gemspec
readme.rdoc

sinatra-static

export your sinatra app to a directory of static files. requires “sinatra-advanced-routes”. get requests and response-status 200 only (no redirects). you also have to copy the public-dir yourself (if you're using it).

usage

require 'sinatra_static'

builder = SinatraStatic.new(MySinatraApp)
builder.build!('/Users/paul/my_static_site')

example

this simple app:

require 'sinatra'
require "sinatra/advanced_routes"
require 'sinatra_static'

class MyApp::App < Sinatra::Base  

  get '/' do    
    "my homepage"
  end

  get '/blog' do
    "blog index"
  end

  get '/blog/ajax.html' do
    "blog index w/o layout"
  end

  %w(page1 page2 page3).each do |page|
    get "/blog/#{page}" do
      "blog page: #{page}"
    end
  end

  get '/dynamic.js' do
    "my generated javascript"
  end

  get '/data.json' do
    "my generated json"
  end

end

builder = SinatraStatic.new(MyApp:App)
builder.build!('/Users/paul/my_static_site')

will generate this output:

~/my_static_site/index.html              -> "my homepage"
~/my_static_site/blog/index.html         -> "blog index"
~/my_static_site/blog/ajax.html          -> "blog index w/o layout"
~/my_static_site/blog/page1/index.html   -> "blog page: page1"
~/my_static_site/blog/page2/index.html   -> "blog page: page2"
~/my_static_site/blog/page3/index.html   -> "blog page: page3"
~/my_static_site/dynamic.js              -> "my generated javascript"
~/my_static_site/data.json               -> "my generated json"

installation

gem install sinatra-static

or in your Gemfile

gem 'sinatra-static', '>= 0.1.1'
Something went wrong with that request. Please try again.