lib/palimpsest/assets.rb in palimpsest-0.0.1 vs lib/palimpsest/assets.rb in palimpsest-0.1.0

- old
+ new

@@ -27,10 +27,13 @@ cdn: '', # keyword to use in asset tag for inline assets inline: 'inline', + # if true, use sprockets-image_compressor with pngcrush and jpegoptim + image_compression: false, + # if true, also generate a gzipped asset gzip: false, # include hash in asset name hash: true, @@ -38,11 +41,11 @@ # opening and closing brackets for asset source tags src_pre: '[%', src_post: '%]', # allowed options for `Sprockets::Environment` - sprockets_options: [ :js_compressor, :css_compressor ] + sprockets_options: [:js_compressor, :css_compressor] } # @!attribute directory # @return [String] directory which all paths will be relative to if set # @@ -76,20 +79,25 @@ # Values are loaded from {#options}. def load_options options[:sprockets_options].each do |opt| sprockets.send "#{opt}=".to_sym, options[opt] if options[opt] end - return self + + if options[:image_compression] + Sprockets::ImageCompressor::Integration.setup sprockets + end + + self end # Load paths into the sprockets environment. # Values are loaded from {#paths}. def load_paths paths.each do |path| sprockets.append_path "#{directory + '/' unless directory.empty?}#{path}" end - return self + self end # @return [Sprockets::Environment] sprockets environment with {#options} and {#paths} loaded def assets unless @loaded @@ -163,18 +171,18 @@ # @param path [String] where to look for source files # @param type [String, nil] only look for asset tags with this type (or any type if `nil`) # @param options [Hash] merged with {DEFAULT_OPTIONS} # (see #find_tags) def self.find_tags path, type=nil, options={} - raise ArgumentError, 'path cannot be empty' if path.empty? + fail ArgumentError, 'path cannot be empty' if path.empty? options = DEFAULT_OPTIONS.merge options pre = Regexp.escape options[:src_pre] post= Regexp.escape options[:src_post] - cmd = [ 'grep' ] - cmd.concat [ '-l', '-I', '-r', '-E' ] - cmd << \ + cmd = ['grep'] + cmd.concat %w(-l -I -r -E) + cmd << if type.nil? pre + '(.*?)' + post else pre + '\s+' + type.to_s + '\s+(.*?)' + post end