Created
March 21, 2012 03:52
-
-
Save STRd6/2144124 to your computer and use it in GitHub Desktop.
Generate that hmtl5 manifest crap. I just copied this from somewhur.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Set the local path to loop through | |
# Relative paths are fine. End with a slash. | |
PATH = "./" | |
# Set the file types to look for | |
FILE_TYPES = "css,jpg,png,html,js,svg,ttf,woff" | |
IGNORE_FILES = [""] | |
# Set the name of the created file | |
OUTPUT = "mobile.appcache" | |
# Get an array of the files | |
files = Dir.glob(PATH + "**/*.{" + FILE_TYPES + "}") | |
# Check if we have any files | |
if files.length == 0 | |
puts "No files found." | |
Process.exit | |
else | |
puts files.length.to_s + " files found." | |
end | |
# Start the cache manifest | |
contents = "CACHE MANIFEST\n" | |
contents += "# Generated at " + Time.now.to_s + "\n\n" | |
contents += "CACHE:\n" | |
# Loop through the files | |
files.each do |file| | |
filename = file.sub(PATH, "") | |
unless IGNORE_FILES.include?(filename) | |
contents += filename + "\n" | |
end | |
end | |
# Add the FALLBACK | |
contents += "\nFALLBACK:\n" | |
contents += "# For example:\n" | |
contents += "# / /offline.html\n" | |
# Add the NETWORK | |
contents += "\nNETWORK:\n" | |
contents += "*\n" | |
# Write it out to disk | |
File.open(OUTPUT, "w") {|f| f.write(contents) } | |
# Show a message to the user | |
puts "Cache-manifest '" + OUTPUT + "' was created successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment