tdreyno-middleman 0.2.1 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/Rakefile +1 -0
  2. data/VERSION +1 -1
  3. data/bin/mm-build +2 -2
  4. data/lib/middleman.rb +16 -15
  5. data/middleman.gemspec +54 -2
  6. data/vendor/rack-test/History.txt +64 -0
  7. data/vendor/rack-test/MIT-LICENSE.txt +19 -0
  8. data/vendor/rack-test/README.rdoc +57 -0
  9. data/vendor/rack-test/Rakefile +62 -0
  10. data/vendor/rack-test/lib/rack/mock_session.rb +57 -0
  11. data/vendor/rack-test/lib/rack/test.rb +246 -0
  12. data/vendor/rack-test/lib/rack/test/cookie_jar.rb +169 -0
  13. data/vendor/rack-test/lib/rack/test/methods.rb +73 -0
  14. data/vendor/rack-test/lib/rack/test/mock_digest_request.rb +27 -0
  15. data/vendor/rack-test/lib/rack/test/uploaded_file.rb +36 -0
  16. data/vendor/rack-test/lib/rack/test/utils.rb +75 -0
  17. data/vendor/rack-test/spec/fixtures/config.ru +3 -0
  18. data/vendor/rack-test/spec/fixtures/fake_app.rb +109 -0
  19. data/vendor/rack-test/spec/fixtures/foo.txt +1 -0
  20. data/vendor/rack-test/spec/rack/test/cookie_spec.rb +176 -0
  21. data/vendor/rack-test/spec/rack/test/digest_auth_spec.rb +48 -0
  22. data/vendor/rack-test/spec/rack/test/multipart_spec.rb +85 -0
  23. data/vendor/rack-test/spec/rack/test/utils_spec.rb +44 -0
  24. data/vendor/rack-test/spec/rack/test_spec.rb +363 -0
  25. data/vendor/rack-test/spec/rcov.opts +1 -0
  26. data/vendor/rack-test/spec/spec.opts +1 -0
  27. data/vendor/rack-test/spec/spec_helper.rb +48 -0
  28. data/vendor/sinatra-markaby/CHANGES +7 -0
  29. data/vendor/sinatra-markaby/LICENSE +20 -0
  30. data/vendor/sinatra-markaby/README.rdoc +33 -0
  31. data/vendor/sinatra-markaby/Rakefile +45 -0
  32. data/vendor/sinatra-markaby/TODO +3 -0
  33. data/vendor/sinatra-markaby/VERSION.yml +4 -0
  34. data/vendor/sinatra-markaby/lib/sinatra/markaby.rb +31 -0
  35. data/vendor/sinatra-markaby/sinatra-markaby.gemspec +49 -0
  36. data/vendor/sinatra-markaby/test/sinatra_markaby_test.rb +72 -0
  37. data/vendor/sinatra-markaby/test/test_helper.rb +19 -0
  38. data/vendor/sinatra-markaby/test/views/hello.mab +1 -0
  39. data/vendor/sinatra-markaby/test/views/html.mab +4 -0
  40. data/vendor/sinatra-maruku/LICENSE +22 -0
  41. data/vendor/sinatra-maruku/README.markdown +85 -0
  42. data/vendor/sinatra-maruku/Rakefile +34 -0
  43. data/vendor/sinatra-maruku/VERSION.yml +4 -0
  44. data/vendor/sinatra-maruku/examples/app.rb +8 -0
  45. data/vendor/sinatra-maruku/examples/config.ru +4 -0
  46. data/vendor/sinatra-maruku/examples/mapp.rb +15 -0
  47. data/vendor/sinatra-maruku/examples/public/javascripts/application.js +0 -0
  48. data/vendor/sinatra-maruku/examples/public/stylesheets/application.css +23 -0
  49. data/vendor/sinatra-maruku/examples/public/stylesheets/print.css +0 -0
  50. data/vendor/sinatra-maruku/examples/views/index.maruku +32 -0
  51. data/vendor/sinatra-maruku/examples/views/layout.maruku +9 -0
  52. data/vendor/sinatra-maruku/lib/sinatra/maruku.rb +25 -0
  53. data/vendor/sinatra-maruku/sinatra-maruku.gemspec +70 -0
  54. data/vendor/sinatra-maruku/test/sinatra_maruku_test.rb +91 -0
  55. data/vendor/sinatra-maruku/test/test_helper.rb +21 -0
  56. data/vendor/sinatra-maruku/test/views/hello.maruku +1 -0
  57. data/vendor/sinatra-maruku/test/views/layout2.maruku +2 -0
  58. metadata +53 -1
