开发者

how to change default behaviour of rack offline

开发者 https://www.devze.com 2023-02-09 05:35 出处:网络
I am trying to use rack offline in rials to make my webpage available offline. By default rack offline takes all files from the public folder into the cache manifest. In which file should I make chang

I am trying to use rack offline in rials to make my webpage available offline. By default rack offline takes all files from the public folder into the cache manifest. In which file should I make changes so that it will take the add the file that I want into the cache manifest. I want to incl开发者_Python百科ude the file in my views folder.


You need to add it to your routes.rb file. Here is my routes.rb file with a customized manifest. This will give you the index and the new routes as well as all of the html files in your public root (*.html) and every file in a sub-folder to public (*/*.*). You can slice and dice that however you need it for stuff in the public folder.

I don't know how to get the database specific routes like show and edit while offline. I would imagine Javascript is needed. Check out Railscast episode 248 for some ideas for integrating JS

OfflineConfirm::Application.routes.draw do
  #match '/application.manifest' => Rails::Offline
  resources :contacts

  offline = Rack::Offline.configure do
    cache ["contacts/new", "contacts"]
    public_path = Rails.root.join("public")
    Dir[public_path.join("*.html"),
        public_path.join("*/*.*")].each do |file|
      p = Pathname.new(file)
      cache p.relative_path_from(public_path)
    end

    network "/"
  end

  match '/application.manifest' => offline
end

The routes file above will produce the following application.manifest

CACHE MANIFEST
# 700ae3e3002382cb98b93c299d7b7bda151183b4703ef65d4c46b0ecf9c46093
contacts/new
contacts
404.html
422.html
500.html
index.html
images/rails.png
javascripts/application.js
javascripts/jquery.js
javascripts/jquery.min.js
javascripts/rails.js
stylesheets/scaffold.css

NETWORK:
/


None of the files in your views folder are available without a server. You want to make a route available in the cache manifest? For instance "/about", which corresponds to a "views/about.haml" file for instance?

Add this to your config:

offline = Rack::Offline.configure do
  cache "about" # or whatever your route is
  public_path = Rails.public_path
  Dir[public_path.join("javascripts/*.js")].each do |file|
    cache file.relative_path_from(public_path)
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消