Skip to content

Instantly share code, notes, and snippets.

@jnstq
Forked from adamloving/installer_controller.rb
Created March 23, 2023 20:09
Show Gist options
  • Save jnstq/c43342fbae2bc321f6180a4286842b05 to your computer and use it in GitHub Desktop.
Save jnstq/c43342fbae2bc321f6180a4286842b05 to your computer and use it in GitHub Desktop.
Rails controller action for an HTML5 cache manifest file.
class InstallerController < ApplicationController
# Rails controller action for an HTML5 cache manifest file.
# Generates a plain text list of files that changes
# when one of the listed files change...
# So the client knows when to refresh its cache.
def cache_manifest
@files = ["CACHE MANIFEST\n"]
@files << 'favicon.ico'
@files << './client/sencha/ext-touch.js'
@files << './client/sencha/resources/css/apple.css'
add_from('./client/views/','*.html')
add_from('./client/javascripts/','*.js')
add_from('./client/stylesheets/','*.css')
add_from('./client/images/','*.png')
@files << "\nNETWORK:"
@files << '*'
digest = Digest::SHA1.new
@files.each do |f|
actual_file = File.join(Rails.root,'public',f)
digest << "##{File.mtime(actual_file)}" if File.exist?(actual_file)
end
@files << "\n# Modification Digest: #{digest.hexdigest}"
render :text => @files.join("\n"), :content_type => 'text/cache-manifest', :layout => nil
end
protected
def add_from(loc,match)
Dir.glob(File.join(Rails.root,'public',loc, match)) do |file|
@files << "#{loc}#{File.basename(file)}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment