Skip to content

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

Notifications You must be signed in to change notification settings

chilian/sinatra-static

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%