renee 0.4.0.pre1 → 0.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/Gemfile +11 -8
  2. data/README.md +50 -1
  3. data/Rakefile +14 -104
  4. data/config.ru +5 -0
  5. data/examples/blog/config.ru +1 -0
  6. data/lib/renee.rb +3 -2
  7. data/lib/renee/render.rb +1 -1
  8. data/lib/renee/url_generation.rb +66 -45
  9. data/lib/renee/version.rb +1 -1
  10. data/plan.txt +1 -5
  11. data/renee.gemspec +3 -3
  12. data/site/public/css/app.css +47 -26
  13. data/site/views/extending.md +66 -0
  14. data/site/views/index.md +14 -4
  15. data/site/views/routing.md +0 -38
  16. data/site/views/variable-types.md +2 -2
  17. data/test/{renee/blog_test.rb → blog_test.rb} +0 -0
  18. data/test/{renee-render/render_test.rb → render_test.rb} +0 -0
  19. data/test/renee-url-generation/test_helper.rb +1 -1
  20. data/test/{renee-session/session_test.rb → session_test.rb} +2 -2
  21. data/test/renee/test_helper.rb b/data/test/test_helper → copy.rb +0 -0
  22. data/test/test_helper.rb +8 -1
  23. data/test/{renee-url-generation/url_generation_test.rb → url_generation_test.rb} +2 -2
  24. metadata +47 -77
  25. data/Gemfile-renee +0 -8
  26. data/Gemfile-renee-core +0 -8
  27. data/Gemfile-renee-render +0 -9
  28. data/Gemfile-renee-session +0 -9
  29. data/Gemfile-renee-url-generation +0 -8
  30. data/README-renee-core.md +0 -242
  31. data/README-renee-render.md +0 -38
  32. data/README-renee-session.md +0 -3
  33. data/README-renee-url-generation.md +0 -3
  34. data/lib/renee/core.rb +0 -98
  35. data/lib/renee/core/chaining.rb +0 -66
  36. data/lib/renee/core/env_accessors.rb +0 -72
  37. data/lib/renee/core/exceptions.rb +0 -15
  38. data/lib/renee/core/matcher.rb +0 -61
  39. data/lib/renee/core/plugins.rb +0 -31
  40. data/lib/renee/core/rack_interaction.rb +0 -50
  41. data/lib/renee/core/request_context.rb +0 -56
  42. data/lib/renee/core/responding.rb +0 -112
  43. data/lib/renee/core/response.rb +0 -78
  44. data/lib/renee/core/routing.rb +0 -319
  45. data/lib/renee/core/transform.rb +0 -18
  46. data/renee-core.gemspec +0 -26
  47. data/renee-render.gemspec +0 -30
  48. data/renee-session.gemspec +0 -28
  49. data/renee-url-generation.gemspec +0 -24
  50. data/test.watchr +0 -61
  51. data/test/renee-core/chaining_test.rb +0 -33
  52. data/test/renee-core/env_accessors_test.rb +0 -43
  53. data/test/renee-core/include_test.rb +0 -14
  54. data/test/renee-core/request_context_test.rb +0 -70
  55. data/test/renee-core/responding_test.rb +0 -128
  56. data/test/renee-core/routing_test.rb +0 -443
  57. data/test/renee-core/test_helper.rb +0 -4
  58. data/test/renee-core/variable_type_test.rb +0 -57
