Sha256: 92bcea63b1d5bb269f5491b5c54f4baffa9a0280581805f339f89d2c16b84b6d

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8
module Middleman
  module Presentation
    # Utils module
    module Utils
      # Create zip archive from directory
      #
      # @param [String] source_directory
      #   The source directory
      #
      # @param [String] destination_file
      #   The zip file which should be created
      #
      # @param [String] prefix
      #   A prefix for the zip file, e.g. dir1/dir2/ => dir1/dir2/zip_file.
      #   Please mind the trailing '/'.
      def zip(source_directory, destination_file, prefix: nil)
        Zip.setup do |c|
          c.on_exists_proc          = true
          c.continue_on_exists_proc = true
          c.unicode_names           = true
          c.default_compression     = Zlib::BEST_COMPRESSION
        end

        Zip::File.open(destination_file, Zip::File::CREATE) do |file|
          Dir.glob(File.join(source_directory, '**', '*')).each do |filename|

            path = ''
            path << prefix if prefix
            path << Pathname.new(filename).relative_path_from(Pathname.new(source_directory)).to_s

            file.add(path, filename)
          end
        end
      end

      module_function :zip
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleman-presentation-core-0.16.0.beta lib/middleman-presentation-core/utils.rb
middleman-presentation-core-0.16.0.alpha lib/middleman-presentation-core/utils.rb