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 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
- # Middleman::ThorBuilder.source_root(Dir.pwd)
13
- Middleman::Builder.start
8
+ require 'middleman/builder'
9
+ Middleman::Builder.start
@@ -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
@@ -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 :SmushPNGs, "middleman/features/smush_pngs"
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::SmushPNGs
2
- class << self
3
- def registered(app)
4
- require "middleman/builder"
5
-
6
- app.alias_method :pre_smush_after_run, :after_run
7
- app.define_method :after_run do
8
- pre_smush_after_run
9
- smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
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
- # Read cache
12
- cache_file = File.join(Middleman::Server.root, ".smush-cache")
13
- cache_data = if File.exists?(cache_file)
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
- require "smusher"
20
- require "json/pure"
18
+ files.each do |file|
21
19
  ::Smusher.class_eval do
22
- images_in_folder(smush_dir).each do |file|
23
- original_file_size = size(file)
24
- return if original_file_size.zero?
25
- return if cache_data[file] && cache_data[file] == original_file_size
26
-
27
- with_logging(file, true) do
28
- write_optimized_data(file)
29
- cache_data[file] = size(file) # Add or update cache
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
@@ -1,3 +1,3 @@
1
1
  module Middleman
2
- VERSION = "1.1.0.beta.1"
2
+ VERSION = "1.1.0.beta.2"
3
3
  end
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: 62196369
4
+ hash: 62196375
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - 0
10
10
  - beta
11
- - 1
12
- version: 1.1.0.beta.1
11
+ - 2
12
+ version: 1.1.0.beta.2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Thomas Reynolds