Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created February 1, 2011 06:11
Show Gist options
  • Select an option

  • Save adamloving/805499 to your computer and use it in GitHub Desktop.

Select an option

Save adamloving/805499 to your computer and use it in GitHub Desktop.

Revisions

  1. adamloving revised this gist Mar 22, 2012. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions installer_controller.rb
    Original file line number Diff line number Diff line change
    @@ -28,4 +28,11 @@ def cache_manifest

    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
  2. adamloving created this gist Feb 1, 2011.
    31 changes: 31 additions & 0 deletions installer_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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
    end