middleman 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@ module Middleman
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
19
- request_path = destination.gsub(Middleman::Server.build_dir, "")
19
+ request_path = destination.sub(/^#{Middleman::Server.build_dir}/, "")
20
20
  @@rack_test.get(request_path)
21
21
  @@rack_test.last_response.body
22
22
  end
@@ -87,7 +87,7 @@ module Middleman
87
87
 
88
88
  protected
89
89
  def handle_directory(lookup)
90
- lookup = File.join(lookup, '{*,.[a-z]*}')
90
+ lookup = File.join(lookup, '*')
91
91
 
92
92
  Dir[lookup].sort.each do |file_source|
93
93
  if File.directory?(file_source)
@@ -71,6 +71,9 @@ module Middleman::Features
71
71
  # to dynamic requests.
72
72
  autoload :Data, "middleman/features/data"
73
73
 
74
+ # Proxy web services requests in dev mode only
75
+ # autoload :Proxy, "middleman/features/proxy"
76
+
74
77
  # Automatically resize images for mobile devises
75
78
  # autoload :TinySrc, "middleman/features/tiny_src"
76
79
 
@@ -0,0 +1,194 @@
1
+ # ===========================================================================
2
+ # Original Project: Abbot - SproutCore Build Tools
3
+ # Copyright: ©2009 Apple Inc.
4
+ # portions copyright @2006-2011 Strobe Inc.
5
+ # and contributors
6
+ # ===========================================================================
7
+
8
+ begin
9
+ require 'net/https'
10
+ Middleman::HTTPS_ENABLED = true
11
+ rescue LoadError => e
12
+ require 'net/http'
13
+ Middleman::HTTPS_ENABLED = false
14
+ end
15
+
16
+ module Middleman::Features::Proxy
17
+ class << self
18
+ def registered(app)
19
+ app.extend ClassMethods
20
+ app.use Middleman::Features::Proxy::Rack
21
+ end
22
+ alias :included :registered
23
+ end
24
+
25
+ class Collection
26
+ def initialize(app)
27
+ @app = app
28
+ end
29
+
30
+ def self.proxies
31
+ @@proxies ||= {}
32
+ end
33
+
34
+ def self.add(path, options={})
35
+ @@proxies ||= {}
36
+ @@proxies[path] = options[:to]
37
+ end
38
+ end
39
+
40
+ module ClassMethods
41
+ # Proxies requests to the path
42
+ #
43
+ # proxy '/twitter', "http://twitter/web/service"
44
+ def proxy(path, options={})
45
+ Middleman::Features::Proxy::Collection.add(path, options)
46
+ end
47
+ end
48
+
49
+ # Rack application proxies requests as needed for the given project.
50
+ module Rack
51
+
52
+ def initialize(app)
53
+ @app = app
54
+ end
55
+
56
+ def call(env)
57
+ url = env['PATH_INFO']
58
+
59
+ @proxies = Middleman::Features::Proxy::Collection.proxies
60
+ @proxies.each do |proxy, value|
61
+ if url.match(/^#{Regexp.escape(proxy.to_s)}/)
62
+ return handle_proxy(value, proxy.to_s, env)
63
+ end
64
+ end
65
+
66
+ return [404, {}, "not found"]
67
+ end
68
+
69
+ def handle_proxy(proxy, proxy_url, env)
70
+ if proxy[:secure] && !Middleman::HTTPS_ENABLED
71
+ $stderr.puts "~ WARNING: HTTPS is not supported on your system, using HTTP instead.\n"
72
+ $stderr.puts" If you are using Ubuntu, you can run `apt-get install libopenssl-ruby`\n"
73
+ proxy[:secure] = false
74
+ end
75
+
76
+ origin_host = env['SERVER_NAME'] # capture the origin host for cookies
77
+ http_method = env['REQUEST_METHOD'].to_s.downcase
78
+ url = env['PATH_INFO']
79
+ params = env['QUERY_STRING']
80
+
81
+ # collect headers...
82
+ headers = {}
83
+ env.each do |key, value|
84
+ next unless key =~ /^HTTP_/
85
+ key = key.gsub(/^HTTP_/,'').downcase.sub(/^\w/){|l| l.upcase}.gsub(/_(\w)/){|l| "-#{$1.upcase}"} # remove HTTP_, dasherize and titleize
86
+ if !key.eql? "Version"
87
+ headers[key] = value
88
+ end
89
+ end
90
+
91
+ # Rack documentation says CONTENT_TYPE and CONTENT_LENGTH aren't prefixed by HTTP_
92
+ headers['Content-Type'] = env['CONTENT_TYPE'] if env['CONTENT_TYPE']
93
+
94
+ length = env['CONTENT_LENGTH']
95
+ headers['Content-Length'] = length if length
96
+
97
+ http_host, http_port = proxy[:to].split(':')
98
+ http_port = proxy[:secure] ? '443' : '80' if http_port.nil?
99
+
100
+ # added 4/23/09 per Charles Jolley, corrects problem
101
+ # when making requests to virtual hosts
102
+ headers['Host'] = "#{http_host}:#{http_port}"
103
+
104
+ if proxy[:url]
105
+ url = url.sub(/^#{Regexp.escape proxy_url}/, proxy[:url])
106
+ end
107
+
108
+ http_path = [url]
109
+ http_path << params if params && params.size>0
110
+ http_path = http_path.join('?')
111
+
112
+ response = nil
113
+ no_body_method = %w(get copy head move options trace)
114
+
115
+ done = false
116
+ tries = 0
117
+ until done
118
+ http = ::Net::HTTP.new(http_host, http_port)
119
+
120
+ if proxy[:secure]
121
+ http.use_ssl = true
122
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
123
+ end
124
+
125
+ http.start do |web|
126
+ if no_body_method.include?(http_method)
127
+ response = web.send(http_method, http_path, headers)
128
+ else
129
+ http_body = env['rack.input']
130
+ http_body.rewind # May not be necessary but can't hurt
131
+
132
+ req = Net::HTTPGenericRequest.new(http_method.upcase,
133
+ true, true, http_path, headers)
134
+ req.body_stream = http_body if length.to_i > 0
135
+ response = web.request(req)
136
+ end
137
+ end
138
+
139
+ status = response.code # http status code
140
+ protocol = proxy[:secure] ? 'https' : 'http'
141
+
142
+ $stderr.puts "~ PROXY: #{http_method.upcase} #{status} #{url} -> #{protocol}://#{http_host}:#{http_port}#{http_path}\n"
143
+
144
+ # display and construct specific response headers
145
+ response_headers = {}
146
+ ignore_headers = ['transfer-encoding', 'keep-alive', 'connection']
147
+ response.each do |key, value|
148
+ next if ignore_headers.include?(key.downcase)
149
+ # If this is a cookie, strip out the domain. This technically may
150
+ # break certain scenarios where services try to set cross-domain
151
+ # cookies, but those services should not be doing that anyway...
152
+ value.gsub!(/domain=[^\;]+\;? ?/,'') if key.downcase == 'set-cookie'
153
+ # Location headers should rewrite the hostname if it is included.
154
+ value.gsub!(/^http:\/\/#{http_host}(:[0-9]+)?\//, "http://#{http_host}/") if key.downcase == 'location'
155
+ # content-length is returning char count not bytesize
156
+ if key.downcase == 'content-length'
157
+ if response.body.respond_to?(:bytesize)
158
+ value = response.body.bytesize.to_s
159
+ elsif response.body.respond_to?(:size)
160
+ value = response.body.size.to_s
161
+ else
162
+ value = '0'
163
+ end
164
+ end
165
+
166
+ $stderr.puts << " #{key}: #{value}\n"
167
+ response_headers[key] = value
168
+ end
169
+
170
+ if [301, 302, 303, 307].include?(status.to_i) && proxy[:redirect] != false
171
+ $stderr.puts '~ REDIRECTING: '+response_headers['location']+"\n"
172
+
173
+ uri = URI.parse(response_headers['location']);
174
+ http_host = uri.host
175
+ http_port = uri.port
176
+ http_path = uri.path
177
+ http_path += '?'+uri.query if uri.query
178
+
179
+ tries += 1
180
+ if tries > 10
181
+ raise "Too many redirects!"
182
+ end
183
+ else
184
+ done = true
185
+ end
186
+ end
187
+
188
+ # Thin doesn't like null bodies
189
+ response_body = response.body || ''
190
+
191
+ return [status, ::Rack::Utils::HeaderHash.new(response_headers), [response_body]]
192
+ end
193
+ end
194
+ end
@@ -38,6 +38,8 @@ end
38
38
 
39
39
  class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
40
40
  def sass_options
41
+ return super if basename.nil?
42
+
41
43
  location_of_sass_file = Middleman::Server.environment == :build ?
42
44
  File.join(Middleman::Server.root, Middleman::Server.build_dir) :
43
45
  Middleman::Server.public
@@ -43,6 +43,9 @@ module Middleman
43
43
  # Activate Yaml Data package
44
44
  register Middleman::Features::Data
45
45
 
46
+ # Activate Webservices Proxy package
47
+ # register Middleman::Features::Proxy
48
+
46
49
  # Activate Lorem helpers
47
50
  register Middleman::Features::Lorem
48
51
 
@@ -1,3 +1,3 @@
1
1
  module Middleman
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
@@ -28,13 +28,11 @@ Gem::Specification.new do |s|
28
28
  s.add_runtime_dependency("padrino-core", ["~> 0.9.23"])
29
29
  s.add_runtime_dependency("padrino-helpers", ["~> 0.9.23"])
30
30
  s.add_runtime_dependency("rack-test", ["~> 0.5.0"])
31
- s.add_runtime_dependency("therubyracer", ["~> 0.8.0"]) unless defined?(JRUBY_VERSION)
32
- s.add_runtime_dependency("therubyrhino", ["~> 1.72.0"]) if defined?(JRUBY_VERSION)
33
31
  s.add_runtime_dependency("uglifier", ["~> 0.5.0"])
34
32
  s.add_runtime_dependency("haml", ["~> 3.1.0"])
35
33
  s.add_runtime_dependency("sass", ["~> 3.1.0"])
36
34
  s.add_runtime_dependency("compass", ["~> 0.11.1"])
37
- s.add_runtime_dependency("coffee-script", ["~> 2.1.0"])
35
+ s.add_runtime_dependency("coffee-script", ["~> 2.2.0"])
38
36
  s.add_runtime_dependency("httparty", ["~> 0.7.0"])
39
37
  # s.add_runtime_dependency("fssm", ["~> 0.2.0"])
40
38
  s.add_development_dependency("cucumber", ["~> 0.10.0"])
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 4
10
- version: 1.2.4
5
+ version: 1.2.5
11
6
  platform: ruby
12
7
  authors:
13
8
  - Thomas Reynolds
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-04-29 00:00:00 -07:00
19
- default_executable:
13
+ date: 2011-05-18 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: rack
@@ -26,10 +20,6 @@ dependencies:
26
20
  requirements:
27
21
  - - ~>
28
22
  - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
23
  version: "1.0"
34
24
  type: :runtime
35
25
  version_requirements: *id001
@@ -41,11 +31,6 @@ dependencies:
41
31
  requirements:
42
32
  - - ~>
43
33
  - !ruby/object:Gem::Version
44
- hash: 31
45
- segments:
46
- - 1
47
- - 2
48
- - 0
49
34
  version: 1.2.0
50
35
  type: :runtime
51
36
  version_requirements: *id002
@@ -57,11 +42,6 @@ dependencies:
57
42
  requirements:
58
43
  - - ~>
59
44
  - !ruby/object:Gem::Version
60
- hash: 63
61
- segments:
62
- - 0
63
- - 8
64
- - 0
65
45
  version: 0.8.0
66
46
  type: :runtime
67
47
  version_requirements: *id003
@@ -73,11 +53,6 @@ dependencies:
73
53
  requirements:
74
54
  - - ~>
75
55
  - !ruby/object:Gem::Version
76
- hash: 39
77
- segments:
78
- - 0
79
- - 14
80
- - 0
81
56
  version: 0.14.0
82
57
  type: :runtime
83
58
  version_requirements: *id004
@@ -89,11 +64,6 @@ dependencies:
89
64
  requirements:
90
65
  - - ~>
91
66
  - !ruby/object:Gem::Version
92
- hash: 27
93
- segments:
94
- - 1
95
- - 3
96
- - 0
97
67
  version: 1.3.0
98
68
  type: :runtime
99
69
  version_requirements: *id005
@@ -105,11 +75,6 @@ dependencies:
105
75
  requirements:
106
76
  - - ~>
107
77
  - !ruby/object:Gem::Version
108
- hash: 31
109
- segments:
110
- - 1
111
- - 2
112
- - 0
113
78
  version: 1.2.0
114
79
  type: :runtime
115
80
  version_requirements: *id006
@@ -121,11 +86,6 @@ dependencies:
121
86
  requirements:
122
87
  - - ~>
123
88
  - !ruby/object:Gem::Version
124
- hash: 21
125
- segments:
126
- - 0
127
- - 9
128
- - 23
129
89
  version: 0.9.23
130
90
  type: :runtime
131
91
  version_requirements: *id007
@@ -137,11 +97,6 @@ dependencies:
137
97
  requirements:
138
98
  - - ~>
139
99
  - !ruby/object:Gem::Version
140
- hash: 21
141
- segments:
142
- - 0
143
- - 9
144
- - 23
145
100
  version: 0.9.23
146
101
  type: :runtime
147
102
  version_requirements: *id008
@@ -153,170 +108,108 @@ dependencies:
153
108
  requirements:
154
109
  - - ~>
155
110
  - !ruby/object:Gem::Version
156
- hash: 11
157
- segments:
158
- - 0
159
- - 5
160
- - 0
161
111
  version: 0.5.0
162
112
  type: :runtime
163
113
  version_requirements: *id009
164
114
  - !ruby/object:Gem::Dependency
165
- name: therubyracer
115
+ name: uglifier
166
116
  prerelease: false
167
117
  requirement: &id010 !ruby/object:Gem::Requirement
168
118
  none: false
169
119
  requirements:
170
120
  - - ~>
171
121
  - !ruby/object:Gem::Version
172
- hash: 63
173
- segments:
174
- - 0
175
- - 8
176
- - 0
177
- version: 0.8.0
122
+ version: 0.5.0
178
123
  type: :runtime
179
124
  version_requirements: *id010
180
125
  - !ruby/object:Gem::Dependency
181
- name: uglifier
126
+ name: haml
182
127
  prerelease: false
183
128
  requirement: &id011 !ruby/object:Gem::Requirement
184
129
  none: false
185
130
  requirements:
186
131
  - - ~>
187
132
  - !ruby/object:Gem::Version
188
- hash: 11
189
- segments:
190
- - 0
191
- - 5
192
- - 0
193
- version: 0.5.0
133
+ version: 3.1.0
194
134
  type: :runtime
195
135
  version_requirements: *id011
196
136
  - !ruby/object:Gem::Dependency
197
- name: haml
137
+ name: sass
198
138
  prerelease: false
199
139
  requirement: &id012 !ruby/object:Gem::Requirement
200
140
  none: false
201
141
  requirements:
202
142
  - - ~>
203
143
  - !ruby/object:Gem::Version
204
- hash: 3
205
- segments:
206
- - 3
207
- - 1
208
- - 0
209
144
  version: 3.1.0
210
145
  type: :runtime
211
146
  version_requirements: *id012
212
147
  - !ruby/object:Gem::Dependency
213
- name: sass
148
+ name: compass
214
149
  prerelease: false
215
150
  requirement: &id013 !ruby/object:Gem::Requirement
216
151
  none: false
217
152
  requirements:
218
153
  - - ~>
219
154
  - !ruby/object:Gem::Version
220
- hash: 3
221
- segments:
222
- - 3
223
- - 1
224
- - 0
225
- version: 3.1.0
155
+ version: 0.11.1
226
156
  type: :runtime
227
157
  version_requirements: *id013
228
158
  - !ruby/object:Gem::Dependency
229
- name: compass
159
+ name: coffee-script
230
160
  prerelease: false
231
161
  requirement: &id014 !ruby/object:Gem::Requirement
232
162
  none: false
233
163
  requirements:
234
164
  - - ~>
235
165
  - !ruby/object:Gem::Version
236
- hash: 49
237
- segments:
238
- - 0
239
- - 11
240
- - 1
241
- version: 0.11.1
166
+ version: 2.2.0
242
167
  type: :runtime
243
168
  version_requirements: *id014
244
- - !ruby/object:Gem::Dependency
245
- name: coffee-script
246
- prerelease: false
247
- requirement: &id015 !ruby/object:Gem::Requirement
248
- none: false
249
- requirements:
250
- - - ~>
251
- - !ruby/object:Gem::Version
252
- hash: 11
253
- segments:
254
- - 2
255
- - 1
256
- - 0
257
- version: 2.1.0
258
- type: :runtime
259
- version_requirements: *id015
260
169
  - !ruby/object:Gem::Dependency
261
170
  name: httparty
262
171
  prerelease: false
263
- requirement: &id016 !ruby/object:Gem::Requirement
172
+ requirement: &id015 !ruby/object:Gem::Requirement
264
173
  none: false
265
174
  requirements:
266
175
  - - ~>
267
176
  - !ruby/object:Gem::Version
268
- hash: 3
269
- segments:
270
- - 0
271
- - 7
272
- - 0
273
177
  version: 0.7.0
274
178
  type: :runtime
275
- version_requirements: *id016
179
+ version_requirements: *id015
276
180
  - !ruby/object:Gem::Dependency
277
181
  name: cucumber
278
182
  prerelease: false
279
- requirement: &id017 !ruby/object:Gem::Requirement
183
+ requirement: &id016 !ruby/object:Gem::Requirement
280
184
  none: false
281
185
  requirements:
282
186
  - - ~>
283
187
  - !ruby/object:Gem::Version
284
- hash: 55
285
- segments:
286
- - 0
287
- - 10
288
- - 0
289
188
  version: 0.10.0
290
189
  type: :development
291
- version_requirements: *id017
190
+ version_requirements: *id016
292
191
  - !ruby/object:Gem::Dependency
293
192
  name: rspec
294
193
  prerelease: false
295
- requirement: &id018 !ruby/object:Gem::Requirement
194
+ requirement: &id017 !ruby/object:Gem::Requirement
296
195
  none: false
297
196
  requirements:
298
197
  - - ">="
299
198
  - !ruby/object:Gem::Version
300
- hash: 3
301
- segments:
302
- - 0
303
199
  version: "0"
304
200
  type: :development
305
- version_requirements: *id018
201
+ version_requirements: *id017
306
202
  - !ruby/object:Gem::Dependency
307
203
  name: rocco
308
204
  prerelease: false
309
- requirement: &id019 !ruby/object:Gem::Requirement
205
+ requirement: &id018 !ruby/object:Gem::Requirement
310
206
  none: false
311
207
  requirements:
312
208
  - - ">="
313
209
  - !ruby/object:Gem::Version
314
- hash: 3
315
- segments:
316
- - 0
317
210
  version: "0"
318
211
  type: :development
319
- version_requirements: *id019
212
+ version_requirements: *id018
320
213
  description:
321
214
  email:
322
215
  - tdreyno@gmail.com
@@ -406,6 +299,7 @@ files:
406
299
  - lib/middleman/features/minify_css.rb
407
300
  - lib/middleman/features/minify_javascript.rb
408
301
  - lib/middleman/features/minify_javascript/rack.rb
302
+ - lib/middleman/features/proxy.rb
409
303
  - lib/middleman/features/relative_assets.rb
410
304
  - lib/middleman/features/tiny_src.rb
411
305
  - lib/middleman/features/ugly_haml.rb
@@ -449,7 +343,6 @@ files:
449
343
  - lib/middleman/templates/xhtml/views/stylesheets/site.css.sass
450
344
  - lib/middleman/version.rb
451
345
  - middleman.gemspec
452
- has_rdoc: true
453
346
  homepage: http://wiki.github.com/tdreyno/middleman
454
347
  licenses: []
455
348
 
@@ -463,23 +356,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
463
356
  requirements:
464
357
  - - ">="
465
358
  - !ruby/object:Gem::Version
466
- hash: 3
467
- segments:
468
- - 0
469
359
  version: "0"
470
360
  required_rubygems_version: !ruby/object:Gem::Requirement
471
361
  none: false
472
362
  requirements:
473
363
  - - ">="
474
364
  - !ruby/object:Gem::Version
475
- hash: 3
476
- segments:
477
- - 0
478
365
  version: "0"
479
366
  requirements: []
480
367
 
481
368
  rubyforge_project: middleman
482
- rubygems_version: 1.5.0
369
+ rubygems_version: 1.7.2
483
370
  signing_key:
484
371
  specification_version: 3
485
372
  summary: A static site generator based on Sinatra. Providing Haml, Sass, Compass, Less, Coffee Script and including minification, compression and cache busting.