lib/juicer/command/merge.rb in psyho_juicer-1.0.0 vs lib/juicer/command/merge.rb in psyho_juicer-1.0.7

- old
+ new

@@ -66,20 +66,25 @@ (" " * 37) + "css with this option in cases where files have other extensions.") { |type| @type = type.to_sym } opt.on("-h", "--hosts hosts", "Cycle asset hosts for referenced urls. Comma separated") { |hosts| @hosts = hosts.split(",") } opt.on("-l", "--local-hosts hosts", "Host names that are served from --document-root (can be given cache busters). Comma separated") do |hosts| @local_hosts = hosts.split(",") end - opt.on("", "--all-hosts-local", "Treat all hosts as local (ie served from --document-root") { |t| @local_hosts = @hosts } + opt.on("", "--all-hosts-local", "Treat all hosts as local (ie served from --document-root)") { @all_hosts_local = true } opt.on("-r", "--relative-urls", "Convert all referenced URLs to relative URLs. Requires --document-root if\n" + (" " * 37) + "absolute URLs are used. Only valid for CSS files") { |t| @relative_urls = true } opt.on("-b", "--absolute-urls", "Convert all referenced URLs to absolute URLs. Requires --document-root.\n" + (" " * 37) + "Works with cycled asset hosts. Only valid for CSS files") { |t| @absolute_urls = true } opt.on("-d", "--document-root dir", "Path to resolve absolute URLs relative to") { |path| @document_root = path } - opt.on("-c", "--cache-buster type", "none, soft or hard. Default is soft, which adds timestamps to referenced\n" + - (" " * 37) + "URLs as query parameters. None leaves URLs untouched and hard alters file names") do |type| - @cache_buster = [:soft, :hard].include?(type.to_sym) ? type.to_sym : nil + opt.on("-c", "--cache-buster type", "none, soft, rails, or hard. Default is soft, which adds timestamps to\n" + + (" " * 37) + "reference URLs as query parameters. None leaves URLs untouched, rails adds\n" + + (" " * 37) + "timestamps in the same format as Rails' image_tag helper, and hard alters\n" + + (" " * 37) + "file names") do |type| + @cache_buster = [:soft, :hard, :rails].include?(type.to_sym) ? type.to_sym : nil end + opt.on("-C", "--cache-buster-format format", "Format of the cache buster. Allowed mtime (timestamp) and git (git commit hash). Default is mtime") do |format| + @cache_buster_format = (format.to_sym == :git) ? :git : :mtime + end opt.on("-e", "--embed-images type", "none or data_uri. Default is none. Data_uri embeds images using Base64 encoding\n" + (" " * 37) + "None leaves URLs untouched. Candiate images must be flagged with '?embed=true to be considered") do |embed| @image_embed_type = [:none, :data_uri].include?(embed.to_sym) ? embed.to_sym : nil end end @@ -91,10 +96,13 @@ if (files = files(args)).length == 0 @log.fatal "Please provide atleast one input file" raise SystemExit.new("Please provide atleast one input file") end + # Copy hosts to local_hosts if --all-hosts-local was specified + @local_hosts = @hosts if @all_hosts_local + # Figure out which file to output to output = output(files.first) # Warn if file already exists if File.exists?(output) && !@force @@ -178,18 +186,18 @@ # # Load cache buster, only available for CSS files # def cache_buster(file) return nil if !file || file !~ /\.css$/ || @cache_buster.nil? - Juicer::CssCacheBuster.new(:document_root => @document_root, :type => @cache_buster, :hosts => @local_hosts) + Juicer::CssCacheBuster.new(:document_root => @document_root, :type => @cache_buster, :hosts => @local_hosts, :format => @cache_buster_format) end # # Load image embed, only available for CSS files # def image_embed(file) return nil if !file || file !~ /\.css$/ || @image_embed_type.nil? - Juicer::ImageEmbed.new( :type => @image_embed_type ) + Juicer::ImageEmbed.new(:document_root => @document_root, :type => @image_embed_type ) end # # Generate output file name. Optional argument is a filename to base the new # name on. It will prepend the original suffix with ".min"