This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Google Gears Manifest Generator
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
One of the modules that makes up Google Gears is the LocalServer that allows you to capture web resources so they can be served up when a user is offline.
The ManagedResourceStore component allows you to declare which resources you want the LocalServer to capture for you. You use a simple JSON manifest file that you can maintain with any text editor.
However, if your application gets large (lots of resources) you may not want to manage it in this way, so I created an open source Ruby library that allows me to generate this file given some rules:
For example, this will generate the manifest as a json string, and create entries using the current directory and sucking in everything apart from files starting with a '.'.
# Defaults to '.'
find_entries :ignore => Google::Gears::LocalServer::Manifest::LEADING_PERIOD
# Only capture HTML pages
find_entries :include => '\.html'
# Look in the resources subdirectory, but use the URL 'static'. This is useful if your directory on disk doesn't match your URLs
find_entries :in => 'resources', :root => 'static'
Once you have created the entries, you may want to add some metadata to a few of them. This is where add_extra_info comes in:
# Find the 'main.html' entry and add a redirect. You can also use a different :src or :ignore_query.
add_extra_info :to => 'main.html', :redirect => 'foo_redirect.html'
You can also create a manifest object (instead of using the block version) if you need to add a few things, get the output, add a few more, etc etc.
If you find yourself not wanting to manage your Manifest file, check out the project.