Skip to content

Commit

Permalink
HTML5 manifest builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Onar Vikingstad authored and Charles Jolley committed Feb 11, 2010
1 parent b040609 commit e1b3304
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions lib/sproutcore/builders/html5_manifest.rb
@@ -0,0 +1,78 @@
# ===========================================================================
# Project: Abbot - SproutCore Build Tools
# Copyright: ©2010 Apple Inc.
# portions copyright @2006-2009 Sprout Systems, Inc.
# and contributors
# ===========================================================================

require File.expand_path(File.join(File.dirname(__FILE__), 'base'))
require 'fileutils'

module SC

# This builder combines several javascript files into a single file. It is
# used to prepare a single javascript file for production use. This build
# tool expects the javascript files to have already been processed for any
# build directives such sc_static().
#
class Builder::HTML5Manifest < Builder::Base

def build(dst_path)
@files = []

@files << "CACHE MANIFEST\n# List of all resources required by this project\n"

path = dst_path.split('/tmp/build')
inspect_files(path[0] + '/tmp/build', path[1])

#puts CONFIG.html5_manifest
#networks = CONFIG.html5_manifest_networks
#if networks
# @files << "\n\nNETWORK:"
# networks.each do |network|
# @files << network
# end
#end

manifest_path = dst_path.sub('index.html', '') + 'app.manifest'
puts manifest_path
writelines manifest_path, @files
end

def joinlines(lines)
lines.join("\n")
end

def inspect_files(base_path, dst_path)
path = base_path + dst_path
content = readlines(path)

content.each do |line|
line.scan(/['"]([^\s]+?(?=\.(css|js|png|gif))\.\2)['"]/) do |x, y, z|
file_location = x
# in case of hyperdomaining, strip off the http part and then look
# for the file
if x[0,4] == 'http'
file_location = '/' + x.gsub(/http\:\/\/.*?\//, '')
end

next unless File.exist?(base_path + file_location)

if !@files.include?(x)
@files << x
end

if y == 'css' || y == 'js'
inspect_files(base_path, file_location)
end

end
end

@files

end

end

end

0 comments on commit e1b3304

Please sign in to comment.