middleman-imageoptim 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ # Ignore bundler lock file
2
+ Gemfile.lock
3
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # If you have OpenSSL installed, we recommend updating
2
+ # the following line to use "https"
3
+ source 'http://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in middleman-imageoptim.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem "rake", "~> 0.9.2"
10
+ gem "rdoc", "~> 3.9"
11
+ gem "yard", "~> 0.8.0"
12
+ end
13
+
14
+ group :test do
15
+ gem "cucumber", "~> 1.2.0"
16
+ gem "fivemat"
17
+ gem "aruba", "~> 0.4.11"
18
+ gem "rspec", "~> 2.7"
19
+ end
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Middleman ImageOptim Extension
2
+
3
+ ## Wat.
4
+
5
+ Compress and optimise your imagery during `middleman build` by running [image_optim](https://github.com/toy/image_optim) over it. Yay-hooray!
6
+
7
+ ## Installation
8
+
9
+ Go set up the [image_optim](https://github.com/toy/image_optim) external utilities, then;
10
+
11
+ ```ruby
12
+ gem "middleman-imageoptim", "0.0.2"
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ activate :image_optim
19
+ ```
20
+
21
+ You can also configure the extension in the usual fashion, by passing a block to `:activate`
22
+ Below is the default configuration showing all available options;
23
+
24
+ ```ruby
25
+ activate :image_optim do |image_optim|
26
+ # print out skipped images
27
+ image_optim.verbose = false
28
+
29
+ # Setting these to true or nil will let image_optim determine them (recommended)
30
+ image_optim.nice = true
31
+ image_optim.threads = true
32
+
33
+ # Image extensions to attempt to compress
34
+ image_optim.image_extensions = %w(.png .jpg .gif)
35
+
36
+ # compressor worker options, individual optimisers can be disabled by passing
37
+ # false instead of a hash
38
+ image_optim.pngcrush_options = {:chunks => ['alla'], :fix => false, :brute => false}
39
+ image_optim.pngout_options = {:copy_chunks => false, :strategy => 0}
40
+ image_optim.optipng_options = {:level => 6, :interlace => false}
41
+ image_optim.advpng_options = {:level => 4}
42
+ image_optim.jpegoptim_options = {:strip => ['all'], :max_quality => 100}
43
+ image_optim.jpegtran_options = {:copy_chunks => false, :progressive => true, :jpegrescan => true}
44
+ image_optim.gifsicle_options = {:interlace => false}
45
+ end
46
+ ```
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/clean'
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require "middleman-core"
3
+ require "middleman-core/step_definitions"
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-imageoptim')
@@ -0,0 +1,68 @@
1
+ require "middleman-core"
2
+ require "image_optim"
3
+ require "fileutils"
4
+
5
+ module MiddlemanImageoptim
6
+ class << self
7
+ def registered(app, options={})
8
+ app.set :verbose, false
9
+ app.set :nice, true
10
+ app.set :threads, true
11
+ app.set :image_extensions, %w(.png .jpg .gif)
12
+ app.set :pngcrush_options, {:chunks => ['alla'], :fix => false, :brute => false}
13
+ app.set :pngout_options, {:copy_chunks => false, :strategy => 0}
14
+ app.set :optipng_options, {:level => 6, :interlace => false}
15
+ app.set :advpng_options, {:level => 4}
16
+ app.set :jpegoptim_options, {:strip => ['all'], :max_quality => 100}
17
+ app.set :jpegtran_options, {:copy_chunks => false, :progressive => true, :jpegrescan => true}
18
+ app.set :gifsicle_options, {:interlace => false}
19
+
20
+ app.after_build do |builder|
21
+ image_optim = ImageOptim.new(
22
+ :nice => nice,
23
+ :threads => threads,
24
+ :pngcrush => pngcrush_options,
25
+ :pngout => pngout_options,
26
+ :optipng => optipng_options,
27
+ :advpng => advpng_options,
28
+ :jpegoptim => jpegoptim_options,
29
+ :jpegtran => jpegtran_options,
30
+ :gifsicle => gifsicle_options
31
+ )
32
+ optimizable_paths = []
33
+ paths = ::Middleman::Util.all_files_under(self.class.inst.build_dir)
34
+
35
+ # iterate over all the paths in the middleman build directory
36
+ paths.each do |path|
37
+
38
+ # reject non-image extension paths
39
+ next unless image_extensions.include? path.extname
40
+
41
+ # check that we can handle this image
42
+ if image_optim.optimizable?(path.to_s)
43
+ optimizable_paths << path
44
+ else
45
+ builder.say_status :img_optim, "skipping #{path} as it is not an image or there is no optimizer for it"
46
+ end
47
+ end
48
+
49
+ # start compressing image assets
50
+ image_optim.optimize_images(optimizable_paths) do |src, dst|
51
+ if dst
52
+ size_change_word = (src.size - dst.size) > 0 ? 'smaller' : 'larger'
53
+ percent_change = '%.2f%%' % [100 - 100.0 * dst.size / src.size]
54
+ builder.say_status :img_optimise, "#{src} (#{percent_change} / #{number_to_human_size((src.size - dst.size).abs)} #{size_change_word})"
55
+ FileUtils.mv(dst, src)
56
+ elsif verbose
57
+ builder.say_status :img_optimise, "#{src} (skipped)"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ alias :included :registered
63
+ end
64
+ end
65
+
66
+ ::Middleman::Extensions.register(:image_optim) do
67
+ ::MiddlemanImageoptim
68
+ end
@@ -0,0 +1,3 @@
1
+ module MiddlemanImageoptim
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1 @@
1
+ require "middleman-imageoptim"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require File.expand_path('../lib/middleman-imageoptim/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "middleman-imageoptim"
7
+ gem.version = MiddlemanImageoptim::VERSION
8
+ gem.platform = Gem::Platform::RUBY
9
+ gem.authors = ["Justin Morris"]
10
+ gem.email = ["desk@pixelbloom.com"]
11
+ gem.homepage = "http://pixelbloom.com"
12
+ gem.summary = %q{A short summary of your extension}
13
+ gem.description = %q{A longer description of your extension}
14
+
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency("middleman-core", [">= 3.0"])
21
+ gem.add_runtime_dependency("image_optim", "~> 0.8.0")
22
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-imageoptim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Morris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: middleman-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: image_optim
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.0
46
+ description: A longer description of your extension
47
+ email:
48
+ - desk@pixelbloom.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - README.md
56
+ - Rakefile
57
+ - features/support/env.rb
58
+ - lib/middleman-imageoptim.rb
59
+ - lib/middleman-imageoptim/version.rb
60
+ - lib/middleman_extension.rb
61
+ - middleman-imageoptim.gemspec
62
+ homepage: http://pixelbloom.com
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A short summary of your extension
86
+ test_files:
87
+ - features/support/env.rb