Class: Middleman::AppCacheExtension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::AppCacheExtension
- Defined in:
- lib/middleman-appcache/extension.rb
Instance Method Summary collapse
-
#initialize(app, options_hash = {}, &block) ⇒ AppCacheExtension
constructor
A new instance of AppCacheExtension.
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ AppCacheExtension
Returns a new instance of AppCacheExtension.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/middleman-appcache/extension.rb', line 13 def initialize app, = {}, &block super cache_manifest_filename = .cache_manifest = .cache = .network = .fallback use_relative = .use_relative app.after_build do |builder| cache = [] .each do |cache_file_pattern| directory = File.join(config[:build_dir], cache_file_pattern) files_to_cache = Dir.glob(directory) files_to_cache.each do |file_to_cache| build_dir = config[:build_dir] build_dir = "#{build_dir}/" if use_relative cache << file_to_cache.gsub(build_dir, '') end end manifest_file = File.join(config[:build_dir], cache_manifest_filename) File.open(manifest_file, "w") do |f| f.write "CACHE MANIFEST\n\n" f.write "CACHE:\n" cache.each do |cache_file| f.write "#{cache_file}\n" end f.write "\n" if .any? f.write "NETWORK:\n" .each do |network_url| f.write "#{network_url}\n" end f.write "\n" end if .any? f.write "FALLBACK:\n" .each do |url, fallback_resource| f.write "#{url} #{fallback_resource}\n" end f.write "\n" end end builder.say_status :regenerated, cache_manifest_filename end end |