Loading Rakefile +4 −19 Original line number Diff line number Diff line require 'rubygems' require 'rake' require 'digest/md5' $LOAD_PATH.unshift File.expand_path("../lib", __FILE__) require 'jsduck/util/md5' def os_is_windows? RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ end Loading Loading @@ -41,22 +42,6 @@ def yui_compress(fname) system "java -jar $(dirname $(which sencha))/bin/yuicompressor.jar -o #{fname} #{fname}" end # Calculates MD5 hash of a file and renames the file to contain the # hash inside the filename. def md5_rename(fname) hash = Digest::MD5.file(fname).hexdigest hashed_name = inject_hash_to_filename(fname, hash) File.rename(fname, hashed_name) return hashed_name end # Given filename "foo/bar.js" and hash "HASH" produces "foo/bar-HASH.js" def inject_hash_to_filename(fname, hash) parts = File.basename(fname).split(/\./) parts[0] += "-" + hash File.dirname(fname) + "/" + parts.join(".") end # Reads in all CSS files referenced between BEGIN CSS and END CSS markers. # Deletes those input CSS files and writes out concatenated CSS to # resources/css/app.css Loading @@ -76,7 +61,7 @@ def combine_css(html, dir, opts = :write) if opts == :write File.open(fname, 'w') {|f| f.write(css.join("\n")) } yui_compress(fname) fname = md5_rename(fname) fname = JsDuck::Util::MD5.rename(fname) end html.sub(css_section_re, '<link rel="stylesheet" href="resources/css/' + File.basename(fname) + '" type="text/css" />') end Loading @@ -101,7 +86,7 @@ def combine_js(html, dir) File.open(fname, 'w') {|f| f.write(js.join("\n")) } yui_compress(fname) fname = md5_rename(fname) fname = JsDuck::Util::MD5.rename(fname) html.sub(js_section_re, '<script type="text/javascript" src="' + File.basename(fname) + '"></script>') end Loading lib/jsduck/util/md5.rb 0 → 100644 +32 −0 Original line number Diff line number Diff line require 'digest/md5' require 'jsduck/util/singleton' module JsDuck module Util # Helper to rename files so that the MD5 hash of their contents is # placed into their name. class MD5 include Util::Singleton # Calculates MD5 hash of a file and renames the file to contain the # hash inside the filename. Returns the new name of the file. def rename(fname) hash = Digest::MD5.file(fname).hexdigest hashed_name = inject_hash_to_filename(fname, hash) File.rename(fname, hashed_name) return hashed_name end private # Given filename "foo/bar.js" and hash "HASH" produces "foo/bar-HASH.js" def inject_hash_to_filename(fname, hash) parts = File.basename(fname).split(/\./) parts[0] += "-" + hash File.dirname(fname) + "/" + parts.join(".") end end end end Loading
Rakefile +4 −19 Original line number Diff line number Diff line require 'rubygems' require 'rake' require 'digest/md5' $LOAD_PATH.unshift File.expand_path("../lib", __FILE__) require 'jsduck/util/md5' def os_is_windows? RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ end Loading Loading @@ -41,22 +42,6 @@ def yui_compress(fname) system "java -jar $(dirname $(which sencha))/bin/yuicompressor.jar -o #{fname} #{fname}" end # Calculates MD5 hash of a file and renames the file to contain the # hash inside the filename. def md5_rename(fname) hash = Digest::MD5.file(fname).hexdigest hashed_name = inject_hash_to_filename(fname, hash) File.rename(fname, hashed_name) return hashed_name end # Given filename "foo/bar.js" and hash "HASH" produces "foo/bar-HASH.js" def inject_hash_to_filename(fname, hash) parts = File.basename(fname).split(/\./) parts[0] += "-" + hash File.dirname(fname) + "/" + parts.join(".") end # Reads in all CSS files referenced between BEGIN CSS and END CSS markers. # Deletes those input CSS files and writes out concatenated CSS to # resources/css/app.css Loading @@ -76,7 +61,7 @@ def combine_css(html, dir, opts = :write) if opts == :write File.open(fname, 'w') {|f| f.write(css.join("\n")) } yui_compress(fname) fname = md5_rename(fname) fname = JsDuck::Util::MD5.rename(fname) end html.sub(css_section_re, '<link rel="stylesheet" href="resources/css/' + File.basename(fname) + '" type="text/css" />') end Loading @@ -101,7 +86,7 @@ def combine_js(html, dir) File.open(fname, 'w') {|f| f.write(js.join("\n")) } yui_compress(fname) fname = md5_rename(fname) fname = JsDuck::Util::MD5.rename(fname) html.sub(js_section_re, '<script type="text/javascript" src="' + File.basename(fname) + '"></script>') end Loading
lib/jsduck/util/md5.rb 0 → 100644 +32 −0 Original line number Diff line number Diff line require 'digest/md5' require 'jsduck/util/singleton' module JsDuck module Util # Helper to rename files so that the MD5 hash of their contents is # placed into their name. class MD5 include Util::Singleton # Calculates MD5 hash of a file and renames the file to contain the # hash inside the filename. Returns the new name of the file. def rename(fname) hash = Digest::MD5.file(fname).hexdigest hashed_name = inject_hash_to_filename(fname, hash) File.rename(fname, hashed_name) return hashed_name end private # Given filename "foo/bar.js" and hash "HASH" produces "foo/bar-HASH.js" def inject_hash_to_filename(fname, hash) parts = File.basename(fname).split(/\./) parts[0] += "-" + hash File.dirname(fname) + "/" + parts.join(".") end end end end