middleman 1.1.0.beta.1 → 1.1.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mm-build +2 -6
- data/lib/middleman/builder.rb +13 -1
- data/lib/middleman/features.rb +1 -1
- data/lib/middleman/features/smush_pngs.rb +39 -29
- data/lib/middleman/version.rb +1 -1
- metadata +3 -3
data/bin/mm-build
CHANGED
@@ -4,10 +4,6 @@ ENV['MM_ENV'] = "build"
|
|
4
4
|
|
5
5
|
# Require app
|
6
6
|
require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
|
7
|
-
require 'middleman/builder'
|
8
|
-
|
9
|
-
# Initialize server once so features are loaded
|
10
|
-
Middleman::Server.new
|
11
7
|
|
12
|
-
|
13
|
-
Middleman::Builder.start
|
8
|
+
require 'middleman/builder'
|
9
|
+
Middleman::Builder.start
|
data/lib/middleman/builder.rb
CHANGED
@@ -12,7 +12,7 @@ module Middleman
|
|
12
12
|
source = File.expand_path(find_in_source_paths(source.to_s))
|
13
13
|
context = instance_eval('binding')
|
14
14
|
|
15
|
-
@@rack_test ||= Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server))
|
15
|
+
@@rack_test ||= ::Rack::Test::Session.new(::Rack::MockSession.new(Middleman::Server))
|
16
16
|
|
17
17
|
create_file destination, nil, config do
|
18
18
|
# The default render just requests the page over Rack and writes the response
|
@@ -28,6 +28,7 @@ module Middleman
|
|
28
28
|
include Middleman::ThorActions
|
29
29
|
|
30
30
|
def initialize(*args)
|
31
|
+
Middleman::Server.new
|
31
32
|
::Tilt.mappings.keys << "js"
|
32
33
|
super
|
33
34
|
end
|
@@ -46,6 +47,17 @@ module Middleman
|
|
46
47
|
def build_dynamic_files
|
47
48
|
action Directory.new(self, Middleman::Server.views, Middleman::Server.build_dir)
|
48
49
|
end
|
50
|
+
|
51
|
+
@@hooks = {}
|
52
|
+
def self.after_run(name, &block)
|
53
|
+
@@hooks[name] = block
|
54
|
+
end
|
55
|
+
|
56
|
+
def run_hooks
|
57
|
+
@@hooks.each do |name, proc|
|
58
|
+
instance_eval(&proc)
|
59
|
+
end
|
60
|
+
end
|
49
61
|
end
|
50
62
|
|
51
63
|
class Directory < ::Thor::Actions::EmptyDirectory
|
data/lib/middleman/features.rb
CHANGED
@@ -8,7 +8,7 @@ module Middleman::Features
|
|
8
8
|
autoload :MinifyCss, "middleman/features/minify_css"
|
9
9
|
autoload :MinifyJavascript, "middleman/features/minify_javascript"
|
10
10
|
autoload :Slickmap, "middleman/features/slickmap"
|
11
|
-
autoload :
|
11
|
+
autoload :SmushPngs, "middleman/features/smush_pngs"
|
12
12
|
autoload :CodeRay, "middleman/features/code_ray"
|
13
13
|
autoload :Lorem, "middleman/features/lorem"
|
14
14
|
# autoload :LiveReload, "middleman/features/live_reload"
|
@@ -1,37 +1,47 @@
|
|
1
|
-
module Middleman::Features::
|
2
|
-
|
3
|
-
def
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Middleman::Features::SmushPngs
|
2
|
+
module ThorActions
|
3
|
+
def smush_pngs
|
4
|
+
# Read cache
|
5
|
+
cache_file = File.join(Middleman::Server.root, ".smush-cache")
|
6
|
+
cache_data = if File.exists?(cache_file)
|
7
|
+
Marshal.restore(File.read(cache_file))
|
8
|
+
else
|
9
|
+
{}
|
10
|
+
end
|
11
|
+
|
12
|
+
smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
Marshal.restore(File.read(cache_file))
|
15
|
-
else
|
16
|
-
{}
|
17
|
-
end
|
14
|
+
files = ::Smusher.class_eval do
|
15
|
+
images_in_folder(smush_dir)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
require "json/pure"
|
18
|
+
files.each do |file|
|
21
19
|
::Smusher.class_eval do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
|
31
|
-
say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Server.build_dir+"/", '')
|
32
|
-
end
|
20
|
+
original_file_size = size(file)
|
21
|
+
return if original_file_size.zero?
|
22
|
+
return if cache_data[file] && cache_data[file] == original_file_size
|
23
|
+
|
24
|
+
with_logging(file, true) do
|
25
|
+
write_optimized_data(file)
|
26
|
+
cache_data[file] = size(file) # Add or update cache
|
27
|
+
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
|
33
28
|
end
|
34
29
|
end
|
30
|
+
|
31
|
+
say_status :smushed, file.gsub(Middleman::Server.build_dir+"/", "")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def registered(app)
|
38
|
+
require "middleman/builder"
|
39
|
+
require "smusher"
|
40
|
+
require "json/pure"
|
41
|
+
|
42
|
+
Middleman::Builder.send :include, ThorActions
|
43
|
+
Middleman::Builder.after_run "smush_pngs" do
|
44
|
+
smush_pngs
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
data/lib/middleman/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196375
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 1.1.0.beta.
|
11
|
+
- 2
|
12
|
+
version: 1.1.0.beta.2
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Thomas Reynolds
|