middleman-core-x86-mingw32 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,6 +37,10 @@ module Middleman::Cli
37
37
  :type => :boolean,
38
38
  :default => false,
39
39
  :desc => 'Generate profiling report for server startup'
40
+ method_option :reload_paths,
41
+ :type => :string,
42
+ :default => false,
43
+ :desc => 'Additional paths to auto-reload when files change'
40
44
 
41
45
  # Start the server
42
46
  def server
@@ -56,7 +60,8 @@ module Middleman::Cli
56
60
  :environment => options["environment"],
57
61
  :debug => options["verbose"],
58
62
  :instrumenting => options["instrument"],
59
- :"disable-watcher" => options["disable-watcher"]
63
+ :"disable-watcher" => options["disable-watcher"],
64
+ :reload_paths => options["reload_paths"]
60
65
  }
61
66
 
62
67
  puts "== The Middleman is loading"
@@ -9,33 +9,19 @@ module Middleman
9
9
  DEFAULT_PORT = 4567
10
10
 
11
11
  class << self
12
- attr_reader :app
12
+ attr_reader :app, :port
13
13
  delegate :logger, :to => :app
14
14
 
15
15
  # Start an instance of Middleman::Application
16
16
  # @return [void]
17
- def start(options={})
18
- @app = ::Middleman::Application.server.inst do
19
- if options[:environment]
20
- set :environment, options[:environment].to_sym
21
- end
22
-
23
- logger(options[:debug] ? 0 : 1, options[:instrumenting] || false)
24
- end
25
-
26
- port = options[:port] || DEFAULT_PORT
17
+ def start(opts={})
18
+ @options = opts
19
+ @port = @options[:port] || DEFAULT_PORT
27
20
 
21
+ mount_instance
28
22
  logger.info "== The Middleman is standing watch on port #{port}"
29
23
 
30
- @webrick ||= setup_webrick(
31
- options[:host] || "0.0.0.0",
32
- port,
33
- options[:debug] || false
34
- )
35
-
36
- mount_instance(app)
37
-
38
- start_file_watcher unless options[:"disable-watcher"]
24
+ start_file_watcher unless @options[:"disable-watcher"]
39
25
 
40
26
  @initialized ||= false
41
27
  unless @initialized
@@ -43,9 +29,8 @@ module Middleman
43
29
 
44
30
  register_signal_handlers unless ::Middleman::WINDOWS
45
31
 
46
- # Save the last-used options so it may be re-used when
32
+ # Save the last-used @options so it may be re-used when
47
33
  # reloading later on.
48
- @last_options = options
49
34
  ::Middleman::Profiling.report("server_start")
50
35
 
51
36
  @webrick.start
@@ -66,8 +51,12 @@ module Middleman
66
51
  # Simply stop, then start the server
67
52
  # @return [void]
68
53
  def reload
69
- stop
70
- start @last_options
54
+ logger.info "== The Middleman is reloading"
55
+
56
+ unmount_instance
57
+ mount_instance
58
+
59
+ logger.info "== The Middleman is standing watch on port #{port}"
71
60
  end
72
61
 
73
62
  # Stop the current instance, exit Webrick
@@ -78,6 +67,16 @@ module Middleman
78
67
  end
79
68
 
80
69
  private