@@ -1,319 +0,0 @@
1
- module Renee
2
- class Core
3
- # Collection of useful methods for routing within a {Renee::Core} app.
4
- module Routing
5
- include Chaining
6
-
7
- # Allow continued routing if a routing block fails to match
8
- #
9
- # @param [Boolean] val
10
- # indicate if continued routing should be allowed.
11
- #
12
- # @api public
13
- def continue_routing
14
- if block_given?
15
- original_env = @env.dup
16
- begin
17
- yield
18
- rescue NotMatchedError
19
- @env = original_env
20
- end
21
- else
22
- create_chain_proxy(:continue_routing)
23
- end
24
- end
25
- chainable :continue_routing
26
-
27
- # Match a path to respond to.
28
- #
29
- # @param [String] p
30
- # path to match.
31
- # @param [Proc] blk
32
- # block to yield
33
- #
34
- # @example
35
- # path('/') { ... } #=> '/'
36
- # path('test') { ... } #=> '/test'
37
- #
38
- # path 'foo' do
39
- # path('bar') { ... } #=> '/foo/bar'
40
- # end
41
- #
42
- # @api public
43
- def path(p, &blk)
44
- if blk
45
- p = p[1, p.size] if p[0] == ?/
46
- extension_part = detected_extension ? "|\\.#{Regexp.quote(detected_extension)}" : ""
47
- part(/^\/#{Regexp.quote(p)}(?=\/|$#{extension_part})/, &blk)
48
- else
49
- create_chain_proxy(:path, p)
50
- end
51
- end
52
- chainable :path
53
-
54
- # Like #path, but doesn't look for leading slashes.
55
- def part(p)
56
- if block_given?
57
- p = /^\/?#{Regexp.quote(p)}/ if p.is_a?(String)
58
- if match = env['PATH_INFO'][p]
59
- with_path_part(match) { yield }
60
- end
61
- else
62
- create_chain_proxy(:part, p)
63
- end
64
- end
65
-
66
- # Match parts off the path as variables. The parts matcher can conform to either a regular expression, or be an Integer, or
67
- # simply a String.
68
- # @param[Object] type the type of object to match for. If you supply Integer, this will only match integers in addition to casting your variable for you.
69
- # @param[Object] default the default value to use if your param cannot be successfully matched.
70
- #
71
- # @example
72
- # path '/' do
73
- # variable { |id| halt [200, {}, id] }
74
- # end
75
- # GET /hey #=> [200, {}, 'hey']
76
- #
77
- # @example
78
- # path '/' do
79
- # variable(:integer) { |id| halt [200, {}, "This is a numeric id: #{id}"] }
80
- # end
81
- # GET /123 #=> [200, {}, 'This is a numeric id: 123']
82
- #
83
- # @example
84
- # path '/test' do
85
- # variable { |foo, bar| halt [200, {}, "#{foo}-#{bar}"] }
86
- # end
87
- # GET /test/hey/there #=> [200, {}, 'hey-there']
88
- #
89
- # @api public
90
- def variable(type = nil, &blk)
91
- blk ? complex_variable(type, '/', 1, &blk) : create_chain_proxy(:variable, type)
92
- end
93
- alias_method :var, :variable
94
- chainable :variable, :var
95
-
96
- def optional_variable(type = nil, &blk)
97
- blk ? complex_variable(type, '/', 0..1) { |vars| blk[vars.first] } : create_chain_proxy(:variable, type)
98
- end
99
- alias_method :optional, :optional_variable
100
- chainable :optional, :optional_variable
101
-
102
- # Same as variable except you can match multiple variables with the same type.
103
- # @param [Range, Integer] count The number of parameters to capture.
104
- # @param [Symbol] type The type to use for match.
105
- def multi_variable(count, type = nil, &blk)
106
- blk ? complex_variable(type, '/', count, &blk) : create_chain_proxy(:multi_variable, count, type)
107
- end
108
- alias_method :multi_var, :multi_variable
109
- alias_method :mvar, :multi_variable
110
- chainable :multi_variable, :multi_var, :mvar
111
-
112
- # Same as variable except it matches indefinitely.
113
- # @param [Symbol] type The type to use for match.
114
- def repeating_variable(type = nil, &blk)
115
- blk ? complex_variable(type, '/', nil, &blk) : create_chain_proxy(:repeating_variable, type)
116
- end
117
- alias_method :glob, :repeating_variable
118
- chainable :repeating_variable, :glob
119
-
120
- # Match parts off the path as variables without a leading slash.
121
- # @see #variable
122
- # @api public
123
- def partial_variable(type = nil, &blk)
124
- blk ? complex_variable(type, nil, 1, &blk) : create_chain_proxy(:partial_variable, type)
125
- end
126
- alias_method :part_var, :partial_variable
127
- chainable :partial_variable, :part_var
128
-
129
- # Returns the matched extension. If no extension is present, returns `nil`.
130
- #
131
- # @example
132
- # halt [200, {}, path] if extension == 'html'
133
- #
134
- # @api public
135
- def extension
136
- detected_extension
137
- end
138
- alias_method :ext, :extension
139
-
140
- # Match no extension.
141
- #
142
- # @example
143
- # no_extension { |path| halt [200, {}, path] }
144
- #
145
- # @api public
146
- def no_extension(&blk)
147
- blk.call unless detected_extension
148
- end
149
-
150
- # Match any remaining path.
151
- #
152
- # @example
153
- # remainder { |path| halt [200, {}, path] }
154
- #
155
- # @api public
156
- def remainder(&blk)
157
- blk ? with_path_part(env['PATH_INFO']) { |var| blk.call(var) } : create_chain_proxy(:remainder)
158
- end
159
- alias_method :catchall, :remainder
160
- chainable :remainder, :catchall
161
-
162
- # Respond to a GET request and yield the block.
163
- #
164
- # @example
165
- # get { halt [200, {}, "hello world"] }
166
- #
167
- # @api public
168
- def get(&blk)
169
- blk ? request_method('GET', &blk) : create_chain_proxy(:get)
170
- end
171
- chainable :get
172
-
173
- # Respond to a POST request and yield the block.
174
- #
175
- # @example
176
- # post { halt [200, {}, "hello world"] }
177
- #
178
- # @api public
179
- def post(&blk)
180
- blk ? request_method('POST', &blk) : create_chain_proxy(:post)
181
- end
182
- chainable :post
183
-
184
- # Respond to a PUT request and yield the block.
185
- #
186
- # @example
187
- # put { halt [200, {}, "hello world"] }
188
- #
189
- # @api public
190
- def put(&blk)
191
- blk ? request_method('PUT', &blk) : create_chain_proxy(:put)
192
- end
193
- chainable :put
194
-
195
- # Respond to a DELETE request and yield the block.
196
- #
197
- # @example
198
- # delete { halt [200, {}, "hello world"] }
199
- #
200
- # @api public
201
- def delete(&blk)
202
- blk ? request_method('DELETE', &blk) : create_chain_proxy(:delete)
203
- end
204
- chainable :delete
205
-
206
- # Match only when the path is either '' or '/'.
207
- #
208
- # @example
209
- # complete { halt [200, {}, "hello world"] }
210
- #
211
- # @api public
212
- def complete(&blk)
213
- if blk
214
- with_path_part(env['PATH_INFO']) { blk.call } if complete?
215
- else
216
- create_chain_proxy(:complete)
217
- end
218
- end
219
- chainable :complete
220
-
221
- # Test if the path has been consumed
222
- #
223
- # @example
224
- # if complete?
225
- # halt "Hey, the path is done"
226
- # end
227
- #
228
- # @api public
229
- def complete?
230
- (detected_extension and env['PATH_INFO'] =~ /^\/?(\.#{Regexp.quote(detected_extension)}\/?)?$/) || (detected_extension.nil? and env['PATH_INFO'] =~ /^\/?$/)
231
- end
232
-
233
- # Match only when the path is ''.
234
- #
235
- # @example
236
- # empty { halt [200, {}, "hello world"] }
237
- #
238
- # @api public
239
- def empty(&blk)
240
- if blk
241
- if env['PATH_INFO'] == ''
242
- with_path_part(env['PATH_INFO']) { blk.call }
243
- end
244
- else
245
- create_chain_proxy(:empty)
246
- end
247
- end
248
- chainable :empty
249
-
250
- private
251
- def complex_variable(type, prefix, count)
252
- matcher = variable_matcher_for_type(type)
253
- path = env['PATH_INFO'].dup
254
- vals = []
255
- var_index = 0
256
- variable_matching_loop(count) do
257
- path.start_with?(prefix) ? path.slice!(0, prefix.size) : break if prefix
258
- if match = matcher[path]
259
- path.slice!(0, match.first.size)
260
- vals << match.last
261
- end
262
- end
263
- return unless count.nil? || count === vals.size
264
- with_path_part(env['PATH_INFO'][0, env['PATH_INFO'].size - path.size]) do
265
- if count == 1
266
- yield(vals.first)
267
- else
268
- yield(vals)
269
- end
270
- end
271
- end
272
-
273
- def variable_matching_loop(count)
274
- case count
275
- when Range then count.max.times { break unless yield }
276
- when nil then loop { break unless yield }
277
- else count.times { break unless yield }
278
- end
279
- end
280
-
281
- def variable_matcher_for_type(type)
282
- if self.class.variable_types.key?(type)
283
- self.class.variable_types[type]
284
- else
285
- regexp = case type
286
- when nil, String
287
- detected_extension ?
288
- /(([^\/](?!#{Regexp.quote(detected_extension)}$))+)(?=$|\/|\.#{Regexp.quote(detected_extension)})/ :
289
- /([^\/]+)(?=$|\/)/
290
- when Regexp
291
- type
292
- else
293
- raise "Unexpected variable type #{type.inspect}"
294
- end
295
- proc do |path|
296
- if match = /^#{regexp.to_s}/.match(path)
297
- [match[0]]
298
- end
299
- end
300
- end
301
- end
302
-
303
- def with_path_part(part)
304
- script_part = env['PATH_INFO'][0, part.size]
305
- env['PATH_INFO'] = env['PATH_INFO'].slice(part.size, env['PATH_INFO'].size)
306
- env['SCRIPT_NAME'] += script_part
307
- yield script_part
308
- raise NotMatchedError
309
- end
310
-
311
- def request_method(method)
312
- if env['REQUEST_METHOD'] == method && complete?
313
- yield
314
- raise NotMatchedError
315
- end
316
- end
317
- end
318
- end
319
- end
@@ -1,18 +0,0 @@
1
- module Renee
2
- class Core
3
- # Module used for transforming arbitrary values using the registerd variable types.
4
- # @see #register_variable_name.
5
- #
6
- module Transform
7
- # Transforms a value according to the rules specified by #register_variable_name.
8
- # @param [Symbol] name The name of the variable type.
9
- # @param [String] value The value to transform.
10
- # @return The transformed value or nil.
11
- def transform(type, value)
12
- if self.class.variable_types.key?(type) and m = self.class.variable_types[type][value]
13
- m.first == value ? m.last : nil
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,26 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "renee/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "renee-core"
7
- s.version = Renee::VERSION
8
- s.authors = ["Josh Hull", "Nathan Esquenazi", "Arthur Chiu"]
9
- s.email = ["joshbuddy@gmail.com", "nesquena@gmail.com", "mr.arthur.chiu@gmail.com"]
10
- s.homepage = "http://reneerb.com"
11
- s.summary = %q{The super-friendly rack helpers}
12
- s.description = %q{The super-friendly rack helpers.}
13
-
14
- s.rubyforge_project = "renee-core"
15
-
16
- s.files = `git ls-files -- lib/renee/core*`.split("\n")
17
- s.test_files = `git ls-files -- test/renee-core/*`.split("\n") + ["test/test_helper.rb"]
18
- s.require_paths = ["lib"]
19
-
20
- s.add_runtime_dependency 'rack', "~> 1.3.0"
21
-
22
- s.add_development_dependency 'minitest', "~> 2.6.1"
23
- s.add_development_dependency 'bundler'
24
- s.add_development_dependency "rack-test", ">= 0.5.0"
25
- s.add_development_dependency "rake"
26
- end
@@ -1,30 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "renee/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "renee-render"
7
- s.version = Renee::VERSION
8
- s.authors = ["Josh Hull", "Nathan Esquenazi", "Arthur Chiu"]
9
- s.email = ["joshbuddy@gmail.com", "nesquena@gmail.com", "mr.arthur.chiu@gmail.com"]
10
- s.homepage = "http://reneerb.com"
11
- s.summary = %q{The super-friendly web framework rendering component}
12
- s.description = %q{The super-friendly web framework rendering component.}
13
-
14
- s.rubyforge_project = "renee-render"
15
-
16
- s.files = `git ls-files -- lib/renee/render*`.split("\n")
17
- s.test_files = `git ls-files -- test/renee-render/*`.split("\n") + ["test/test_helper.rb"]
18
- s.require_paths = ["lib"]
19
-
20
- s.add_runtime_dependency 'rack', "~> 1.3.0"
21
- s.add_runtime_dependency 'tilt', "~> 1.3.3"
22
- s.add_runtime_dependency 'callsite', '~> 0.0.6'
23
- s.add_runtime_dependency 'renee-core', "#{Renee::VERSION}"
24
-
25
- s.add_development_dependency 'minitest', "~> 2.6.1"
26
- s.add_development_dependency 'rake'
27
- s.add_development_dependency 'bundler'
28
- s.add_development_dependency "rack-test", ">= 0.5.0"
29
- s.add_development_dependency "haml", ">= 2.2.0"
30
- end
@@ -1,28 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "renee/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "renee-session"
7
- s.version = Renee::VERSION
8
- s.authors = ["Josh Hull"]
9
- s.email = ["joshbuddy@gmail.com"]
10
- s.homepage = "http://reneerb.com"
11
- s.summary = %q{The super-friendly web framework session component}
12
- s.description = %q{The super-friendly web framework session component.}
13
-
14
- s.rubyforge_project = "renee-session"
15
-
16
- s.files = `git ls-files -- lib/renee/session*`.split("\n")
17
- s.test_files = `git ls-files -- test/renee-session/*`.split("\n") + ["test/test_helper.rb"]
18
- s.require_paths = ["lib"]
19
-
20
- s.add_runtime_dependency 'rack', "~> 1.3.0"
21
- s.add_runtime_dependency 'renee-core', "#{Renee::VERSION}"
22
-
23
- s.add_development_dependency 'minitest', "~> 2.6.1"
24
- s.add_development_dependency 'rake'
25
- s.add_development_dependency 'bundler'
26
- s.add_development_dependency "rack-test", ">= 0.5.0"
27
- s.add_development_dependency "haml", ">= 2.2.0"
28
- end
@@ -1,24 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "renee/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "renee-url-generation"
7
- s.version = Renee::VERSION
8
- s.authors = ["Josh Hull", "Nathan Esquenazi", "Arthur Chiu"]
9
- s.email = ["joshbuddy@gmail.com", "nesquena@gmail.com", "mr.arthur.chiu@gmail.com"]
10
- s.homepage = "http://reneerb.com"
11
- s.summary = %q{The super-friendly rack helpers -- URL generation}
12
- s.description = %q{The super-friendly rack helpers -- URL generation.}
13
-
14
- s.rubyforge_project = "renee-url-generation"
15
-
16
- s.files = `git ls-files -- lib/renee/core*`.split("\n")
17
- s.test_files = `git ls-files -- test/renee-core/*`.split("\n") + ["test/test_helper.rb"]
18
- s.require_paths = ["lib"]
19
-
20
- s.add_development_dependency 'minitest', "~> 2.6.1"
21
- s.add_development_dependency 'bundler'
22
- s.add_development_dependency "rack-test", ">= 0.5.0"
23
- s.add_development_dependency "rake"
24
- end