oily_png 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ Makefile
2
+ /conftest.dSYM
3
+ /*.bundle
4
+ /*.o
5
+ /.bundle/
6
+ /pkg
7
+ oily_png-*.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubyforge
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oily_png (0.0.2)
5
+ chunky_png (~> 0.10.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ chunky_png (0.10.1)
11
+ rake (0.8.7)
12
+ rspec (1.3.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ chunky_png (~> 0.10.1)
19
+ oily_png!
20
+ rake
21
+ rspec (>= 1.3)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Willem van Bergen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ === OilyPNG
2
+
3
+ Native module to speed up ChunkyPNG.
4
+
5
+ * Install this gem
6
+ * Use require "oily_png" instead of require"chunky_png"
7
+ * Use the ChunkyPNG API as you normally would.
8
+ * Presto!
9
+
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup
5
+
6
+ Dir['tasks/*.rake'].each { |file| load(file) }
7
+
8
+ GithubGem::RakeTasks.new(:gem)
9
+ task :default => [:spec]
@@ -0,0 +1,151 @@
1
+ #include "ruby.h"
2
+
3
+ // Variable for the OilyPNG module
4
+ VALUE OilyPNG = Qnil;
5
+
6
+ void Init_decoding();
7
+
8
+ VALUE oily_png_decode_png_image_pass(VALUE self, VALUE stream, VALUE width, VALUE height, VALUE color_mode, VALUE start_pos);
9
+
10
+ // COLOR_GRAYSCALE = 0
11
+ // COLOR_TRUECOLOR = 2
12
+ // COLOR_INDEXED = 3
13
+ // COLOR_GRAYSCALE_ALPHA = 4
14
+ // COLOR_TRUECOLOR_ALPHA = 6
15
+ //
16
+ // FILTERING_DEFAULT = 0
17
+ //
18
+ // COMPRESSION_DEFAULT = 0
19
+ //
20
+ // INTERLACING_NONE = 0
21
+ // INTERLACING_ADAM7 = 1
22
+ //
23
+ // FILTER_NONE = 0
24
+ // FILTER_SUB = 1
25
+ // FILTER_UP = 2
26
+ // FILTER_AVERAGE = 3
27
+ // FILTER_PAETH = 4
28
+
29
+ void Init_decoding() {
30
+ VALUE OilyPNG = rb_define_module("OilyPNG");
31
+ VALUE OilyPNGDecoding = rb_define_module_under(OilyPNG, "PNGDecoding");
32
+ rb_define_method(OilyPNGDecoding, "decode_png_image_pass", oily_png_decode_png_image_pass, 5);
33
+ }
34
+
35
+ int oily_png_pixel_size(color_mode) {
36
+ switch (color_mode) {
37
+ case 0: return 1;
38
+ case 2: return 3;
39
+ case 3: return 1;
40
+ case 4: return 2;
41
+ case 6: return 4;
42
+ default: return -1;
43
+ }
44
+ }
45
+
46
+ unsigned int oily_png_decode_pixel(int color_mode, unsigned char* bytes, int byte_index, VALUE decoding_palette) {
47
+ switch (color_mode) {
48
+ case 0:
49
+ return (bytes[byte_index] << 24) + (bytes[byte_index] << 16) + (bytes[byte_index] << 8) + 0xff;
50
+ case 2:
51
+ return (bytes[byte_index] << 24) + (bytes[byte_index + 1] << 16) + (bytes[byte_index + 2] << 8) + 0xff;
52
+ case 3:
53
+ return NUM2UINT(rb_funcall(decoding_palette, rb_intern("[]"), 1, INT2FIX(bytes[byte_index])));
54
+ case 4:
55
+ return (bytes[byte_index] << 24) + (bytes[byte_index] << 16) + (bytes[byte_index] << 8) + bytes[byte_index + 1];
56
+ case 6:
57
+ return (bytes[byte_index] << 24) + (bytes[byte_index + 1] << 16) + (bytes[byte_index + 2] << 8) + bytes[byte_index + 3];
58
+ default:
59
+ exit(1);
60
+ }
61
+ }
62
+
63
+ void oily_png_filter_sub(unsigned char* bytes, int pos, int line_length, int pixel_size) {
64
+ int i;
65
+ for (i = 1 + pixel_size; i < line_length; i++) {
66
+ bytes[pos + i] += bytes[pos + i - pixel_size]; // mod 256 ???
67
+ }
68
+ }
69
+
70
+ void oily_png_filter_up(unsigned char* bytes, int pos, int line_length, int pixel_size) {
71
+ int i;
72
+ if (pos >= line_length) {
73
+ for (i = 1; i < line_length; i++) {
74
+ bytes[pos + i] += bytes[pos + i - line_length]; // mod 256 ???
75
+ }
76
+ }
77
+ }
78
+
79
+ void oily_png_filter_average(unsigned char* bytes, int pos, int line_length, int pixel_size) {
80
+ int i;
81
+ unsigned char a, b;
82
+ for (i = 1; i < line_length; i++) {
83
+ a = (i > pixel_size) ? bytes[pos + i - pixel_size] : 0;
84
+ b = (pos >= line_length) ? bytes[pos + i - line_length] : 0;
85
+ bytes[pos + i] += (a + b) >> 1;
86
+ }
87
+ }
88
+
89
+ void oily_png_filter_paeth(unsigned char* bytes, int pos, int line_length, int pixel_size) {
90
+ unsigned char a, b, c, pr;
91
+ int i, p, pa, pb, pc;
92
+ for (i = 1; i < line_length; i++) {
93
+ a = (i > pixel_size) ? bytes[pos + i - pixel_size] : 0;
94
+ b = (pos >= line_length) ? bytes[pos + i - line_length] : 0;
95
+ c = (pos >= line_length && i > pixel_size) ? bytes[pos + i - line_length - pixel_size] : 0;
96
+ p = a + b - c;
97
+ pa = abs(p - a);
98
+ pb = abs(p - b);
99
+ pc = abs(p - c);
100
+ pr = (pa <= pb) ? (pa <= pc ? a : c) : (pb <= pc ? b : c);
101
+ bytes[pos + i] += pr;
102
+ }
103
+ }
104
+
105
+
106
+ VALUE oily_png_decode_png_image_pass(VALUE self, VALUE stream, VALUE width, VALUE height, VALUE color_mode, VALUE start_pos) {
107
+
108
+ int pixel_size = oily_png_pixel_size(FIX2INT(color_mode));
109
+ int line_size = pixel_size * FIX2INT(width) + 1;
110
+ int pass_size = line_size * FIX2INT(height);
111
+
112
+ VALUE pixels = rb_ary_new();
113
+
114
+ VALUE decoding_palette = Qnil;
115
+ if (FIX2INT(color_mode) == 3) {
116
+ decoding_palette = rb_funcall(self, rb_intern("decoding_palette"), 0);
117
+ }
118
+
119
+ unsigned char* pixelstream = RSTRING_PTR(stream);
120
+ unsigned char* bytes = malloc(pass_size);
121
+ memcpy(bytes, pixelstream + FIX2INT(start_pos), pass_size);
122
+
123
+ int y, x, line_start, prev_line_start, byte_index, pixel_index;
124
+ unsigned char filter;
125
+ unsigned int pixel;
126
+
127
+ for (y = 0; y < FIX2INT(height); y++) {
128
+ line_start = y * line_size;
129
+ filter = bytes[line_start];
130
+
131
+ switch (filter) {
132
+ case 0: break;
133
+ case 1: oily_png_filter_sub( bytes, line_start, line_size, pixel_size); break;
134
+ case 2: oily_png_filter_up( bytes, line_start, line_size, pixel_size); break;
135
+ case 3: oily_png_filter_average( bytes, line_start, line_size, pixel_size); break;
136
+ case 4: oily_png_filter_paeth( bytes, line_start, line_size, pixel_size); break;
137
+ default: exit(1);
138
+ }
139
+
140
+ for (x = 0; x < FIX2INT(width); x++) {
141
+ pixel_index = FIX2INT(width) * y + x;
142
+ byte_index = line_start + 1 + (x * pixel_size);
143
+ pixel = oily_png_decode_pixel(FIX2INT(color_mode), bytes, byte_index, decoding_palette);
144
+ rb_ary_store(pixels, pixel_index, INT2NUM(pixel));
145
+ }
146
+ }
147
+
148
+ free(bytes);
149
+ return rb_funcall(self, rb_intern("new"), 3, width, height, pixels);
150
+ }
151
+
@@ -0,0 +1,11 @@
1
+ # Loads mkmf which is used to make makefiles for Ruby extensions
2
+ require 'mkmf'
3
+
4
+ # paths = ['/opt/local', '/usr/local']
5
+ # lib_paths = paths.map { |p| p + '/lib' }
6
+ # inc_paths = paths.map { |p| p + '/include' }
7
+
8
+ # exit(1) unless find_library('png', 'png_get_io_ptr', *lib_paths) && find_header('png.h', *inc_paths)
9
+
10
+ # Create a makefile
11
+ create_makefile('oily_png/decoding')
@@ -0,0 +1,14 @@
1
+ require 'chunky_png'
2
+ require 'oily_png/decoding'
3
+
4
+ module OilyPNG
5
+
6
+ VERSION = "0.0.2"
7
+
8
+ def self.included(base)
9
+ base::Canvas.extend OilyPNG::PNGDecoding
10
+ end
11
+
12
+ end
13
+
14
+ ChunkyPNG.send(:include, OilyPNG)
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'oily_png'
3
+ s.rubyforge_project = s.name
4
+
5
+ # Do not change the version and date fields by hand. This will be done
6
+ # automatically by the gem release script.
7
+ s.version = "0.0.2"
8
+ s.date = "2010-10-05"
9
+
10
+ s.summary = "Native mixin to speed up ChunkyPNG"
11
+ s.description = <<-EOT
12
+ This Ruby C extenstion defines a module that can be included into ChunkyPNG to improve its speed.
13
+ EOT
14
+
15
+ s.authors = ['Willem van Bergen']
16
+ s.email = ['willem@railsdoctors.com']
17
+ s.homepage = 'http://wiki.github.com/wvanbergen/oily_png'
18
+
19
+ s.extensions = ["ext/oily_png/extconf.rb"]
20
+ s.require_paths = ["lib", "ext"]
21
+
22
+ s.required_rubygems_version = '1.3.7'
23
+ s.add_runtime_dependency('chunky_png', '~> 0.10.1')
24
+
25
+ s.add_development_dependency('rake')
26
+ s.add_development_dependency('rspec', '>= 1.3')
27
+
28
+ s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
29
+ s.extra_rdoc_files = ['README.rdoc']
30
+
31
+ # Do not change the files and test_files fields by hand. This will be done
32
+ # automatically by the gem release script.
33
+ s.files = %w(.gitignore Gemfile Gemfile.lock LICENSE README.rdoc Rakefile ext/oily_png/decoding.c ext/oily_png/extconf.rb lib/oily_png.rb oily_png.gemspec tasks/github-gem.rake)
34
+ s.test_files = %w()
35
+ end
@@ -0,0 +1,359 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+ require 'date'
5
+ require 'set'
6
+
7
+ module GithubGem
8
+
9
+ # Detects the gemspc file of this project using heuristics.
10
+ def self.detect_gemspec_file
11
+ FileList['*.gemspec'].first
12
+ end
13
+
14
+ # Detects the main include file of this project using heuristics
15
+ def self.detect_main_include
16
+ if detect_gemspec_file =~ /^(\.*)\.gemspec$/ && File.exist?("lib/#{$1}.rb")
17
+ "lib/#{$1}.rb"
18
+ elsif FileList['lib/*.rb'].length == 1
19
+ FileList['lib/*.rb'].first
20
+ else
21
+ nil
22
+ end
23
+ end
24
+
25
+ class RakeTasks
26
+
27
+ attr_reader :gemspec, :modified_files
28
+ attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
29
+
30
+ # Initializes the settings, yields itself for configuration
31
+ # and defines the rake tasks based on the gemspec file.
32
+ def initialize(task_namespace = :gem)
33
+ @gemspec_file = GithubGem.detect_gemspec_file
34
+ @task_namespace = task_namespace
35
+ @main_include = GithubGem.detect_main_include
36
+ @modified_files = Set.new
37
+ @root_dir = Dir.pwd
38
+ @test_pattern = 'test/**/*_test.rb'
39
+ @spec_pattern = 'spec/**/*_spec.rb'
40
+ @local_branch = 'master'
41
+ @remote = 'origin'
42
+ @remote_branch = 'master'
43
+
44
+ yield(self) if block_given?
45
+
46
+ load_gemspec!
47
+ define_tasks!
48
+ end
49
+
50
+ protected
51
+
52
+ def git
53
+ @git ||= ENV['GIT'] || 'git'
54
+ end
55
+
56
+ # Define Unit test tasks
57
+ def define_test_tasks!
58
+ require 'rake/testtask'
59
+
60
+ namespace(:test) do
61
+ Rake::TestTask.new(:basic) do |t|
62
+ t.pattern = test_pattern
63
+ t.verbose = true
64
+ t.libs << 'test'
65
+ end
66
+ end
67
+
68
+ desc "Run all unit tests for #{gemspec.name}"
69
+ task(:test => ['test:basic'])
70
+ end
71
+
72
+ # Defines RSpec tasks
73
+ def define_rspec_tasks!
74
+ require 'spec/rake/spectask'
75
+
76
+ namespace(:spec) do
77
+ desc "Verify all RSpec examples for #{gemspec.name}"
78
+ Spec::Rake::SpecTask.new(:basic) do |t|
79
+ t.spec_files = FileList[spec_pattern]
80
+ end
81
+
82
+ desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
83
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
84
+ t.spec_files = FileList[spec_pattern]
85
+ t.spec_opts << '--format' << 'specdoc' << '--color'
86
+ end
87
+
88
+ desc "Run RCov on specs for #{gemspec.name}"
89
+ Spec::Rake::SpecTask.new(:rcov) do |t|
90
+ t.spec_files = FileList[spec_pattern]
91
+ t.rcov = true
92
+ t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
93
+ end
94
+ end
95
+
96
+ desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
97
+ task(:spec => ['spec:specdoc'])
98
+ end
99
+
100
+ # Defines the rake tasks
101
+ def define_tasks!
102
+
103
+ define_test_tasks! if has_tests?
104
+ define_rspec_tasks! if has_specs?
105
+
106
+ namespace(@task_namespace) do
107
+ desc "Updates the filelist in the gemspec file"
108
+ task(:manifest) { manifest_task }
109
+
110
+ desc "Builds the .gem package"
111
+ task(:build => :manifest) { build_task }
112
+
113
+ desc "Sets the version of the gem in the gemspec"
114
+ task(:set_version => [:check_version, :check_current_branch]) { version_task }
115
+ task(:check_version => :fetch_origin) { check_version_task }
116
+
117
+ task(:fetch_origin) { fetch_origin_task }
118
+ task(:check_current_branch) { check_current_branch_task }
119
+ task(:check_clean_status) { check_clean_status_task }
120
+ task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
121
+
122
+ checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
123
+ checks.unshift('spec:basic') if has_specs?
124
+ checks.unshift('test:basic') if has_tests?
125
+ # checks.push << [:check_rubyforge] if gemspec.rubyforge_project
126
+
127
+ desc "Perform all checks that would occur before a release"
128
+ task(:release_checks => checks)
129
+
130
+ release_tasks = [:release_checks, :set_version, :build, :github_release, :gemcutter_release]
131
+ # release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
132
+
133
+ desc "Release a new version of the gem using the VERSION environment variable"
134
+ task(:release => release_tasks) { release_task }
135
+
136
+ namespace(:release) do
137
+ desc "Release the next version of the gem, by incrementing the last version segment by 1"
138
+ task(:next => [:next_version] + release_tasks) { release_task }
139
+
140
+ desc "Release the next version of the gem, using a patch increment (0.0.1)"
141
+ task(:patch => [:next_patch_version] + release_tasks) { release_task }
142
+
143
+ desc "Release the next version of the gem, using a minor increment (0.1.0)"
144
+ task(:minor => [:next_minor_version] + release_tasks) { release_task }
145
+
146
+ desc "Release the next version of the gem, using a major increment (1.0.0)"
147
+ task(:major => [:next_major_version] + release_tasks) { release_task }
148
+ end
149
+
150
+ # task(:check_rubyforge) { check_rubyforge_task }
151
+ # task(:rubyforge_release) { rubyforge_release_task }
152
+ task(:gemcutter_release) { gemcutter_release_task }
153
+ task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
154
+ task(:tag_version) { tag_version_task }
155
+ task(:commit_modified_files) { commit_modified_files_task }
156
+
157
+ task(:next_version) { next_version_task }
158
+ task(:next_patch_version) { next_version_task(:patch) }
159
+ task(:next_minor_version) { next_version_task(:minor) }
160
+ task(:next_major_version) { next_version_task(:major) }
161
+
162
+ desc "Updates the gem release tasks with the latest version on Github"
163
+ task(:update_tasks) { update_tasks_task }
164
+ end
165
+ end
166
+
167
+ # Updates the files list and test_files list in the gemspec file using the list of files
168
+ # in the repository and the spec/test file pattern.
169
+ def manifest_task
170
+ # Load all the gem's files using "git ls-files"
171
+ repository_files = `#{git} ls-files`.split("\n")
172
+ test_files = Dir[test_pattern] + Dir[spec_pattern]
173
+
174
+ update_gemspec(:files, repository_files)
175
+ update_gemspec(:test_files, repository_files & test_files)
176
+ end
177
+
178
+ # Builds the gem
179
+ def build_task
180
+ sh "gem build -q #{gemspec_file}"
181
+ Dir.mkdir('pkg') unless File.exist?('pkg')
182
+ sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
183
+ end
184
+
185
+ def newest_version
186
+ `#{git} tag`.split("\n").map { |tag| tag.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
187
+ end
188
+
189
+ def next_version(increment = nil)
190
+ next_version = newest_version.segments
191
+ increment_index = case increment
192
+ when :micro then 3
193
+ when :patch then 2
194
+ when :minor then 1
195
+ when :major then 0
196
+ else next_version.length - 1
197
+ end
198
+
199
+ next_version[increment_index] ||= 0
200
+ next_version[increment_index] = next_version[increment_index].succ
201
+ ((increment_index + 1)...next_version.length).each { |i| next_version[i] = 0 }
202
+
203
+ Gem::Version.new(next_version.join('.'))
204
+ end
205
+
206
+ def next_version_task(increment = nil)
207
+ ENV['VERSION'] = next_version(increment).version
208
+ puts "Releasing version #{ENV['VERSION']}..."
209
+ end
210
+
211
+ # Updates the version number in the gemspec file, the VERSION constant in the main
212
+ # include file and the contents of the VERSION file.
213
+ def version_task
214
+ update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
215
+ update_gemspec(:date, Date.today)
216
+
217
+ update_version_file(gemspec.version)
218
+ update_version_constant(gemspec.version)
219
+ end
220
+
221
+ def check_version_task
222
+ raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
223
+ proposed_version = Gem::Version.new(ENV['VERSION'].dup || gemspec.version)
224
+ raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version >= proposed_version
225
+ end
226
+
227
+ # Checks whether the current branch is not diverged from the remote branch
228
+ def check_not_diverged_task
229
+ raise "The current branch is diverged from the remote branch!" if `#{git} rev-list HEAD..#{remote}/#{remote_branch}`.split("\n").any?
230
+ end
231
+
232
+ # Checks whether the repository status ic clean
233
+ def check_clean_status_task
234
+ raise "The current working copy contains modifications" if `#{git} ls-files -m`.split("\n").any?
235
+ end
236
+
237
+ # Checks whether the current branch is correct
238
+ def check_current_branch_task
239
+ raise "Currently not on #{local_branch} branch!" unless `#{git} branch`.split("\n").detect { |b| /^\* / =~ b } == "* #{local_branch}"
240
+ end
241
+
242
+ # Fetches the latest updates from Github
243
+ def fetch_origin_task
244
+ sh git, 'fetch', remote
245
+ end
246
+
247
+ # Commits every file that has been changed by the release task.
248
+ def commit_modified_files_task
249
+ really_modified = `#{git} ls-files -m #{modified_files.entries.join(' ')}`.split("\n")
250
+ if really_modified.any?
251
+ really_modified.each { |file| sh git, 'add', file }
252
+ sh git, 'commit', '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
253
+ end
254
+ end
255
+
256
+ # Adds a tag for the released version
257
+ def tag_version_task
258
+ sh git, 'tag', '-a', "#{gemspec.name}-#{gemspec.version}", '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
259
+ end
260
+
261
+ # Pushes the changes and tag to github
262
+ def github_release_task
263
+ sh git, 'push', '--tags', remote, remote_branch
264
+ end
265
+
266
+ def gemcutter_release_task
267
+ sh "gem", 'push', "pkg/#{gemspec.name}-#{gemspec.version}.gem"
268
+ end
269
+
270
+ # Gem release task.
271
+ # All work is done by the task's dependencies, so just display a release completed message.
272
+ def release_task
273
+ puts
274
+ puts '------------------------------------------------------------'
275
+ puts "Released #{gemspec.name} version #{gemspec.version}"
276
+ end
277
+
278
+ private
279
+
280
+ # Checks whether this project has any RSpec files
281
+ def has_specs?
282
+ FileList[spec_pattern].any?
283
+ end
284
+
285
+ # Checks whether this project has any unit test files
286
+ def has_tests?
287
+ FileList[test_pattern].any?
288
+ end
289
+
290
+ # Loads the gemspec file
291
+ def load_gemspec!
292
+ @gemspec = eval(File.read(@gemspec_file))
293
+ end
294
+
295
+ # Updates the VERSION file with the new version
296
+ def update_version_file(version)
297
+ if File.exists?('VERSION')
298
+ File.open('VERSION', 'w') { |f| f << version.to_s }
299
+ modified_files << 'VERSION'
300
+ end
301
+ end
302
+
303
+ # Updates the VERSION constant in the main include file if it exists
304
+ def update_version_constant(version)
305
+ if main_include && File.exist?(main_include)
306
+ file_contents = File.read(main_include)
307
+ if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
308
+ File.open(main_include, 'w') { |f| f << file_contents }
309
+ modified_files << main_include
310
+ end
311
+ end
312
+ end
313
+
314
+ # Updates an attribute of the gemspec file.
315
+ # This function will open the file, and search/replace the attribute using a regular expression.
316
+ def update_gemspec(attribute, new_value, literal = false)
317
+
318
+ unless literal
319
+ new_value = case new_value
320
+ when Array then "%w(#{new_value.join(' ')})"
321
+ when Hash, String then new_value.inspect
322
+ when Date then new_value.strftime('%Y-%m-%d').inspect
323
+ else raise "Cannot write value #{new_value.inspect} to gemspec file!"
324
+ end
325
+ end
326
+
327
+ spec = File.read(gemspec_file)
328
+ regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
329
+ if spec.sub!(regexp) { $1 + new_value }
330
+ File.open(gemspec_file, 'w') { |f| f << spec }
331
+ modified_files << gemspec_file
332
+
333
+ # Reload the gemspec so the changes are incorporated
334
+ load_gemspec!
335
+ end
336
+ end
337
+
338
+ # Updates the tasks file using the latest file found on Github
339
+ def update_tasks_task
340
+ require 'net/http'
341
+
342
+ server = 'github.com'
343
+ path = '/wvanbergen/github-gem/raw/master/tasks/github-gem.rake'
344
+
345
+ Net::HTTP.start(server) do |http|
346
+ response = http.get(path)
347
+ open(__FILE__, "w") { |file| file.write(response.body) }
348
+ end
349
+
350
+ relative_file = File.expand_path(__FILE__).sub(%r[^#{@root_dir}/], '')
351
+ if `#{git} ls-files -m #{relative_file}`.split("\n").any?
352
+ sh git, 'add', relative_file
353
+ sh git, 'commit', '-m', "Updated to latest gem release management tasks."
354
+ else
355
+ puts "Release managament tasks already are at the latest version."
356
+ end
357
+ end
358
+ end
359
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oily_png
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Willem van Bergen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-05 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 53
28
+ segments:
29
+ - 0
30
+ - 10
31
+ - 1
32
+ version: 0.10.1
33
+ requirement: *id001
34
+ name: chunky_png
35
+ prerelease: false
36
+ type: :runtime
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ requirement: *id002
48
+ name: rake
49
+ prerelease: false
50
+ type: :development
51
+ - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 9
58
+ segments:
59
+ - 1
60
+ - 3
61
+ version: "1.3"
62
+ requirement: *id003
63
+ name: rspec
64
+ prerelease: false
65
+ type: :development
66
+ description: " This Ruby C extenstion defines a module that can be included into ChunkyPNG to improve its speed.\n"
67
+ email:
68
+ - willem@railsdoctors.com
69
+ executables: []
70
+
71
+ extensions:
72
+ - ext/oily_png/extconf.rb
73
+ extra_rdoc_files:
74
+ - README.rdoc
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE
80
+ - README.rdoc
81
+ - Rakefile
82
+ - ext/oily_png/decoding.c
83
+ - ext/oily_png/extconf.rb
84
+ - lib/oily_png.rb
85
+ - oily_png.gemspec
86
+ - tasks/github-gem.rake
87
+ has_rdoc: true
88
+ homepage: http://wiki.github.com/wvanbergen/oily_png
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --title
94
+ - oily_png
95
+ - --main
96
+ - README.rdoc
97
+ - --line-numbers
98
+ - --inline-source
99
+ require_paths:
100
+ - lib
101
+ - ext
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - "="
115
+ - !ruby/object:Gem::Version
116
+ hash: 21
117
+ segments:
118
+ - 1
119
+ - 3
120
+ - 7
121
+ version: 1.3.7
122
+ requirements: []
123
+
124
+ rubyforge_project: oily_png
125
+ rubygems_version: 1.3.7
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Native mixin to speed up ChunkyPNG
129
+ test_files: []
130
+