hobbit 0.0.3 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9539a9f971f1c9ce832fc5d01b91426268ae7ad5
4
- data.tar.gz: ba9c03f191da3ca5582ffd605a860e58b4d1b6e0
3
+ metadata.gz: a40ad5190f62122b017865652dd404d685679bbd
4
+ data.tar.gz: 68ab170cf365e621b439e3c95c37d68b27391213
5
5
  SHA512:
6
- metadata.gz: f9d0975a41d756f846b0f188039af5783de409f56e5637c8599eaa12cd2a218d351a5e100cabe7a87b03bcd2e7b7b9e7996fded1cf542680fcaeb7028cd70805
7
- data.tar.gz: 4d492a410464fe67e13e015e8ef2307a58a19701be4661d99a42f445c6dea7157517bd64ade2bafd9f76931d1cf707e608b1f28d2f25d175708c1aadc94b88e1
6
+ metadata.gz: 655b5ebd8ff4cb2df724c477ab376c801f9d3a2c303a0ad417ad0670600d4900bba76eb0404ca0879df63ffc9323ffdc1d64abcb45b802289d04e8c868ac4d46
7
+ data.tar.gz: 3024565ad30b77a25403b7f7863667293101ba3bbbf7960d9f15f99733e28128f87bc29e3fc877cc1938f69b5a75519581aa83287718e9fe9ff7b6e692813fe8
data/.gitignore CHANGED
@@ -8,8 +8,6 @@ InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
10
  doc/
11
- examples/example_1/Gemfile.lock
12
- examples/example_2/Gemfile.lock
13
11
  lib/bundler/man
14
12
  pkg
15
13
  rdoc