70
+ def new_app
71
+ opts = @options
72
+ @app =::Middleman::Application.server.inst do
73
+ if opts[:environment]
74
+ set :environment, opts[:environment].to_sym
75
+ end
76
+
77
+ logger(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
78
+ end
79
+ end
81
80
 
82
81
  def start_file_watcher
83
82
  # Watcher Library
@@ -99,7 +98,7 @@ module Middleman
99
98
 
100
99
  # Otherwise forward to Middleman
101
100
  added_and_modified.each do |path|
102
- @app.files.did_change(path)
101
+ app.files.did_change(path)
103
102
  end
104
103
  end
105
104
 
@@ -112,7 +111,7 @@ module Middleman
112
111
 
113
112
  # Otherwise forward to Middleman
114
113
  removed.each do |path|
115
- @app.files.did_delete(path)
114
+ app.files.did_delete(path)
116
115
  end
117
116
  end
118
117
  end
@@ -131,13 +130,12 @@ module Middleman
131
130
 
132
131
  # Initialize webrick
133
132
  # @return [void]
134
- def setup_webrick(host, port, is_logging)
133
+ def setup_webrick(host, is_logging)
135
134
  @host = host
136
- @port = port
137
135
 
138
136
  http_opts = {
139
137
  :BindAddress => @host,
140
- :Port => @port,
138
+ :Port => port,
141
139
  :AccessLog => []
142
140
  }
143
141
 
@@ -147,15 +145,27 @@ module Middleman
147
145
  http_opts[:Logger] = ::WEBrick::Log.new(nil, 0)
148
146
  end
149
147
 
150
- ::WEBrick::HTTPServer.new(http_opts)
148
+ begin
149
+ ::WEBrick::HTTPServer.new(http_opts)
150
+ rescue Errno::EADDRINUSE => e
151
+ logger.error "== Port #{port} is unavailable. Either close the instance of Middleman already running on #{port} or start this Middleman on a new port with: --port=#{port.to_i+1}"
152
+ exit(1)
153
+ end
151
154
  end
152
155
 
153
156
  # Attach a new Middleman::Application instance
154
157
  # @param [Middleman::Application] app
155
158
  # @return [void]
156
- def mount_instance(app)
157
- @app = app
158
- @webrick.mount "/", ::Rack::Handler::WEBrick, @app.class.to_rack_app
159
+ def mount_instance
160
+ @app = new_app
161
+ @webrick ||= setup_webrick(
162
+ @options[:host] || "0.0.0.0",
163
+ @options[:debug] || false
164
+ )
165
+
166
+ @app = new_app
167
+
168
+ @webrick.mount "/", ::Rack::Handler::WEBrick, app.class.to_rack_app
159
169
  end
160
170
 
161
171
  # Detach the current Middleman::Application instance
@@ -169,8 +179,22 @@ module Middleman
169
179
  # @param [Array<String>] paths Array of paths to check
170
180
  # @return [Boolean] Whether the server needs to reload
171
181
  def needs_to_reload?(paths)
182
+ match_against = [
183
+ %r{^config\.rb},
184
+ %r{^lib/^[^\.](.*)\.rb$},
185
+ %r{^helpers/^[^\.](.*)_helper\.rb$}
186
+ ]
187
+
188
+ if @options[:reload_paths]
189
+ @options[:reload_paths].split(',').each do |part|
190
+ match_against << %r{^#{part}}
191
+ end
192
+ end
193
+
172
194
  paths.any? do |path|
173
- path.match(%{^config\.rb}) || path.match(%r{^lib/^[^\.](.*)\.rb$}) || path.match(%r{^helpers/^[^\.](.*)_helper\.rb$})
195
+ match_against.any? do |matcher|
196
+ path.match(matcher)
197
+ end
174
198
  end
175
199
  end
176
200
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  # Current Version
3
3
  # @return [String]
4
- VERSION = '3.0.2' unless const_defined?(:VERSION)
4
+ VERSION = '3.0.3' unless const_defined?(:VERSION)
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-core-x86-mingw32
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-05 00:00:00.000000000 Z
13
+ date: 2012-09-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -569,7 +569,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
569
569
  version: '0'
570
570
  segments:
571
571
  - 0
572
- hash: 4569212249862071353
572
+ hash: 4093729475455442254
573
573
  required_rubygems_version: !ruby/object:Gem::Requirement
574
574
  none: false
575
575
  requirements:
@@ -578,7 +578,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
578
578
  version: '0'
579
579
  segments:
580
580
  - 0
581
- hash: 4569212249862071353
581
+ hash: 4093729475455442254
582
582
  requirements: []
583
583
  rubyforge_project:
584
584
  rubygems_version: 1.8.23