Permalink
Browse files

HTML5 manifest builder

  • Loading branch information...
1 parent b040609 commit e1b33040fb2b3b431f7e1de17a6757c321937dc7 Onar Vikingstad committed with Charles Jolley Feb 3, 2010
Showing with 78 additions and 0 deletions.
  1. +78 −0 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.