John Topley’s Weblog

Announcing Manifesto

I’ve just released my first ever RubyGem. It’s a simple gem named Manifesto that dynamically generates an HTML 5 cache manifest for offline application caching. I got the idea whilst developing my Truth Tables Sinatra micro web application. It returns a list of files within the specified directory and sub-directories. By default it also includes a computed hash of the files' contents, so that if a file is changed a different hash is produced, causing the cache to be automatically invalidated.

Installation

To install the gem, use:

[sudo] gem install manifesto

Usage

# Basic usage, list all non-hidden files in ./public and include
# a computed hash of their contents
Manifesto.cache

# Specify a directory
Manifesto.cache :directory => './mobile'

# Specify a directory and don't compute the hash
Manifesto.cache :directory => './mobile', :compute_hash => false

Sample Output

CACHE MANIFEST
# Generated by manifesto (http://github.com/johntopley/manifesto)
# Hash: 7013a3b8292ceeeb6336849bee1d1365
/apple-touch-icon.png
/apple-touch-startup.png
/index.html
/mobile/mobile.css
/mobile/mobile.js

Sinatra Example

require 'manifesto.rb'

get '/manifest' do
  # Must be served with this MIME type
  headers 'Content-Type' => 'text/cache-manifest' 
  Manifesto.cache
end

Ruby on Rails Example

# Create a Rails 2.x route for the manifest
map.manifest '/manifest', :controller => 'manifest', :action => 'show'

# ...or a Rails 3.x route
match '/manifest' => 'manifest#show'

# Create a controller action
def show
  headers['Content-Type'] = 'text/cache-manifest'
  render :text => Manifesto.cache, :layout => false
end

Enjoy!

Comments

There aren’t any comments on this post. Comments are closed.

I’ve just released my first ever RubyGem.


Archives

  • Jan
  • Feb
  • Mar
  • Apr
  • May
  • Jun
  • Jul
  • Aug
  • Sep
  • Oct
  • Nov
  • Dec
  • 2019
  • 2018
  • 2017
  • 2016
  • 2015
  • 2014

More Archives


Sign In