compressor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +29 -0
  3. data/lib/compressor.rb +95 -0
  4. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe6408879a8b5700850aa9cab175d3f3af75a669
4
+ data.tar.gz: 1fe8fea3ba49445a9f2ce468aee76f2b7e9103fc
5
+ SHA512:
6
+ metadata.gz: a8d91ccfadd2b7d8f973d039eefe74adf96f5c104ed78b8dc7229f526bea2dbdf10ec6790e581dbf0384d40761210eba0bd2f852b6e641761c16dfee7f483f0a
7
+ data.tar.gz: 40018f8339521dacc20eeda4a780762b5fe00adb2dcf60eaded634245ce903dc51e8c2edd938fff2a2ccf98146425c48e7586adc074a127538e5f9acaf37a55d
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # compressor
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'compressor'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install compressor
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/lib/compressor.rb ADDED
@@ -0,0 +1,95 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ module Motion::Project
8
+ class Config
9
+ def concat_files(opts={})
10
+ files_to_concatenate = extract_concatenated_files(Array(opts[:exclude]))
11
+ concatenate_files!(files_to_concatenate, opts[:parallel] || 4)
12
+ end
13
+
14
+ private
15
+
16
+ def extract_concatenated_files(excluded=[])
17
+ @files.flatten!
18
+ @concatenated_files = @files.select { |f| excluded.none? { |excluded_match| !!f.match(excluded_match) } }
19
+ @files = @files - @concatenated_files
20
+ @concatenated_files = order_concatenated_files(@concatenated_files)
21
+ end
22
+
23
+ def order_concatenated_files(concatenated_files)
24
+ concatenated_files.map { |file| file_dependencies(file) }.flatten.uniq
25
+ end
26
+
27
+ def concatenate_files!(concat_files, parallel=4)
28
+ group_number = 1
29
+ concat_files.in_groups(parallel, false) do |group|
30
+ concat_path = File.join(File.expand_path(@project_dir), "build", "app-concatenated-#{group_number}.rb")
31
+ File.delete(concat_path) if File.exist?(concat_path)
32
+ Motion::Project::App.info "Concat", concat_path
33
+
34
+ File.open(concat_path, 'a') do |concat|
35
+ group.each do |filename|
36
+ concat << "# #{"=" * filename.length}\n"
37
+ concat << "# #{filename}\n"
38
+ concat << "# #{"=" * filename.length}\n"
39
+ concat << File.read(filename)
40
+ concat << "\n"
41
+ end
42
+ end
43
+ @files << concat_path
44
+ group_number += 1
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
51
+ class Array
52
+ # Splits or iterates over the array in +number+ of groups, padding any
53
+ # remaining slots with +fill_with+ unless it is +false+.
54
+ #
55
+ # %w(1 2 3 4 5 6 7 8 9 10).in_groups(3) {|group| p group}
56
+ # ["1", "2", "3", "4"]
57
+ # ["5", "6", "7", nil]
58
+ # ["8", "9", "10", nil]
59
+ #
60
+ # %w(1 2 3 4 5 6 7 8 9 10).in_groups(3, '&nbsp;') {|group| p group}
61
+ # ["1", "2", "3", "4"]
62
+ # ["5", "6", "7", "&nbsp;"]
63
+ # ["8", "9", "10", "&nbsp;"]
64
+ #
65
+ # %w(1 2 3 4 5 6 7).in_groups(3, false) {|group| p group}
66
+ # ["1", "2", "3"]
67
+ # ["4", "5"]
68
+ # ["6", "7"]
69
+ def in_groups(number, fill_with = nil)
70
+ # size / number gives minor group size;
71
+ # size % number gives how many objects need extra accommodation;
72
+ # each group hold either division or division + 1 items.
73
+ division = size.div number
74
+ modulo = size % number
75
+
76
+ # create a new array avoiding dup
77
+ groups = []
78
+ start = 0
79
+
80
+ number.times do |index|
81
+ length = division + (modulo > 0 && modulo > index ? 1 : 0)
82
+ groups << last_group = slice(start, length)
83
+ last_group << fill_with if fill_with != false &&
84
+ modulo > 0 && length == division
85
+ start += length
86
+ end
87
+
88
+ if block_given?
89
+ groups.each { |g| yield(g) }
90
+ else
91
+ groups
92
+ end
93
+ end
94
+ end
95
+
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compressor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jamon Holmgren
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Concatenates your RubyMotion files so they build much faster than they
28
+ normally would.
29
+ email:
30
+ - jamon@clearsightstudio.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - lib/compressor.rb
37
+ homepage: https://github.com/jamonholmgren/compressor
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.4.6
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Concatenates your RubyMotion files so they build much faster.
61
+ test_files: []