albacore 2.0.0.rc.8 → 2.0.0.rc.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -308,6 +308,28 @@ filesystem:
308
308
  + Files not in src/MyMvcSite/MyMvcSite.csproj but on filesystem:
309
309
  file_missing_in_csproj.png
310
310
 
311
+ ## Docs: Zippy
312
+
313
+ This is a simple example which uses rubyzip to recursively generate a zip file
314
+ from the contents of a specified directory. The directory itself is not included
315
+ in the archive, rather just its contents.
316
+
317
+ Usage:
318
+
319
+ ```
320
+ dir_to_zip = "/tmp/input"
321
+ out_file = "/tmp/out.zip"
322
+ zf = Zippy.new dir_to_zip, out_file
323
+ zf.write
324
+ ```
325
+
326
+ Or:
327
+
328
+ ```
329
+ z = Zippy.new(directory_to_zip, output_file) { |f| f.include? 'html' }
330
+ z.write
331
+ ```
332
+
311
333
  ## Ideas:
312
334
 
313
335
  When building multiple configurations,
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ require 'zip'
3
+ require "albacore"
4
+
5
+ # https://github.com/aussiegeek/rubyzip/blob/master/samples/example_recursive.rb
6
+ # This is a simple example which uses rubyzip to
7
+ # recursively generate a zip file from the contents of
8
+ # a specified directory. The directory itself is not
9
+ # included in the archive, rather just its contents.
10
+ #
11
+ # Usage:
12
+ # dir_to_zip = "/tmp/input"
13
+ # out_file = "/tmp/out.zip"
14
+ # zf = Zippy.new dir_to_zip, out_file
15
+ # zf.write
16
+ #
17
+ # Or:
18
+ # z = Zippy.new(directory_to_zip, output_file) { |f| f.include? 'html' }
19
+ # z.write
20
+ class Zippy
21
+
22
+ # Initialize with the directory to zip and the location of the output archive.
23
+ #
24
+ # @param [String] input_dir The location to zip as a file system relative or
25
+ # absolute path
26
+ #
27
+ # @param [String] out_file The path of the output zip file that is generated.
28
+ # @param [Block] filter An optional block with a filter that is to return true
29
+ # if the file is to be added.
30
+ def initialize input_dir, out_file, &filter
31
+ @input_dir = input_dir.
32
+ gsub(/[\/\\]$/, '').
33
+ gsub(/\\/, '/')
34
+ @out_file = out_file
35
+ @filter = block_given? ? filter : lambda { |f| true }
36
+ end
37
+
38
+ # Zips the input directory.
39
+ def write
40
+ FileUtils.rm @out_file if File.exists? @out_file
41
+ in_progress "Writing archive #{@out_file} from #{@input_dir}" do
42
+ Zip::File.open @out_file, Zip::File::CREATE do |zipfile|
43
+ Dir["#{@input_dir}/**/**"].reject{ |f| f == @out_file || !@filter.call(f) }.each do |file|
44
+ progress "deflating #{file}"
45
+ zipfile.add(file.sub(@input_dir + '/', ''), file)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+ def in_progress msg, &block
53
+ Albacore.publish :start_progress, OpenStruct.new(:message => msg)
54
+ yield
55
+ Albacore.publish :finish_progress, OpenStruct.new(:message => msg)
56
+ end
57
+
58
+ def progress msg
59
+ Albacore.publish :progress, OpenStruct.new(:message => msg)
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module Albacore
2
- VERSION = "2.0.0.rc.8"
2
+ VERSION = "2.0.0.rc.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: albacore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc.8
4
+ version: 2.0.0.rc.9
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-10 00:00:00.000000000 Z
13
+ date: 2014-03-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -214,6 +214,7 @@ files:
214
214
  - lib/albacore/tools.rb
215
215
  - lib/albacore/tools/fluent_migrator.rb
216
216
  - lib/albacore/tools/restore_hint_paths.rb
217
+ - lib/albacore/tools/zippy.rb
217
218
  - lib/albacore/version.rb
218
219
  - spec/Rakefile
219
220
  - spec/albacore_spec.rb
@@ -316,7 +317,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
316
317
  version: '0'
317
318
  segments:
318
319
  - 0
319
- hash: 3238636988153789761
320
+ hash: -3459761293197322545
320
321
  required_rubygems_version: !ruby/object:Gem::Requirement
321
322
  none: false
322
323
  requirements: