middleman-smusher 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/middleman-smusher.rb +52 -0
- data/lib/middleman-smusher/version.rb +5 -0
- data/middleman-smusher.gemspec +23 -0
- metadata +88 -0
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Rakefile
    ADDED
    
    
| @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            module Middleman
         | 
| 2 | 
            +
              module Features
         | 
| 3 | 
            +
                module Smusher
         | 
| 4 | 
            +
                  module ThorActions
         | 
| 5 | 
            +
                    def smush_pngs
         | 
| 6 | 
            +
                      # Read cache
         | 
| 7 | 
            +
                      cache_file = File.join(Middleman::Server.root, ".smush-cache")
         | 
| 8 | 
            +
                      cache_data = if File.exists?(cache_file)
         | 
| 9 | 
            +
                        Marshal.restore(File.read(cache_file))
         | 
| 10 | 
            +
                      else
         | 
| 11 | 
            +
                        {}
         | 
| 12 | 
            +
                      end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                      smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                      files = ::Smusher.class_eval do
         | 
| 17 | 
            +
                        images_in_folder(smush_dir)
         | 
| 18 | 
            +
                      end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                      files.each do |file|
         | 
| 21 | 
            +
                        ::Smusher.class_eval do
         | 
| 22 | 
            +
                          original_file_size = size(file)
         | 
| 23 | 
            +
                          return if original_file_size.zero?
         | 
| 24 | 
            +
                          return if cache_data[file] && cache_data[file] == original_file_size
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                          with_logging(file, true) do
         | 
| 27 | 
            +
                            write_optimized_data(file)
         | 
| 28 | 
            +
                            cache_data[file] = size(file) # Add or update cache
         | 
| 29 | 
            +
                            File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
         | 
| 30 | 
            +
                          end
         | 
| 31 | 
            +
                        end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                        say_status :smushed, file.gsub(Middleman::Server.build_dir+"/", "")
         | 
| 34 | 
            +
                      end
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  class << self
         | 
| 39 | 
            +
                    def registered(app)
         | 
| 40 | 
            +
                      require "middleman/builder"
         | 
| 41 | 
            +
                      require "smusher"
         | 
| 42 | 
            +
                      require "json/pure"
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                      Middleman::Builder.send :include, ThorActions
         | 
| 45 | 
            +
                      Middleman::Builder.after_run "smush_pngs" do
         | 
| 46 | 
            +
                        smush_pngs
         | 
| 47 | 
            +
                      end
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            require "middleman-smusher/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name        = "middleman-smusher"
         | 
| 7 | 
            +
              s.version     = Middleman::Smusher::VERSION
         | 
| 8 | 
            +
              s.platform    = Gem::Platform::RUBY
         | 
| 9 | 
            +
              s.authors     = ["Thomas Reynolds"]
         | 
| 10 | 
            +
              s.email       = ["tdreyno@gmail.com"]
         | 
| 11 | 
            +
              s.homepage    = "https://github.com/tdreyno/middleman-smusher"
         | 
| 12 | 
            +
              s.summary     = %q{Compress images in your Middleman project}
         | 
| 13 | 
            +
              s.description = %q{Compress images in your Middleman project}
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              s.rubyforge_project = "middleman-smusher"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              s.files         = `git ls-files`.split("\n")
         | 
| 18 | 
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 19 | 
            +
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 20 | 
            +
              s.require_paths = ["lib"]
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              s.add_runtime_dependency("smusher", ["~> 0.4.6"])
         | 
| 23 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,88 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: middleman-smusher
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 29
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 0
         | 
| 8 | 
            +
              - 0
         | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 0.0.1
         | 
| 11 | 
            +
            platform: ruby
         | 
| 12 | 
            +
            authors: 
         | 
| 13 | 
            +
            - Thomas Reynolds
         | 
| 14 | 
            +
            autorequire: 
         | 
| 15 | 
            +
            bindir: bin
         | 
| 16 | 
            +
            cert_chain: []
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            date: 2011-04-18 00:00:00 -07:00
         | 
| 19 | 
            +
            default_executable: 
         | 
| 20 | 
            +
            dependencies: 
         | 
| 21 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            +
              name: smusher
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements: 
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 29 | 
            +
                    hash: 3
         | 
| 30 | 
            +
                    segments: 
         | 
| 31 | 
            +
                    - 0
         | 
| 32 | 
            +
                    - 4
         | 
| 33 | 
            +
                    - 6
         | 
| 34 | 
            +
                    version: 0.4.6
         | 
| 35 | 
            +
              type: :runtime
         | 
| 36 | 
            +
              version_requirements: *id001
         | 
| 37 | 
            +
            description: Compress images in your Middleman project
         | 
| 38 | 
            +
            email: 
         | 
| 39 | 
            +
            - tdreyno@gmail.com
         | 
| 40 | 
            +
            executables: []
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            extensions: []
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            extra_rdoc_files: []
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            files: 
         | 
| 47 | 
            +
            - .gitignore
         | 
| 48 | 
            +
            - Gemfile
         | 
| 49 | 
            +
            - Rakefile
         | 
| 50 | 
            +
            - lib/middleman-smusher.rb
         | 
| 51 | 
            +
            - lib/middleman-smusher/version.rb
         | 
| 52 | 
            +
            - middleman-smusher.gemspec
         | 
| 53 | 
            +
            has_rdoc: true
         | 
| 54 | 
            +
            homepage: https://github.com/tdreyno/middleman-smusher
         | 
| 55 | 
            +
            licenses: []
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            post_install_message: 
         | 
| 58 | 
            +
            rdoc_options: []
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            require_paths: 
         | 
| 61 | 
            +
            - lib
         | 
| 62 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 63 | 
            +
              none: false
         | 
| 64 | 
            +
              requirements: 
         | 
| 65 | 
            +
              - - ">="
         | 
| 66 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 67 | 
            +
                  hash: 3
         | 
| 68 | 
            +
                  segments: 
         | 
| 69 | 
            +
                  - 0
         | 
| 70 | 
            +
                  version: "0"
         | 
| 71 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 72 | 
            +
              none: false
         | 
| 73 | 
            +
              requirements: 
         | 
| 74 | 
            +
              - - ">="
         | 
| 75 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 76 | 
            +
                  hash: 3
         | 
| 77 | 
            +
                  segments: 
         | 
| 78 | 
            +
                  - 0
         | 
| 79 | 
            +
                  version: "0"
         | 
| 80 | 
            +
            requirements: []
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            rubyforge_project: middleman-smusher
         | 
| 83 | 
            +
            rubygems_version: 1.5.0
         | 
| 84 | 
            +
            signing_key: 
         | 
| 85 | 
            +
            specification_version: 3
         | 
| 86 | 
            +
            summary: Compress images in your Middleman project
         | 
| 87 | 
            +
            test_files: []
         | 
| 88 | 
            +
             |