@@ -0,0 +1,169 @@
1
+ require "uri"
2
+ module Rack
3
+ module Test
4
+
5
+ class Cookie
6
+ include Rack::Utils
7
+
8
+ # :api: private
9
+ attr_reader :name, :value
10
+
11
+ # :api: private
12
+ def initialize(raw, uri = nil, default_host = DEFAULT_HOST)
13
+ @default_host = default_host
14
+ uri ||= default_uri
15
+
16
+ # separate the name / value pair from the cookie options
17
+ @name_value_raw, options = raw.split(/[;,] */n, 2)
18
+
19
+ @name, @value = parse_query(@name_value_raw, ';').to_a.first
20
+ @options = parse_query(options, ';')
21
+
22
+ @options["domain"] ||= (uri.host || default_host)
23
+ @options["path"] ||= uri.path.sub(/\/[^\/]*\Z/, "")
24
+ end
25
+
26
+ def replaces?(other)
27
+ [name.downcase, domain, path] == [other.name.downcase, other.domain, other.path]
28
+ end
29
+
30
+ # :api: private
31
+ def raw
32
+ @name_value_raw
33
+ end
34
+
35
+ # :api: private
36
+ def empty?
37
+ @value.nil? || @value.empty?
38
+ end
39
+
40
+ # :api: private
41
+ def domain
42
+ @options["domain"]
43
+ end
44
+
45
+ def secure?
46
+ @options.has_key?("secure")
47
+ end
48
+
49
+ # :api: private
50
+ def path
51
+ @options["path"].strip || "/"
52
+ end
53
+
54
+ # :api: private
55
+ def expires
56
+ Time.parse(@options["expires"]) if @options["expires"]
57
+ end
58
+
59
+ # :api: private
60
+ def expired?
61
+ expires && expires < Time.now
62
+ end
63
+
64
+ # :api: private
65
+ def valid?(uri)
66
+ uri ||= default_uri
67
+
68
+ if uri.host.nil?
69
+ uri.host = @default_host
70
+ end
71
+
72
+ (!secure? || (secure? && uri.scheme == "https")) &&
73
+ uri.host =~ Regexp.new("#{Regexp.escape(domain)}$", Regexp::IGNORECASE) &&
74
+ uri.path =~ Regexp.new("^#{Regexp.escape(path)}")
75
+ end
76
+
77
+ # :api: private
78
+ def matches?(uri)
79
+ ! expired? && valid?(uri)
80
+ end
81
+
82
+ # :api: private
83
+ def <=>(other)
84
+ # Orders the cookies from least specific to most
85
+ [name, path, domain.reverse] <=> [other.name, other.path, other.domain.reverse]
86
+ end
87
+
88
+ protected
89
+
90
+ def default_uri
91
+ URI.parse("//" + @default_host + "/")
92
+ end
93
+
94
+ end
95
+
96
+ class CookieJar
97
+
98
+ # :api: private
99
+ def initialize(cookies = [], default_host = DEFAULT_HOST)
100
+ @default_host = default_host
101
+ @cookies = cookies
102
+ @cookies.sort!
103
+ end
104
+
105
+ def [](name)
106
+ cookies = hash_for(nil)
107
+ # TODO: Should be case insensitive
108
+ cookies[name] && cookies[name].value
109
+ end
110
+
111
+ def []=(name, value)
112
+ # TODO: needs proper escaping
113
+ merge("#{name}=#{value}")
114
+ end
115
+
116
+ def merge(raw_cookies, uri = nil)
117
+ return unless raw_cookies
118
+
119
+ Array(raw_cookies).join("\n").split("\n").each do |raw_cookie|
120
+ cookie = Cookie.new(raw_cookie, uri, @default_host)
121
+ self << cookie if cookie.valid?(uri)
122
+ end
123
+ end
124
+
125
+ def <<(new_cookie)
126
+ @cookies.reject! do |existing_cookie|
127
+ new_cookie.replaces?(existing_cookie)
128
+ end
129
+
130
+ @cookies << new_cookie
131
+ @cookies.sort!
132
+ end
133
+
134
+ # :api: private
135
+ def for(uri)
136
+ hash_for(uri).values.map { |c| c.raw }.join(';')
137
+ end
138
+
139
+ def to_hash
140
+ cookies = {}
141
+
142
+ hash_for(nil).each do |name, cookie|
143
+ cookies[name] = cookie.value
144
+ end
145
+
146
+ return cookies
147
+ end
148
+
149
+ protected
150
+
151
+ def hash_for(uri = nil)
152
+ cookies = {}
153
+
154
+ # The cookies are sorted by most specific first. So, we loop through
155
+ # all the cookies in order and add it to a hash by cookie name if
156
+ # the cookie can be sent to the current URI. It's added to the hash
157
+ # so that when we are done, the cookies will be unique by name and
158
+ # we'll have grabbed the most specific to the URI.
159
+ @cookies.each do |cookie|
160
+ cookies[cookie.name] = cookie if cookie.matches?(uri)
161
+ end
162
+
163
+ return cookies
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+ end
@@ -0,0 +1,73 @@
1
+ require "forwardable"
2
+
3
+ module Rack
4
+ module Test
5
+ module Methods
6
+ extend Forwardable
7
+
8
+ def rack_mock_session(name = :default)
9
+ return build_rack_mock_session unless name
10
+
11
+ @_rack_mock_sessions ||= {}
12
+ @_rack_mock_sessions[name] ||= build_rack_mock_session
13
+ end
14
+
15
+ def build_rack_mock_session
16
+ Rack::MockSession.new(app)
17
+ end
18
+
19
+ def rack_test_session(name = :default)
20
+ return build_rack_test_session(name) unless name
21
+
22
+ @_rack_test_sessions ||= {}
23
+ @_rack_test_sessions[name] ||= build_rack_test_session(name)
24
+ end
25
+
26
+ def build_rack_test_session(name)
27
+ Rack::Test::Session.new(rack_mock_session(name))
28
+ end
29
+
30
+ def current_session
31
+ rack_test_session(_current_session_names.last)
32
+ end
33
+
34
+ def with_session(name)
35
+ _current_session_names.push(name)
36
+ yield rack_test_session(name)
37
+ _current_session_names.pop
38
+ end
39
+
40
+ def _current_session_names
41
+ @_current_session_names ||= [:default]
42
+ end
43
+
44
+ METHODS = [
45
+ :request,
46
+
47
+ # HTTP verbs
48
+ :get,
49
+ :post,
50
+ :put,
51
+ :delete,
52
+ :head,
53
+
54
+ # Redirects
55
+ :follow_redirect!,
56
+
57
+ # Header-related features
58
+ :header,
59
+ :set_cookie,
60
+ :clear_cookies,
61
+ :authorize,
62
+ :basic_authorize,
63
+ :digest_authorize,
64
+
65
+ # Expose the last request and response
66
+ :last_response,
67
+ :last_request
68
+ ]
69
+
70
+ def_delegators :current_session, *METHODS
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,27 @@
1
+ module Rack
2
+ module Test
3
+
4
+ class MockDigestRequest
5
+ def initialize(params)
6
+ @params = params
7
+ end
8
+
9
+ def method_missing(sym)
10
+ if @params.has_key? k = sym.to_s
11
+ return @params[k]
12
+ end
13
+
14
+ super
15
+ end
16
+
17
+ def method
18
+ @params['method']
19
+ end
20
+
21
+ def response(password)
22
+ Rack::Auth::Digest::MD5.new(nil).send :digest, self, password
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ require "tempfile"
2
+
3
+ module Rack
4
+ module Test
5
+
6
+ class UploadedFile
7
+ # The filename, *not* including the path, of the "uploaded" file
8
+ attr_reader :original_filename
9
+
10
+ # The content type of the "uploaded" file
11
+ attr_accessor :content_type
12
+
13
+ def initialize(path, content_type = "text/plain", binary = false)
14
+ raise "#{path} file does not exist" unless ::File.exist?(path)
15
+ @content_type = content_type
16
+ @original_filename = ::File.basename(path)
17
+ @tempfile = Tempfile.new(@original_filename)
18
+ @tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
19
+ @tempfile.binmode if binary
20
+ FileUtils.copy_file(path, @tempfile.path)
21
+ end
22
+
23
+ def path
24
+ @tempfile.path
25
+ end
26
+
27
+ alias_method :local_path, :path
28
+
29
+ def method_missing(method_name, *args, &block) #:nodoc:
30
+ @tempfile.__send__(method_name, *args, &block)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,75 @@
1
+ module Rack
2
+ module Test
3
+
4
+ module Utils
5
+ include Rack::Utils
6
+
7
+ def requestify(value, prefix = nil)
8
+ case value
9
+ when Array
10
+ value.map do |v|
11
+ requestify(v, "#{prefix}[]")
12
+ end.join("&")
13
+ when Hash
14
+ value.map do |k, v|
15
+ requestify(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
16
+ end.join("&")
17
+ else
18
+ "#{prefix}=#{escape(value)}"
19
+ end
20
+ end
21
+
22
+ module_function :requestify
23
+
24
+ def multipart_requestify(params, first=true)
25
+ p = Hash.new
26
+
27
+ params.each do |key, value|
28
+ k = first ? key.to_s : "[#{key}]"
29
+
30
+ if Hash === value
31
+ multipart_requestify(value, false).each do |subkey, subvalue|
32
+ p[k + subkey] = subvalue
33
+ end
34
+ else
35
+ p[k] = value
36
+ end
37
+ end
38
+
39
+ return p
40
+ end
41
+
42
+ module_function :multipart_requestify
43
+
44
+ def multipart_body(params)
45
+ multipart_requestify(params).map do |key, value|
46
+ if value.respond_to?(:original_filename)
47
+ ::File.open(value.path, "rb") do |f|
48
+ f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding)
49
+
50
+ <<-EOF
51
+ --#{MULTIPART_BOUNDARY}\r
52
+ Content-Disposition: form-data; name="#{key}"; filename="#{escape(value.original_filename)}"\r
53
+ Content-Type: #{value.content_type}\r
54
+ Content-Length: #{::File.stat(value.path).size}\r
55
+ \r
56
+ #{f.read}\r
57
+ EOF
58
+ end
59
+ else
60
+ <<-EOF
61
+ --#{MULTIPART_BOUNDARY}\r
62
+ Content-Disposition: form-data; name="#{key}"\r
63
+ \r
64
+ #{value}\r
65
+ EOF
66
+ end
67
+ end.join("")+"--#{MULTIPART_BOUNDARY}--\r"
68
+ end
69
+
70
+ module_function :multipart_body
71
+
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ require "fake_app"
2
+
3
+ run Rack::Test::FakeApp
@@ -0,0 +1,109 @@
1
+ require "sinatra/base"
2
+
3
+ module Rack
4
+ module Test
5
+
6
+ class FakeApp < Sinatra::Default
7
+ head "/" do
8
+ "meh"
9
+ end
10
+
11
+ get "/" do
12
+ "Hello, GET: #{params.inspect}"
13
+ end
14
+
15
+ get "/redirect" do
16
+ redirect "/redirected"
17
+ end
18
+
19
+ get "/redirected" do
20
+ "You've been redirected"
21
+ end
22
+
23
+ get "/void" do
24
+ [200, {}, ""]
25
+ end
26
+
27
+ get "/cookies/show" do
28
+ request.cookies.inspect
29
+ end
30
+
31
+ get "/COOKIES/show" do
32
+ request.cookies.inspect
33
+ end
34
+
35
+ get "/not-cookies/show" do
36
+ request.cookies.inspect
37
+ end
38
+
39
+ get "/cookies/set-secure" do
40
+ raise if params["value"].nil?
41
+
42
+ response.set_cookie("secure-cookie", :value => params["value"], :secure => true)
43
+ "Set"
44
+ end
45
+
46
+ get "/cookies/set-simple" do
47
+ raise if params["value"].nil?
48
+
49
+ response.set_cookie "simple", params["value"]
50
+ "Set"
51
+ end
52
+
53
+ get "/cookies/delete" do
54
+ response.delete_cookie "value"
55
+ end
56
+
57
+ get "/cookies/count" do
58
+ old_value = request.cookies["count"].to_i || 0
59
+ new_value = (old_value + 1).to_s
60
+
61
+ response.set_cookie("count", :value => new_value)
62
+ new_value
63
+ end
64
+
65
+ get "/cookies/set" do
66
+ raise if params["value"].nil?
67
+
68
+ response.set_cookie("value", {
69
+ :value => params["value"],
70
+ :path => "/cookies",
71
+ :expires => Time.now + 10
72
+ })
73
+ "Set"
74
+ end
75
+
76
+ get "/cookies/domain" do
77
+ old_value = request.cookies["count"].to_i || 0
78
+ new_value = (old_value + 1).to_s
79
+
80
+ response.set_cookie("count", :value => new_value, :domain => "localhost.com")
81
+ new_value
82
+ end
83
+
84
+ get "/cookies/set-uppercase" do
85
+ raise if params["value"].nil?
86
+
87
+ response.set_cookie("VALUE", {
88
+ :value => params["value"],
89
+ :path => "/cookies",
90
+ :expires => Time.now + 10
91
+ })
92
+ "Set"
93
+ end
94
+
95
+ post "/" do
96
+ "Hello, POST: #{params.inspect}"
97
+ end
98
+
99
+ put "/" do
100
+ "Hello, PUT: #{params.inspect}"
101
+ end
102
+
103
+ delete "/" do
104
+ "Hello, DELETE: #{params.inspect}"
105
+ end
106
+ end
107
+
108
+ end
109
+ end