data/README.md CHANGED
@@ -1,7 +1,4 @@
1
- # Hobbit
2
-
3
- [![Build Status](https://travis-ci.org/patriciomacadden/hobbit.png?branch=master)](https://travis-ci.org/patriciomacadden/hobbit)
4
- [![Code Climate](https://codeclimate.com/github/patriciomacadden/hobbit.png)](https://codeclimate.com/github/patriciomacadden/hobbit)
1
+ # Hobbit [![Build Status](https://travis-ci.org/patriciomacadden/hobbit.png?branch=master)](https://travis-ci.org/patriciomacadden/hobbit) [![Code Climate](https://codeclimate.com/github/patriciomacadden/hobbit.png)](https://codeclimate.com/github/patriciomacadden/hobbit) [![Coverage Status](https://coveralls.io/repos/patriciomacadden/hobbit/badge.png?branch=master)](https://coveralls.io/r/patriciomacadden/hobbit) [![Dependency Status](https://gemnasium.com/patriciomacadden/hobbit.png)](https://gemnasium.com/patriciomacadden/hobbit) [![Gem Version](https://badge.fury.io/rb/hobbit.png)](http://badge.fury.io/rb/hobbit)
5
2
 
6
3
  A minimalistic microframework built on top of [Rack](http://rack.github.io/).
7
4
 
@@ -11,7 +8,7 @@ Add this line to your application's Gemfile:
11
8
 
12
9
  ```ruby
13
10
  gem 'hobbit'
14
- # or this if you want to use master
11
+ # or this if you want to use hobbit master
15
12
  # gem 'hobbit', github: 'patriciomacadden/hobbit'
16
13
  ```
17
14
 
@@ -30,20 +27,28 @@ $ gem install hobbit
30
27
  ## Features
31
28
 
32
29
  * DSL inspired by [Sinatra](http://www.sinatrarb.com/).
33
- * Extensible with standard ruby classes and modules, with no extra logic (See
34
- the included modules and [hobbit-contrib](https://github.com/patriciomacadden/hobbit-contrib)).
35
- * No configuration needed.
36
- * Encourages the understanding and use of [Rack](http://rack.github.io/) and
37
- its extensions.
30
+ * [Speed](https://github.com/patriciomacadden/microbenchmarks).
31
+ * Extensible with standard ruby classes and modules, with no extra logic. See
32
+ [hobbit-contrib](https://github.com/patriciomacadden/hobbit-contrib).
33
+ * Zero configuration.
38
34
  * Request and response classes could be injected (Defaults to `Rack::Request`
39
35
  and `Hobbit::Response`, respectively).
40
36
 
37
+ ## Philosophy
38
+
39
+ * [Don't repeat yourself](http://en.wikipedia.org/wiki/Don't_repeat_yourself)
40
+ * Encourages the understanding and use of [Rack](http://rack.github.io/) and
41
+ its extensions instead of providing such functionality.
42
+
41
43
  ## Usage
42
44
 
43
- `Hobbit` applications are just instances of `Hobbit::Base`, which complies the
45
+ `Hobbit` applications are just instances of classes that inherits from
46
+ `Hobbit::Base`, which complies the
44
47
  [Rack SPEC](http://rack.rubyforge.org/doc/SPEC.html).
45
48
 
46
- Here is a classic **Hello World!** example (write this code in `config.ru`):
49
+ ### Hello World example
50
+
51
+ Create a file called `app.rb`:
47
52
 
48
53
  ```ruby
49
54
  require 'hobbit'
@@ -53,41 +58,67 @@ class App < Hobbit::Base
53
58
  'Hello World!'
54
59
  end
55
60
  end
61
+ ```
62
+
63
+ Create a `config.ru` file:
64
+
65
+ ```ruby
66
+ require './app'
56
67
 
57
68
  run App.new
58
69
  ```
59
70
 
60
- **Note**: In the examples, the classes are written in the `config.ru` file.
61
- However, this is not recommended. Please, **always** follow the coding
62
- standards!
71
+ Run it with `rackup`:
72
+
73
+ ```bash
74
+ $ rackup
75
+ ```
76
+
77
+ View your app at [http://localhost:9292](http://localhost:9292).
63
78
 
64
79
  ### Routes
65
80
 
66
- You can define routes as in [Sinatra](http://www.sinatrarb.com/):
81
+ Every route is composed of a verb, a path (optional) and a block. When an
82
+ incoming request matches a route, the block is executed and a response is sent
83
+ back to the client. The return value of the block will be the `body` of the
84
+ response. The `headers` and `status code` of the response will be calculated by
85
+ `Hobbit::Response`, but you could modify it anyway you want it.
86
+
87
+ See an example:
67
88
 
68
89
  ```ruby
69
90
  class App < Hobbit::Base
70
91
  get '/' do
71
- 'Hello world'
92
+ # ...
72
93
  end
73
94
 
74
- get '/hi/:name' do
75
- "Hello #{request.params[:name]}"
95
+ post '/' do
96
+ # ...
97
+ end
98
+
99
+ put '/' do
100
+ # ...
101
+ end
102
+
103
+ patch '/' do
104
+ # ...
105
+ end
106
+
107
+ delete '/' do
108
+ # ...
109
+ end
110
+
111
+ options '/' do
112
+ # ...
76
113
  end
77
114
  end
78
115
  ```
79
116
 
80
- Every route is composed of a verb, a path and a block. When an incoming request
81
- matches a route, the block is executed and a response is sent back to the
82
- client. The return value of the block will be the `body` of the response. The
83
- `headers` and `status code` of the response will be calculated by
84
- `Hobbit::Response`, but you could modify it anyway you want it.
85
-
86
- Additionally, when a route gets called you have this methods available:
117
+ When a route gets called you have this methods available:
87
118
 
88
119
  * `env`: The Rack environment.
89
120
  * `request`: a `Rack::Request` instance.
90
- * `response`: a `Rack::Response` instance.
121
+ * `response`: a `Hobbit::Response` instance.
91
122
 
92
123
  #### Available methods
93
124
 
@@ -102,180 +133,32 @@ Additionally, when a route gets called you have this methods available:
102
133
  **Note**: Since most browsers don't support methods other than **GET** and
103
134
  **POST** you must use the `Rack::MethodOverride` middleware. (See
104
135
  [Rack::MethodOverride](https://github.com/rack/rack/blob/master/lib/rack/methodoverride.rb)).
105
- Here is an example on how to use it in a RESTful way:
106
136
 
107
- ```ruby
108
- require 'hobbit'
109
-
110
- class App < Hobbit::Base
111
- use Rack::MethodOverride
137
+ #### Routes with parameters
112
138
 
113
- get '/users' do
114
- # list the users
115
- end
116
-
117
- get '/users/new' do
118
- # render a form for creating an user
119
- end
120
-
121
- post '/users' do
122
- # create an user
123
- end
124
-
125
- get '/users/:id/edit' do
126
- # render a form for editing an user
127
- end
128
-
129
- put '/users/:id' do
130
- # update an user
131
- end
132
-
133
- get '/users/:id' do
134
- # show an user
135
- end
136
-
137
- delete '/users/:id' do
138
- # delete an user
139
- end
140
- end
141
-
142
- run App.new
143
- ```
144
-
145
- ### Rendering
146
-
147
- `Hobbit` comes with a module that uses [Tilt](https://github.com/rtomayko/tilt)
148
- for rendering templates. See the example:
149
-
150
- In `config.ru`:
139
+ Besides the standard `GET` and `POST` parameters, you can have routes with
140
+ parameters:
151
141
 
152
142
  ```ruby
153
143
  require 'hobbit'
154
144
 
155
145
  class App < Hobbit::Base
156
- include Hobbit::Render
157
-
158
- get '/' do
159
- render 'views/index.erb'
160
- end
161
- end
162
-
163
- run App.new
164
- ```
165
-
166
- and in `views/index.erb`:
167
-
168
- ```html
169
- <!DOCTYPE html>
170
- <html>
171
- <head>
172
- <title>Hello World!</title>
173
- </head>
174
- <body>
175
- <h1>Hello World!</h1>
176
- </body>
177
- </html>
178
- ```
179
-
180
- **Note**: If you want to use other template engine than `erb`, you should
181
- require the gem, ie. add the gem to your `Gemfile`.
182
-
183
- #### Layout
184
-
185
- For now, the `Hobbit::Render` module is pretty simple (just `render`). If you
186
- want to render a template within a layout, you could simply do this:
187
-
188
- In `config.ru`:
189
-
190
- ```ruby
191
- require 'hobbit'
192
-
193
- class App < Hobbit::Base
194
- include Hobbit::Render
195
-
196
- get '/' do
197
- render 'views/layout.erb' do
198
- render 'views/index.erb'
199
- end
200
- end
201
- end
202
-
203
- run App.new
204
- ```
205
-
206
- In `views/layout.erb`:
207
-
208
- ```html
209
- <!DOCTYPE html>
210
- <html>
211
- <head>
212
- <title>Hello World!</title>
213
- </head>
214
- <body>
215
- <%= yield %>
216
- </body>
217
- </html>
218
- ```
219
-
220
- And in `views/index.erb`:
221
-
222
- ```html
223
- <h1>Hello World!</h1>
224
- ```
225
-
226
- #### Partials
227
-
228
- Partials are just `render` calls:
229
-
230
- ```ruby
231
- <%= render 'views/_some_partial.erb' %>
232
- ```
233
-
234
- #### Helpers
235
-
236
- Who needs helpers when you have standard ruby methods? All methods defined in
237
- the application can be used in the templates, since the template code is
238
- executed within the scope of the application instance. See an example:
239
-
240
- ```ruby
241
- require 'hobbit'
242
-
243
- class App < Hobbit::Base
244
- include Hobbit::Render
245
-
246
- def name
247
- 'World'
248
- end
249
-
250
- get '/' do
251
- render 'views/index.erb'
146
+ # matches both /hi/hobbit and /hi/patricio
147
+ get '/hi/:name' do
148
+ # request.params is filled with the route paramters, like this:
149
+ "Hello #{request.params[:name]}"
252
150
  end
253
151
  end
254
-
255
- run App.new
256
- ```
257
-
258
- and in `views/index.erb`:
259
-
260
- ```ruby
261
- <!DOCTYPE html>
262
- <html>
263
- <head>
264
- <title>Hello <%= name %>!</title>
265
- </head>
266
- <body>
267
- <h1>Hello <%= name %>!</h1>
268
- </body>
269
- </html>
270
152
  ```
271
153
 
272
- ### Redirecting
154
+ #### Redirecting
273
155
 
274
156
  If you look at Hobbit implementation, you may notice that there is no
275
157
  `redirect` method (or similar). This is because such functionality is provided
276
158
  by [Rack::Response](https://github.com/rack/rack/blob/master/lib/rack/response.rb)
277
- and for now we [don't wan't to repeat ourselves](http://en.wikipedia.org/wiki/Don't_repeat_yourself).
278
- So, if you want to redirect to another route, do it like this:
159
+ and for now we [don't wan't to repeat ourselves](http://en.wikipedia.org/wiki/Don't_repeat_yourself)
160
+ (obviously you can create an extension!). So, if you want to redirect to
161
+ another route, do it like this:
279
162
 
280
163
  ```ruby
281
164
  require 'hobbit'
@@ -289,13 +172,13 @@ class App < Hobbit::Base
289
172
  'Hello World!'
290
173
  end
291
174
  end
292
-
293
- run App.new
294
175
  ```
295
176
 
296
- ### Built on rack
177
+ ### Built on top of rack
297
178
 
298
- Each hobbit application is a Rack stack (See this [blog post](http://m.onkey.org/ruby-on-rack-2-the-builder)).
179
+ Each hobbit application is a Rack stack (See this
180
+ [blog post](http://m.onkey.org/ruby-on-rack-2-the-builder) for more
181
+ information).
299
182
 
300
183
  #### Mapping applications
301
184
 
@@ -319,8 +202,6 @@ class App < Hobbit::Base
319
202
  'Hello App!'
320
203
  end
321
204
  end
322
-
323
- run App.new
324
205
  ```
325
206
 
326
207
  #### Using middleware
@@ -345,108 +226,45 @@ end
345
226
  run App.new
346
227
  ```
347
228
 
348
- ### Security
229
+ ### Request and response classes
349
230
 
350
- By default, `hobbit` (nor Rack) comes without any protection against web
351
- attacks. The use of [Rack::Protection](https://github.com/rkh/rack-protection)
352
- is highly recommended:
231
+ You can inject the request (`Rack::Request`) and response (`Hobbit::Response`)
232
+ classes for your application. Do it like this:
353
233
 
354
234
  ```ruby
355
- require 'hobbit'
356
- require 'rack/protection'
357
- require 'securerandom'
358
-
359
235
  class App < Hobbit::Base
360
- use Rack::Session::Cookie, secret: SecureRandom.hex(64)
361
- use Rack::Protection
236
+ settings[:request_class] = MyRequest
237
+ settings[:response_class] = MyResponse
362
238
 
363
- get '/' do
364
- 'Hello World!'
365
- end
239
+ # the rest of your app...
366
240
  end
367
-
368
- run App.new
369
241
  ```
370
242
 
371
- ### Sessions
243
+ ### Security
372
244
 
373
- You can add user sessions using any [Rack session middleware](https://github.com/rack/rack/tree/master/lib/rack/session)
374
- and then access the session through `env['rack.session']`. Fortunately, there
375
- is `Hobbit::Session` which comes with a useful helper:
245
+ By default, `hobbit` (nor Rack) comes without any protection against web
246
+ attacks. The use of [rack-protection](https://github.com/rkh/rack-protection)
247
+ is highly recommended:
376
248
 
377
249
  ```ruby
378
250
  require 'hobbit'
251
+ require 'rack/protection'
379
252
  require 'securerandom'
380
253
 
381
254
  class App < Hobbit::Base
382
- include Hobbit::Session
383
255
  use Rack::Session::Cookie, secret: SecureRandom.hex(64)
384
-
385
- post '/' do
386
- session[:name] = 'hobbit'
387
- end
388
-
389
- get '/' do
390
- session[:name]
391
- end
392
- end
393
-
394
- run App.new
395
- ```
396
-
397
- ### Static files
398
-
399
- `Hobbit` does not serve static files like images, javascripts and stylesheets.
400
- However, you can serve static files using the `Rack::Static` middleware. Here
401
- is an example (See [Rack::Static](https://github.com/rack/rack/blob/master/lib/rack/static.rb)
402
- for further details):
403
-
404
- In `config.ru`
405
-
406
- ```ruby
407
- require 'hobbit'
408
-
409
- class App < Hobbit::Base
410
- include Hobbit::Render
411
- use Rack::Static, root: 'public', urls: ['/javascripts', '/stylesheets']
256
+ use Rack::Protection
412
257
 
413
258
  get '/' do
414
- render 'views/index.erb'
259
+ 'Hello World!'
415
260
  end
416
261
  end
417
-
418
- run App.new
419
262
  ```
420
263
 
421
- In `views/index.erb`:
264
+ Please see the [rack-protection](https://github.com/rkh/rack-protection)
265
+ documentation for futher information.
422
266
 
423
- ```ruby
424
- <!DOCTYPE html>
425
- <html>
426
- <head>
427
- <title>Hello World!</title>
428
- <link href="/stylesheets/application.css" rel="stylesheet"/>
429
- <script src="/javascripts/application.js" type="text/javascript"></script>
430
- </head>
431
- <body>
432
- <h1>Hello World!</h1>
433
- </body>
434
- </html>
435
- ```
436
-
437
- In `public/javascripts/application.js`:
438
-
439
- ```js
440
- alert(1);
441
- ```
442
-
443
- In `public/stylesheets/application.css`:
444
-
445
- ```css
446
- h1 { color: blue; }
447
- ```
448
-
449
- ### Testing Hobbit applications
267
+ ### Testing
450
268
 
451
269
  [rack-test](https://github.com/brynary/rack-test) is highly recommended. See
452
270
  an example:
@@ -461,8 +279,6 @@ class App < Hobbit::Base
461
279
  'Hello World!'
462
280
  end
463
281
  end
464
-
465
- run App.new
466
282
  ```
467
283
 
468
284
  In `app_spec.rb`:
@@ -489,17 +305,51 @@ describe App do
489
305
  end
490
306
  ```
491
307
 
492
- Please see the [rack-test](https://github.com/brynary/rack-test) documentation.
308
+ Please see the [rack-test](https://github.com/brynary/rack-test) documentation
309
+ for futher information.
310
+
311
+ ### Extensions
312
+
313
+ You can extend hobbit by creating standard ruby modules. See an example:
314
+
315
+ ```ruby
316
+ module MyExtension
317
+ def do_something
318
+ # do something
319
+ end
320
+ end
321
+
322
+ class App < Hobbit::Base
323
+ include MyExtension
324
+
325
+ get '/' do
326
+ do_something
327
+ 'Hello World!'
328
+ end
329
+ end
330
+ ```
331
+
332
+ #### Hobbit::Contrib
333
+
334
+ [hobbit-contrib](https://github.com/patriciomacadden/hobbit-contrib) is a ruby
335
+ gem that comes with a lot of hobbit extensions, such as:
493
336
 
494
- ## Extending Hobbit
337
+ * `Hobbit::Render`: provides a (very) basic template rendering module.
338
+ * `Hobbit::EnhancedRender`: provides an enhanced template rendering module.
339
+ * `Hobbit::Session`: provides helper methods for handling user sessions.
340
+ * `Hobbit::Environment`: provides helper methods for handling application
341
+ environments.
342
+ * `Hobbit::Filter`: provides helper class methods for handling Sinatra-like
343
+ filters.
344
+ * `Hobbit::ErrorHandling`: provides helper class methods for handling
345
+ Sinatra-like error handling.
495
346
 
496
- You can extend hobbit by creating modules or classes. See `Hobbit::Render` or
497
- `Hobbit::Session` for examples.
347
+ ... And many more!
498
348
 
499
- ### Hobbit::Contrib
349
+ ## Futher documentation
500
350
 
501
- See [hobbit-contrib](https://github.com/patriciomacadden/hobbit-contrib) for
502
- more hobbit extensions!
351
+ The [hobbit wiki](https://github.com/patriciomacadden/hobbit/wiki) contains
352
+ guides, how-tos and recipes for a better hobbit experience.
503
353
 
504
354
  ## Contributing
505
355
 
@@ -19,12 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'coveralls'
22
23
  spec.add_development_dependency 'minitest'
23
24
  spec.add_development_dependency 'rack'
24
25
  spec.add_development_dependency 'rack-test'
25
26
  spec.add_development_dependency 'rake'
26
- spec.add_development_dependency 'tilt'
27
27
 
28
28
  spec.add_runtime_dependency 'rack'
29
- spec.add_runtime_dependency 'tilt'
30
29
  end
@@ -1,5 +1,3 @@
1
1
  require 'hobbit/base'
2
- require 'hobbit/render'
3
2
  require 'hobbit/response'
4
- require 'hobbit/session'
5
- require 'hobbit/version'
3
+ require 'hobbit/version'
@@ -65,7 +65,7 @@ module Hobbit
65
65
  def route_eval
66
66
  route = self.class.routes[request.request_method].detect { |r| r[:compiled_path] =~ request.path_info }
67
67
  if route
68
- route[:compiled_path].match(request.path_info).captures.each_with_index do |value, index|
68
+ $~.captures.each_with_index do |value, index|
69
69
  param = route[:extra_params][index]
70
70
  request.params[param] = value
71
71
  end
@@ -3,8 +3,8 @@ require 'rack'
3
3
  module Hobbit
4
4
  class Response < Rack::Response
5
5
  def initialize(body = [], status = 200, header = {})
6
- header['Content-Type'] = 'text/html'
6
+ header['Content-Type'] = 'text/html; charset=utf-8'
7
7
  super
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Hobbit
2
- VERSION = '0.0.3'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -3,6 +3,9 @@ ENV['RACK_ENV'] ||= 'test'
3
3
  require 'bundler'
4
4
  Bundler.require :default, ENV['RACK_ENV'].to_sym
5
5
 
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
6
9
  require 'minitest/autorun'
7
10
  require 'rack'
8
11
  require 'rack/test'
@@ -16,4 +19,4 @@ module Hobbit
16
19
  app.new
17
20
  end
18
21
  end
19
- end
22
+ end
@@ -2,8 +2,8 @@ require 'minitest_helper'
2
2
 
3
3
  describe Hobbit::Response do
4
4
  describe '#initialize' do
5
- it 'must initialize Content-Type with text/html' do
6
- Hobbit::Response.new.headers['Content-Type'].must_equal 'text/html'
5
+ it 'must initialize Content-Type with text/html; charset=utf-8' do
6
+ Hobbit::Response.new.headers['Content-Type'].must_equal 'text/html; charset=utf-8'
7
7
  end
8
8
  end
9
- end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Mac Adden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-25 00:00:00.000000000 Z
11
+ date: 2013-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: minitest
28
+ name: coveralls
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rack
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rack-test
56
+ name: rack
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '>='
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: rack-test
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '>='
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: tilt
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '>='
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: tilt
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
111
  description: A minimalistic microframework built on top of rack
126
112
  email:
127
113
  - patriciomacadden@gmail.com
@@ -138,17 +124,11 @@ files:
138
124
  - hobbit.gemspec
139
125
  - lib/hobbit.rb
140
126
  - lib/hobbit/base.rb
141
- - lib/hobbit/render.rb
142
127
  - lib/hobbit/response.rb
143
- - lib/hobbit/session.rb
144
128
  - lib/hobbit/version.rb
145
129
  - spec/base_spec.rb
146
- - spec/fixtures/views/hello.erb
147
- - spec/fixtures/views/index.erb
148
130
  - spec/minitest_helper.rb
149
- - spec/render_spec.rb
150
131
  - spec/response_spec.rb
151
- - spec/session_spec.rb
152
132
  - spec/version_spec.rb
153
133
  homepage: ''
154
134
  licenses:
@@ -176,10 +156,6 @@ specification_version: 4
176
156
  summary: A minimalistic microframework built on top of rack
177
157
  test_files:
178
158
  - spec/base_spec.rb
179
- - spec/fixtures/views/hello.erb
180
- - spec/fixtures/views/index.erb
181
159
  - spec/minitest_helper.rb
182
- - spec/render_spec.rb
183
160
  - spec/response_spec.rb
184
- - spec/session_spec.rb
185
161
  - spec/version_spec.rb
@@ -1,17 +0,0 @@
1
- require 'tilt'
2
-
3
- module Hobbit
4
- module Render
5
- def render(template, locals = {}, options = {}, &block)
6
- cache.fetch(template) do
7
- Tilt.new(template, options)
8
- end.render(self, locals, &block)
9
- end
10
-
11
- private
12
-
13
- def cache
14
- Thread.current[:cache] ||= Tilt::Cache.new
15
- end
16
- end
17
- end
@@ -1,7 +0,0 @@
1
- module Hobbit
2
- module Session
3
- def session
4
- env['rack.session']
5
- end
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head><title>Hello <%= name %>!</title></head>
4
- <body>Hello <%= name %>!</body>
5
- </html>
@@ -1,5 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head><title>Hello World!</title></head>
4
- <body>Hello World!</body>
5
- </html>
@@ -1,33 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Hobbit::Render do
4
- include Hobbit::Mock
5
- include Rack::Test::Methods
6
-
7
- def app
8
- mock_app do
9
- include Hobbit::Render
10
-
11
- def name
12
- 'Hobbit'
13
- end
14
-
15
- get('/') { render File.expand_path('../fixtures/views/index.erb', __FILE__) }
16
- get('/using-context') { render File.expand_path('../fixtures/views/hello.erb', __FILE__) }
17
- end
18
- end
19
-
20
- describe '#render' do
21
- it 'must render a template' do
22
- get '/'
23
- last_response.must_be :ok?
24
- last_response.body.must_match /Hello World!/
25
- end
26
-
27
- it 'must use the app as context' do
28
- get '/using-context'
29
- last_response.must_be :ok?
30
- last_response.body.must_match /Hello Hobbit!/
31
- end
32
- end
33
- end
@@ -1,33 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Hobbit::Session do
4
- include Hobbit::Mock
5
- include Rack::Test::Methods
6
-
7
- def app
8
- mock_app do
9
- include Hobbit::Session
10
- use Rack::Session::Cookie, secret: SecureRandom.hex(64)
11
-
12
- get '/' do
13
- session[:name] = 'hobbit'
14
- end
15
-
16
- get '/name' do
17
- session[:name]
18
- end
19
- end
20
- end
21
-
22
- describe '#session' do
23
- it 'must return a session object' do
24
- get '/'
25
- last_response.must_be :ok?
26
- last_response.body.must_equal 'hobbit'
27
-
28
- get '/name'
29
- last_response.must_be :ok?
30
- last_response.body.must_equal 'hobbit'
31
- end
32
- end
33
- end