middleman 0.9.23 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/middleman/features/smush_pngs.rb +27 -50
- data/lib/middleman/templater+dynamic_renderer.rb +4 -3
- data/middleman.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.10.0
|
@@ -1,58 +1,35 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'httpclient'
|
6
|
-
rescue LoadError
|
7
|
-
puts "httpclient not available. Install it with: gem install httpclient"
|
8
|
-
end
|
1
|
+
require "smusher"
|
2
|
+
require "middleman/builder"
|
9
3
|
|
10
4
|
module Middleman
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
begin
|
22
|
-
raise "Error: got larger" if size(file) < optimized.size
|
23
|
-
raise "Error: empty file downloaded" if optimized.size < 20
|
24
|
-
|
25
|
-
optimized
|
26
|
-
rescue
|
27
|
-
File.read(file)
|
28
|
-
end
|
5
|
+
class Builder
|
6
|
+
alias_method :pre_smush_after_run, :after_run
|
7
|
+
def after_run
|
8
|
+
pre_smush_after_run
|
9
|
+
smush_dir = File.join(Middleman::Base.build_dir, Middleman::Base.images_dir)
|
10
|
+
|
11
|
+
# Read cache
|
12
|
+
cache_file = File.join(Middleman::Base.root, ".smush-cache")
|
13
|
+
cache_data = if File.exists?(cache_file)
|
14
|
+
Marshal.restore(File.read(cache_file))
|
29
15
|
else
|
30
|
-
|
16
|
+
{}
|
31
17
|
end
|
32
|
-
|
18
|
+
|
19
|
+
::Smusher.class_eval do
|
20
|
+
images_in_folder(smush_dir).each do |file|
|
21
|
+
original_file_size = size(file)
|
22
|
+
return if original_file_size.zero?
|
23
|
+
return if cache_data[file] && cache_data[file] == original_file_size
|
33
24
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
url = 'http://ws1.adq.ac4.yahoo.com/ysmush.it/ws.php'
|
43
|
-
# url = "http://developer.yahoo.com/yslow/smushit/ws.php" # official but does not work
|
44
|
-
# url = "http://smushit.com/ysmush.it/ws.php" # used at the new page but does not hande uploads
|
45
|
-
# url = "http://smushit.eperf.vip.ac4.yahoo.com/ysmush.it/ws.php" # used at the new page but does not hande uploads
|
46
|
-
response = HTTPClient.post url, { 'files[]' => File.new(file) }
|
47
|
-
response = JSON.parse(response.body.content)
|
48
|
-
raise "smush.it: #{response['error']}" if response['error']
|
49
|
-
image_url = response['dest']
|
50
|
-
raise "no dest path found" unless image_url
|
51
|
-
open(image_url) { |source| source.read() }
|
25
|
+
with_logging(file, true) do
|
26
|
+
write_optimized_data(file)
|
27
|
+
cache_data[file] = size(file) # Add or update cache
|
28
|
+
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
|
29
|
+
say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Base.build_dir+"/", '')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
52
33
|
end
|
53
34
|
end
|
54
|
-
|
55
|
-
class Base
|
56
|
-
include Middleman::SmushPngs
|
57
|
-
end
|
58
35
|
end
|
@@ -14,12 +14,13 @@ end
|
|
14
14
|
|
15
15
|
class Templater::Actions::Template
|
16
16
|
def render
|
17
|
+
@@rack_test ||= Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
|
18
|
+
|
17
19
|
@render_cache ||= begin
|
18
20
|
# The default render just requests the page over Rack and writes the response
|
19
21
|
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
|
20
|
-
|
21
|
-
|
22
|
-
browser.last_response.body
|
22
|
+
@@rack_test.get(request_path)
|
23
|
+
@@rack_test.last_response.body
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/middleman.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{middleman}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.10.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thomas Reynolds"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-29}
|
13
13
|
s.email = %q{tdreyno@gmail.com}
|
14
14
|
s.executables = ["mm-init", "mm-build", "mm-server"]
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Reynolds
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-29 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|